dtd.vim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. " Vim syntax file
  2. " Language: DTD (Document Type Definition for XML)
  3. " Maintainer: Christian Brabandt <cb@256bit.org>
  4. " Repository: https://github.com/chrisbra/vim-xml-ftplugin
  5. " Previous Maintainer: Johannes Zellner <johannes@zellner.org>
  6. " Author: Daniel Amyot <damyot@site.uottawa.ca>
  7. " Last Changed: Sept 24, 2019
  8. " Filenames: *.dtd
  9. "
  10. " REFERENCES:
  11. " http://www.w3.org/TR/html40/
  12. " http://www.w3.org/TR/NOTE-html-970421
  13. "
  14. " TODO:
  15. " - improve synchronizing.
  16. if exists("b:current_syntax")
  17. finish
  18. endif
  19. let s:dtd_cpo_save = &cpo
  20. set cpo&vim
  21. if !exists("dtd_ignore_case")
  22. " I prefer having the case takes into consideration.
  23. syn case match
  24. else
  25. syn case ignore
  26. endif
  27. " the following line makes the opening <! and
  28. " closing > highlighted using 'dtdFunction'.
  29. "
  30. " PROVIDES: @dtdTagHook
  31. "
  32. syn region dtdTag matchgroup=dtdFunction
  33. \ start=+<!+ end=+>+ matchgroup=NONE
  34. \ contains=dtdTag,dtdTagName,dtdError,dtdComment,dtdString,dtdAttrType,dtdAttrDef,dtdEnum,dtdParamEntityInst,dtdParamEntityDecl,dtdCard,@dtdTagHook
  35. if !exists("dtd_no_tag_errors")
  36. " mark everything as an error which starts with a <!
  37. " and is not overridden later. If this is annoying,
  38. " it can be switched off by setting the variable
  39. " dtd_no_tag_errors.
  40. syn region dtdError contained start=+<!+lc=2 end=+>+
  41. endif
  42. " if this is a html like comment highlight also
  43. " the opening <! and the closing > as Comment.
  44. syn region dtdComment start=+<![ \t]*--+ end=+-->+ contains=dtdTodo,@Spell
  45. " proper DTD comment
  46. syn region dtdComment contained start=+--+ end=+--+ contains=dtdTodo,@Spell
  47. " Start tags (keywords). This is contained in dtdFunction.
  48. " Note that everything not contained here will be marked
  49. " as error.
  50. syn match dtdTagName contained +<!\(ATTLIST\|DOCTYPE\|ELEMENT\|ENTITY\|NOTATION\|SHORTREF\|USEMAP\|\[\)+lc=2,hs=s+2
  51. " wildcards and operators
  52. syn match dtdCard contained "|"
  53. syn match dtdCard contained ","
  54. " evenutally overridden by dtdEntity
  55. syn match dtdCard contained "&"
  56. syn match dtdCard contained "?"
  57. syn match dtdCard contained "\*"
  58. syn match dtdCard contained "+"
  59. " ...and finally, special cases.
  60. syn match dtdCard "ANY"
  61. syn match dtdCard "EMPTY"
  62. if !exists("dtd_no_param_entities")
  63. " highlight parameter entity declarations
  64. " and instances. Note that the closing `;'
  65. " is optional.
  66. " instances
  67. syn region dtdParamEntityInst oneline matchgroup=dtdParamEntityPunct
  68. \ start="%[-_a-zA-Z0-9.]\+"he=s+1,rs=s+1
  69. \ skip=+[-_a-zA-Z0-9.]+
  70. \ end=";\|\>"
  71. \ matchgroup=NONE contains=dtdParamEntityPunct
  72. syn match dtdParamEntityPunct contained "\."
  73. " declarations
  74. " syn region dtdParamEntityDecl oneline matchgroup=dtdParamEntityDPunct start=+<!ENTITY % +lc=8 skip=+[-_a-zA-Z0-9.]+ matchgroup=NONE end="\>" contains=dtdParamEntityDPunct
  75. syn match dtdParamEntityDecl +<!ENTITY % [-_a-zA-Z0-9.]*+lc=8 contains=dtdParamEntityDPunct
  76. syn match dtdParamEntityDPunct contained "%\|\."
  77. endif
  78. " &entities; compare with xml
  79. syn match dtdEntity "&[^; \t]*;" contains=dtdEntityPunct
  80. syn match dtdEntityPunct contained "[&.;]"
  81. " Strings are between quotes
  82. syn region dtdString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=dtdAttrDef,dtdAttrType,dtdParamEntityInst,dtdEntity,dtdCard
  83. syn region dtdString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=dtdAttrDef,dtdAttrType,dtdParamEntityInst,dtdEntity,dtdCard
  84. " Enumeration of elements or data between parenthesis
  85. "
  86. " PROVIDES: @dtdEnumHook
  87. "
  88. syn region dtdEnum matchgroup=dtdType start="(" end=")" matchgroup=NONE contains=dtdEnum,dtdParamEntityInst,dtdCard,@dtdEnumHook
  89. "Attribute types
  90. syn keyword dtdAttrType NMTOKEN ENTITIES NMTOKENS ID CDATA
  91. syn keyword dtdAttrType IDREF IDREFS
  92. " ENTITY has to treated special for not overriding <!ENTITY
  93. syn match dtdAttrType +[^!]\<ENTITY+
  94. "Attribute Definitions
  95. syn match dtdAttrDef "#REQUIRED"
  96. syn match dtdAttrDef "#IMPLIED"
  97. syn match dtdAttrDef "#FIXED"
  98. syn case match
  99. " define some common keywords to mark TODO
  100. " and important sections inside comments.
  101. syn keyword dtdTodo contained TODO FIXME XXX
  102. syn sync lines=250
  103. " Define the default highlighting.
  104. " Only when an item doesn't have highlighting yet
  105. " The default highlighting.
  106. hi def link dtdFunction Function
  107. hi def link dtdTag Normal
  108. hi def link dtdType Type
  109. hi def link dtdAttrType dtdType
  110. hi def link dtdAttrDef dtdType
  111. hi def link dtdConstant Constant
  112. hi def link dtdString dtdConstant
  113. hi def link dtdEnum dtdConstant
  114. hi def link dtdCard dtdFunction
  115. hi def link dtdEntity Statement
  116. hi def link dtdEntityPunct dtdType
  117. hi def link dtdParamEntityInst dtdConstant
  118. hi def link dtdParamEntityPunct dtdType
  119. hi def link dtdParamEntityDecl dtdType
  120. hi def link dtdParamEntityDPunct dtdComment
  121. hi def link dtdComment Comment
  122. hi def link dtdTagName Statement
  123. hi def link dtdError Error
  124. hi def link dtdTodo Todo
  125. let &cpo = s:dtd_cpo_save
  126. unlet s:dtd_cpo_save
  127. let b:current_syntax = "dtd"
  128. " vim: ts=8