1
###############################################################################
3
# Purpose: Define HTML syntax for highlighting and other features #
4
# Author: Cody Precord <cprecord@editra.org> #
5
# Copyright: (c) 2007 Cody Precord <staff@editra.org> #
6
# License: wxWindows License #
7
###############################################################################
12
@summary: Lexer configuration module for HTML/DHTML/SGML.
13
@todo: Add Netscape/Microsoft Tag Extenstions (maybe)
14
@todo: Styleing needs lots of tweaking
18
__author__ = "Cody Precord <cprecord@editra.org>"
19
__svnid__ = "$Id: _html.py 68798 2011-08-20 17:17:05Z CJP $"
20
__revision__ = "$Revision: 68798 $"
22
#-----------------------------------------------------------------------------#
32
#-----------------------------------------------------------------------------#
34
#---- Keyword Specifications ----#
37
HTML_TAGS = (0, "address applet area a base basefont big blockquote br caption "
38
"center cite code dd dfn dir div dl dt font form hr html img "
39
"input isindex kbd li link map menu meta ol option param pre p "
40
"samp span select small strike sub sup table td textarea th tr "
41
"script noscript tt ul var xmp b i u h1 h2 h3 h4 h5 h6 em "
42
"strong head body title "
44
"abbr acronym bdo button col label colgroup del fieldset "
45
"iframe ins legend object optgroup q s tbody tfoot thead "
47
"article aside audio canvas command datalist details dialog "
48
"embed figcaption figure footer header hgroup keygen mark "
49
"meter nav output progress rp rt ruby section source time "
51
# Tag Attributes / Arguments
52
"action align alink alt archive background bgcolor border "
53
"bordercolor cellpadding cellspacing checked class clear "
54
"codebase color cols colspan content coords enctype face "
55
"gutter height hspace id link lowsrc marginheight marginwidth "
56
"maxlength method name prompt rel rev rows rowspan scrolling "
57
"selected shape size src start target text type url usemap "
58
"ismap valign value vlink vspace width wrap href http-equiv "
59
# HTML 4 Tag Attributes /Arguments
60
"accept accesskey axis char charoff charset cite classid "
61
"codetype compact data datetime declare defer dir disabled for "
62
"frame headers hreflang lang language longdesc multiple nohref "
63
"nowrap profile readonly rules scheme scope standby style "
64
"summary tabindex valuetype version "
65
# HTML 5 Tag Attributes / Arguments
66
"async autocomplete contenteditable contextmenu date "
67
"datetime-local draggable email formaction formenctype "
68
"formmethod formnovalidate formtarget hidden list manifest max "
69
"media min month novalidate number pattern ping range required "
70
"reversed role sandbox scoped seamless search sizes spellcheck "
71
"srcdoc step tel week "
73
"dtml-var dtml-if dtml-unless dtml-in dtml-with dtml-let "
74
"dtml-call dtml-raise dtml-try dtml-comment dtml-tree")
76
#---- Extra defs ----#
78
CF_TAGS = ("cfabort cfapplet cfapplication cfargument cfassociate cfbreak "
79
"cfcache cfcalendar cfcase cfcatch cfchart cfchartdata "
80
"cfchartseries cfcol cfcollection cfcomponent cfcontent cfcookie "
81
"cfdefaultcase cfdirectory cfdocument cfdocumentitem "
82
"cfdocumentsection cfdump cfelse cfelseif cferror cfexecute cfexit "
83
"cffile cfflush cfform cfformgroup cfformitem cfftp cffunction "
84
"cfgrid cfgridcolumn cfgridrow cfgridupdate cfheader cfhtmlhead "
85
"cfhttp cfhttpparam cfif cfimport cfinclude cfindex cfinput "
86
"cfinsert cfinvoke cfinvokeargument cfldap cflocation cflock cflog "
87
"cflogin cfloginuser cflogout cfloop cfmail cfmailparam cfmailpart "
88
"cfmodule cfNTauthenticate cfobject cfobjectcache cfoutput cfparam "
89
"cfpop cfprocessingdirective cfprocparam cfprocresult cfproperty "
90
"cfquery cfqueryparam cfregistry cfreport cfreportparam cfrethrow "
91
"cfreturn cfsavecontent cfschedule cfscript cfsearch cfselect cfset "
92
"cfsetting cfsilent cfslider cfstoredproc cfswitch cftable "
93
"cftextarea cfthrow cftimer cftrace cftransaction cftree cftreeitem "
94
"cftry cfupdate cfwddx cfxml")
96
# JavaScript Keywords (see javascript.py)
97
JS_KEYWORDS = (1, _javascript.KeywordString(synglob.ID_LANG_JS))
99
# VBScript Keywords (currently unsupported)
100
VBS_KEYWORDS = (2, _vbscript.VBS_KW)
102
# Python Keywords (see python.py)
103
PY_KEYWORDS = (3, "")
105
# PHP Keywords (see php.py)
106
# This module is loaded for files with a .html/htm extension so it is assumed
107
# that there is no php in the file. On the other hand the php module loads
108
# this module so that it can support embedded html. This behavior may be changed
111
# XML Keywords (see xml.py)
112
# XML files are handled independantly from html although there is support for
113
# embedded xml highlighting it is currently not being used.
116
SGML_KEYWORDS = (5, "ELEMENT DOCTYPE ATTLIST ENTITY NOTATION")
117
#SGML_KEYWORDS = (5, "#CURRENT #IMPLIED #REQUIRED ATTLIST CDATA DOCTYPE "
118
# "ELEMENT ENTITY HTML IDREF INCLUDE IGNORE NMTOKEN NUMBER "
121
# SGML Block Keywords
124
#---- Syntax Style Specs ----#
125
SYNTAX_ITEMS = [ (stc.STC_H_DEFAULT, 'default_style'),
126
(stc.STC_H_ASP, 'array_style'),
127
(stc.STC_H_ASPAT, 'array_style'),
128
(stc.STC_H_ATTRIBUTE, 'keyword2_style'),
129
(stc.STC_H_ATTRIBUTEUNKNOWN, 'error_style'),
130
(stc.STC_H_CDATA, 'default_style'), # Style ME
131
(stc.STC_H_COMMENT, 'comment_style'),
132
(stc.STC_H_DOUBLESTRING, 'string_style'),
133
(stc.STC_H_ENTITY, 'default_style'), # Style ME
134
(stc.STC_H_NUMBER, 'number_style'),
135
(stc.STC_H_OTHER, 'default_style'), # Style ME
136
(stc.STC_H_QUESTION, 'scalar_style'),
137
(stc.STC_H_SCRIPT, 'funct_style'), # STYLE ME
138
(stc.STC_H_SGML_1ST_PARAM, 'keyword2_style'), # STYLE ME
139
(stc.STC_H_SGML_1ST_PARAM_COMMENT, 'comment_style'),
140
(stc.STC_H_SGML_BLOCK_DEFAULT, 'default_style'), # STYLE ME
141
(stc.STC_H_SGML_COMMAND, 'keyword_style'), # STYLE ME
142
(stc.STC_H_SGML_COMMENT, 'comment_style'),
143
(stc.STC_H_SGML_DEFAULT, 'array_style'), # STYLE ME
144
(stc.STC_H_SGML_DOUBLESTRING, 'string_style'),
145
(stc.STC_H_SGML_ENTITY, 'default_style'), # STYLE ME
146
(stc.STC_H_SGML_ERROR, 'error_style'),
147
(stc.STC_H_SGML_SIMPLESTRING, 'string_style'),
148
(stc.STC_H_SGML_SPECIAL, 'default_style'), # STYLE ME
149
(stc.STC_H_SINGLESTRING, 'string_style'),
150
(stc.STC_H_TAG, 'keyword_style'),
151
(stc.STC_H_TAGEND, 'keyword_style'),
152
(stc.STC_H_TAGUNKNOWN, 'error_style'),
153
(stc.STC_H_VALUE, 'number_style'),
154
(stc.STC_H_XCCOMMENT, 'comment_style'),
155
(stc.STC_H_XMLEND, 'scalar_style'),
156
(stc.STC_H_XMLSTART, 'scalar_style'),
158
# Embedded JavaScript
159
(stc.STC_HJ_COMMENT, 'comment_style'),
160
(stc.STC_HJ_COMMENTDOC, 'comment_style'),
161
(stc.STC_HJ_COMMENTLINE, 'comment_style'),
162
(stc.STC_HJ_DEFAULT, 'default_style'),
163
(stc.STC_HJ_DOUBLESTRING, 'default_style'), # STYLE ME
164
(stc.STC_HJ_KEYWORD, 'default_style'), # STYLE ME
165
(stc.STC_HJ_NUMBER, 'default_style'), # STYLE ME
166
(stc.STC_HJ_REGEX, 'default_style'), # STYLE ME
167
(stc.STC_HJ_SINGLESTRING, 'default_style'), # STYLE ME
168
(stc.STC_HJ_START, 'default_style'), # STYLE ME
169
(stc.STC_HJ_STRINGEOL, 'default_style'), # STYLE ME
170
(stc.STC_HJ_SYMBOLS, 'default_style'), # STYLE ME
171
(stc.STC_HJ_WORD, 'default_style'), # STYLE ME
173
(stc.STC_HJA_COMMENT, 'comment_style'),
174
(stc.STC_HJA_COMMENTDOC, 'comment_style'),
175
(stc.STC_HJA_COMMENTLINE, 'comment_style'),
176
(stc.STC_HJA_DEFAULT, 'default_style'),
177
(stc.STC_HJA_DOUBLESTRING, 'default_style'), # STYLE ME
178
(stc.STC_HJA_KEYWORD, 'default_style'), # STYLE ME
179
(stc.STC_HJA_NUMBER, 'default_style'), # STYLE ME
180
(stc.STC_HJA_REGEX, 'default_style'), # STYLE ME # STYLE ME
181
(stc.STC_HJA_SINGLESTRING, 'default_style'), # STYLE ME
182
(stc.STC_HJA_START, 'default_style'), # STYLE ME
183
(stc.STC_HJA_STRINGEOL, 'default_style'), # STYLE ME
184
(stc.STC_HJA_SYMBOLS, 'default_style'), # STYLE ME
185
(stc.STC_HJA_WORD, 'default_style'),
187
(stc.STC_HBA_DEFAULT, 'operator_style'), # Styles ( ) ?
188
(stc.STC_HBA_COMMENTLINE, 'comment_style'),
189
(stc.STC_HBA_IDENTIFIER, 'default_style'), # TODO
190
(stc.STC_HBA_NUMBER, 'number_style'),
191
(stc.STC_HBA_START, 'default_style'), # TODO
192
(stc.STC_HBA_STRING, 'string_style'),
193
(stc.STC_HBA_STRINGEOL, 'stringeol_style'),
194
(stc.STC_HBA_WORD, 'keyword_style') ]
196
#---- Extra Properties ----#
198
FLD_HTML = ("fold.html", "1")
200
#------------------------------------------------------------------------------#
202
class SyntaxData(syndata.SyntaxDataBase):
203
"""SyntaxData object for Html and related languages"""
204
def __init__(self, langid):
205
super(SyntaxData, self).__init__(langid)
208
self.SetLexer(stc.STC_LEX_HTML)
209
self.RegisterFeature(synglob.FEATURE_AUTOINDENT, AutoIndenter)
211
def GetKeywords(self):
212
"""Returns Specified Keywords List"""
213
if self.LangId == synglob.ID_LANG_COLDFUSION:
214
return [(HTML_TAGS[0], HTML_TAGS[1] + " " + CF_TAGS), JS_KEYWORDS]
216
return [HTML_TAGS, JS_KEYWORDS, SGML_KEYWORDS, VBS_KEYWORDS]
218
def GetSyntaxSpec(self):
219
"""Syntax Specifications"""
220
return SYNTAX_ITEMS + _javascript.SYNTAX_ITEMS
222
def GetProperties(self):
223
"""Returns a list of Extra Properties to set"""
224
return [FOLD, FLD_HTML]
226
def GetCommentPattern(self):
227
"""Returns a list of characters used to comment a block of code"""
228
return [u'<!--', u'-->']
230
#-----------------------------------------------------------------------------#
232
def AutoIndenter(estc, pos, ichar):
233
"""Auto indent python code.
234
@param estc: EditraStyledTextCtrl
235
@param pos: current carat position
236
@param ichar: Indentation character
240
line = estc.GetCurrentLine()
241
spos = estc.PositionFromLine(line)
242
text = estc.GetTextRange(spos, pos)
243
eolch = estc.GetEOLChar()
244
inspace = text.isspace()
246
# Cursor is in the indent area somewhere
248
estc.AddText(eolch + text)
251
# Check if the cursor is in column 0 and just return newline.
257
tabw = estc.GetTabWidth()
259
tabw = estc.GetIndent()
261
# Standard indent to match previous line
262
indent = estc.GetLineIndentation(line)
263
levels = indent / tabw
264
end_spaces = ((indent - (tabw * levels)) * u" ")
265
rtxt = eolch + (ichar * levels) + end_spaces
267
# Check if we need some 'special' indentation
269
if tmp.endswith(u">"):
270
# At a tag check for if we need extra indentation
271
tagstart = tmp.rfind(u"<")
273
tagval = tmp[tagstart:]
274
if not tagval.startswith(u"</") and \
275
not tagval.endswith(u"/>") and \
276
not tagval.endswith(u"?>"):
277
# Cursor is after an opening tag so we need to indent more
278
# First match to the starting tag
279
levels = (tagstart / tabw) # Add an extra level
280
end_spaces = ((tagstart - (tabw * levels)) * u" ")
281
rtxt = eolch + (ichar * (levels+1)) + end_spaces
283
# Put text in the buffer
286
#---- Syntax Modules Internal Functions ----#
287
def KeywordString(option=0):
288
"""Returns the specified Keyword String
289
@param option: specific subset of keywords to get
292
if option == synglob.ID_LANG_SGML:
293
return SGML_KEYWORDS[1]
297
#---- End Syntax Modules Internal Functions ----#