1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
from highlighter.common import *
#################################################
# Keywords, properties and default values lists #
#################################################
properties_list = ["align-content", "align-items", "align-self",
"animation-delay", "animation-direction",
"animation-duration", "animation-fill-mode",
"animation-iteration-count", "animation-name",
"animation-play-state", "animation-timing-function",
"animation", "backface-visibility", "background-attachment",
"background-clip", "background-color", "background-image",
"background-origin", "background-position",
"background-repeat", "background-size", "background",
"border-bottom-color", "border-bottom-left-radius",
"border-bottom-right-radius", "border-bottom-style",
"border-bottom-width", "border-bottom", "border-collapse",
"border-color", "border-image-outset",
"border-image-repeat", "border-image-slice",
"border-image-source", "border-image-width",
"border-image", "border-left-color",
"border-left-style", "border-left-width", "border-left",
"border-radius", "border-right-color",
"border-right-style", "border-right-width",
"border-right", "border-spacing",
"border-style", "border-top-color",
"border-top-left-radius", "border-top-right-radius",
"border-top-style", "border-top-width",
"border-top", "border-width",
"border", "bottom", "box-shadow", "box-sizing",
"caption-side", "clear", "clip", "color", "column-count",
"column-fill", "column-gap", "column-rule",
"column-rule-color", "column-rule-style",
"column-rule-width", "column-span", "column-width",
"columns", "content", "counter-increment", "counter-reset",
"cursor", "direction", "display", "empty-cells",
"filter", "flex-basis", "flex-direction", "flex-flow",
"flex-grow", "flex-shrink", "flex-wrap", "flex",
"float", "@font-face", "font-family", "font-size",
"font-size-adjust", "font-stretch", "font-style",
"font-variant", "font-weight", "font",
"hanging-punctuation", "height", "justify-content",
"@keyframes", "left", "letter-spacing",
"line-height", "list-style-image",
"list-style-position", "list-style-type", "list-style",
"margin-bottom", "margin-left", "margin-right",
"margin-top", "margin", "max-height", "max-width",
"@media", "min-height", "min-width", "nav-down",
"nav-index", "nav-left", "nav-right",
"nav-up", "opacity", "order",
"outline-color", "outline-offset", "outline-style",
"outline-width", "outline", "overflow-x", "overflow-y",
"overflow", "padding-bottom", "padding-left",
"padding-right", "padding-top", "padding",
"page-break-after", "page-break-before",
"page-break-inside", "perspective", "perspective-origin",
"position", "quotes", "resize", "right", "tab-size",
"table-layout", "text-align-last", "text-align",
"text-decoration-color", "text-decoration-line",
"text-decoration-style", "text-decoration", "text-indent",
"text-justify",
"text-overflow", "text-shadow", "text-transform",
"top", "transform-origin", "transform-style",
"transform", "transition-delay", "transition-duration",
"transition-property", "transition-timing-function",
"transition", "unicode-bidi", "vertical-align",
"visibility", "white-space", "width",
"word-break", "word-spacing", "word-wrap", "z-index"]
html_elements_list = ["a", "abbr", "acronym", "abbr", "address", "applet",
"embed", "object", "area", "article", "aside",
"audio", "b", "base", "basefont", "bdi", "bdo",
"big", "blockquote", "body", "br", "button",
"canvas", "caption", "center", "cite", "code", "col",
"colgroup", "colgroup", "datalist", "dd", "del",
"details", "dfn", "dialog", "dir", "ul", "div", "dl",
"dt", "em", "embed", "fieldset", "figcaption", "figure",
"figure", "font", "footer", "form", "frame", "frameset",
"h1", "h6", "head", "header", "hr", "html", "i",
"iframe", "img", "input", "ins",
"kbd", "keygen", "label", "input", "legend",
"fieldset", "li", "link", "main", "map", "mark",
"menu", "menuitem", "meta", "meter", "nav",
"noframes", "noscript", "object", "ol", "optgroup",
"option", "output", "p", "param", "pre", "progress",
"q", "rp", "rt", "ruby", "s", "samp", "script",
"section", "select", "small", "source", "video",
"audio", "span", "strike", "del", "s", "strong", "style",
"sub", "summary", "details", "sup", "table", "tbody",
"td", "textarea", "tfoot", "th", "thead", "time",
"title", "tr", "track", "video", "audio", "tt",
"u", "ul", "var", "video", "wbr"]
length_units_list = "|".join(["em", "ex", "%", "px", "cm", "mm", "in", "pt",
"pc", "ch", "rem", "vh", "vw", "vmin", "vmax"])
border_types_list = ["none", "hidden", "dotted", "dashed", "solid", "groove",
"ridge", "inset", "outset", "initial", "inherit"]
color_names_list = ["aliceblue", "antiquewhite", "aqua", "aquamarine",
"azure", "beige", "bisque", "black", "blanchedalmond",
"blue", "blueviolet", "brown", "burlywood", "cadetblue",
"chartreuse", "chocolate", "coral", "cornflowerblue",
"cornsilk", "crimson", "cyan", "darkblue", "darkcyan",
"darkgoldenrod", "darkgray", "darkgreen", "darkkhaki",
"darkmagenta", "darkolivegreen", "darkorange",
"darkorchid", "darkred", "darksalmon",
"darkseagreen", "darkslateblue", "darkslategray",
"darkturquoise", "darkviolet", "deeppink",
"deepskyblue", "dimgray", "dodgerblue", "firebrick",
"floralwhite", "forestgreen", "fuchsia", "gainsboro",
"ghostwhite", "gold", "goldenrod", "gray", "green",
"greenyellow", "honeydew", "hotpink", "indianred",
"indigo", "ivory", "khaki", "lavender", "lavenderblush",
"lawngreen", "lemonchiffon", "lightblue", "lightcoral",
"lightcyan", "lightgoldenrodyellow", "lightgray",
"lightgreen", "lightpink", "lightsalmon", "lightseagreen",
"lightskyblue", "lightslategray", "lightsteelblue",
"lightyellow", "lime", "limegreen", "linen",
"magenta", "maroon", "mediumaquamarine", "mediumblue",
"mediumorchid", "mediumpurple", "mediumseagreen",
"mediumslateblue", "mediumspringgreen", "mediumturquoise",
"mediumvioletred", "midnightblue", "mintcream",
"mistyrose", "moccasin", "navajowhite",
"navy", "oldlace", "olive", "olivedrab", "orange",
"orangered", "orchid", "palegoldenrod", "palegreen",
"paleturquoise", "palevioletred", "papayawhip",
"peachpuff", "peru", "pink", "plum", "powderblue",
"purple", "rebeccapurple", "red", "rosybrown",
"royalblue", "saddlebrown", "salmon", "sandybrown",
"seagreen", "seashell", "sienna", "silver", "skyblue",
"slateblue", "slategray", "snow", "springgreen",
"steelblue", "tan", "teal", "thistle", "tomato",
"turquoise", "transparent", "violet", "wheat", "white",
"whitesmoke", "yellow", "yellowgreen"]
####################
# Tag definitions #
####################
tag_classes_id_identifiers = new_style(lang="CSS",
name="css_classes_id_identifiers",
label="Classes and ID identifiers",
doc="Style used for class selectors"
" and id selectors identifiers",
foreground_colors=('#99FF33',
'#99FF33'))
tag_length_units = new_style(lang="CSS",
name="css_length_units",
label="Length units",
doc="Style used for the CSS length units",
foreground_colors=('#F92572', '#F92572'))
#######################
# Matcher definitions #
#######################
string_template = region_template(tag=tag_string,
highlighter=(hl_inside_strings,))
simple_quoted_strings = string_template(r"'", r"'",
name="simple_quoted_strings")
double_quoted_strings = string_template(r'"', r'"',
name="double_quoted_strings")
comments = region(r"/\*", r"\*/",
tag=tag_comment,
highlighter=(hl_comment_notes,))
number_literals = simple(r"\b[0-9]*\.?[0-9]+\b", tag=tag_number)
colors = simple(r"#[0-9-a-f-A-F]{3}(?:[0-9-a-f-A-F]{3})?\b", tag=tag_number)
length_units = simple(r"{0}".format(length_units_list), tag=tag_length_units)
length_values = region(r"\b[0-9]", r"\b", tag=tag_number,
highlighter=(length_units,))
properties = words(properties_list, tag=tag_type)
html_elements = words(html_elements_list, tag=tag_keyword)
color_names = words(color_names_list, tag=tag_type)
border_types = words(border_types_list, tag=tag_type)
class_or_id_identifiers = simple(r"(?:\.|#)(?:\w|-)+",
tag=tag_classes_id_identifiers)
gtk_variables = simple(r"@(?:\w|-)+", tag=tag_default)
property_assignment = region(r":", r";",
tag=tag_default,
highlighter=(color_names,
border_types,
colors,
number_literals,
length_values,
comments,
simple_quoted_strings,
double_quoted_strings,
gtk_variables))
blocks = region(r"\{", r"\}",
tag=tag_default,
highlighter=(properties, property_assignment, comments))
#######################
# General highlighter #
#######################
register_highlighter(
language="css",
spec=(html_elements,
number_literals,
colors,
class_or_id_identifiers,
blocks,
comments,
simple_quoted_strings,
double_quoted_strings))
|