Skip to content

Commit

Permalink
enh(css): support SVG highlighting (#3893)
Browse files Browse the repository at this point in the history
* enh(css): support svg properties
* enh(css): support svg elements
* Separate the TAGS into HTML_TAGS and SVG_TAGS
  • Loading branch information
MohamedAli00949 committed Oct 21, 2023
1 parent a5cec83 commit 17494c8
Showing 1 changed file with 89 additions and 1 deletion.
90 changes: 89 additions & 1 deletion src/languages/lib/css-shared.js
Expand Up @@ -43,7 +43,7 @@ export const MODES = (hljs) => {
};
};

export const TAGS = [
const HTML_TAGS = [
'a',
'abbr',
'address',
Expand Down Expand Up @@ -118,6 +118,55 @@ export const TAGS = [
'video'
];

const SVG_TAGS = [
'defs',
'g',
'marker',
'mask',
'pattern',
'svg',
'switch',
'symbol',
'feBlend',
'feColorMatrix',
'feComponentTransfer',
'feComposite',
'feConvolveMatrix',
'feDiffuseLighting',
'feDisplacementMap',
'feFlood',
'feGaussianBlur',
'feImage',
'feMerge',
'feMorphology',
'feOffset',
'feSpecularLighting',
'feTile',
'feTurbulence',
'linearGradient',
'radialGradient',
'stop',
'circle',
'ellipse',
'image',
'line',
'path',
'polygon',
'polyline',
'rect',
'text',
'use',
'textPath',
'tspan',
'foreignObject',
'clipPath'
];

export const TAGS = [
...HTML_TAGS,
...SVG_TAGS,
];

// Sorting, then reversing makes sure longer attributes/elements like
// `font-weight` are matched fully instead of getting false positives on say `font`

Expand Down Expand Up @@ -243,6 +292,7 @@ export const ATTRIBUTES = [
'align-content',
'align-items',
'align-self',
'alignment-baseline',
'all',
'animation',
'animation-delay',
Expand All @@ -264,6 +314,7 @@ export const ATTRIBUTES = [
'background-position',
'background-repeat',
'background-size',
'baseline-shift',
'block-size',
'border',
'border-block',
Expand Down Expand Up @@ -329,13 +380,19 @@ export const ATTRIBUTES = [
'break-after',
'break-before',
'break-inside',
'cx',
'cy',
'caption-side',
'caret-color',
'clear',
'clip',
'clip-path',
'clip-rule',
'color',
'color-interpolation',
'color-interpolation-filters',
'color-profile',
'color-rendering',
'column-count',
'column-fill',
'column-gap',
Expand All @@ -357,7 +414,12 @@ export const ATTRIBUTES = [
'cursor',
'direction',
'display',
'dominant-baseline',
'empty-cells',
'enable-background',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'flex',
'flex-basis',
Expand All @@ -368,6 +430,8 @@ export const ATTRIBUTES = [
'flex-wrap',
'float',
'flow',
'flood-color',
'flood-opacity',
'font',
'font-display',
'font-family',
Expand All @@ -389,6 +453,7 @@ export const ATTRIBUTES = [
'font-variation-settings',
'font-weight',
'gap',
'glyph-orientation-horizontal',
'glyph-orientation-vertical',
'grid',
'grid-area',
Expand Down Expand Up @@ -416,15 +481,22 @@ export const ATTRIBUTES = [
'ime-mode',
'inline-size',
'isolation',
'kerning',
'justify-content',
'left',
'letter-spacing',
'lighting-color',
'line-break',
'line-height',
'list-style',
'list-style-image',
'list-style-position',
'list-style-type',
'marker',
'marker-end',
'marker-mid',
'marker-start',
'mask',
'margin',
'margin-block',
'margin-block-end',
Expand Down Expand Up @@ -506,6 +578,7 @@ export const ATTRIBUTES = [
'pointer-events',
'position',
'quotes',
'r',
'resize',
'rest',
'rest-after',
Expand Down Expand Up @@ -543,11 +616,23 @@ export const ATTRIBUTES = [
'shape-image-threshold',
'shape-margin',
'shape-outside',
'shape-rendering',
'stop-color',
'stop-opacity',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'speak',
'speak-as',
'src', // @font-face
'tab-size',
'table-layout',
'text-anchor',
'text-align',
'text-align-all',
'text-align-last',
Expand Down Expand Up @@ -579,6 +664,7 @@ export const ATTRIBUTES = [
'transition-property',
'transition-timing-function',
'unicode-bidi',
'vector-effect',
'vertical-align',
'visibility',
'voice-balance',
Expand All @@ -597,6 +683,8 @@ export const ATTRIBUTES = [
'word-spacing',
'word-wrap',
'writing-mode',
'x',
'y',
'z-index'
].sort().reverse();

Expand Down

0 comments on commit 17494c8

Please sign in to comment.