highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

Fix/issue 3972

Open akhtarmdsaad opened this issue 2 years ago • 1 comments

Problem: When I use namespace as the name of the variable, everything that follows is highlighted incorrectly. While namespace is a TS keyword it's fine to use it as a variable name too. Solution: Used a multimatcher to solve it

Before:

image

After:

image

Resolves #3972

Changes

Before:

const NAMESPACE = {
    beginKeywords: 'namespace',
    end: /\{/,
    excludeEnd: true,
    contains: [ tsLanguage.exports.CLASS_REFERENCE ]
  };

After:

const NAMESPACE = {
    begin: [
      /namespace/,
      /\s+/,
      hljs.IDENT_RE
    ],
    beginScope: {
      1: "keyword",
      3: "variable"
    },
    end: /\{/,
    excludeEnd: true,
    contains: [tsLanguage.exports.CLASS_REFERENCE]
  };

Checklist

  • [x] Added markup tests, or they don't apply here because...
  • [x] Updated the changelog at CHANGES.md

akhtarmdsaad avatar Feb 18 '24 06:02 akhtarmdsaad

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +40 B

View Changes
file base pr diff
es/core.min.js 8.17 KB 8.17 KB -1 B
es/highlight.min.js 8.17 KB 8.17 KB -1 B
es/languages/typescript.min.js 3.15 KB 3.17 KB +22 B
highlight.min.js 8.21 KB 8.2 KB -2 B
languages/typescript.min.js 3.16 KB 3.18 KB +22 B

github-actions[bot] avatar Feb 18 '24 06:02 github-actions[bot]

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +31 B

View Changes
file base pr diff
es/core.min.js 8.17 KB 8.18 KB +2 B
es/highlight.min.js 8.17 KB 8.18 KB +2 B
es/languages/typescript.min.js 3.15 KB 3.16 KB +12 B
highlight.min.js 8.21 KB 8.21 KB +2 B
languages/typescript.min.js 3.16 KB 3.17 KB +13 B

github-actions[bot] avatar Feb 24 '24 16:02 github-actions[bot]

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

3 files changed

Total change +24 B

View Changes
file base pr diff
es/languages/typescript.min.js 3.15 KB 3.16 KB +12 B
highlight.min.js 8.21 KB 8.21 KB -1 B
languages/typescript.min.js 3.16 KB 3.17 KB +13 B

github-actions[bot] avatar Feb 24 '24 16:02 github-actions[bot]

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

3 files changed

Total change +12 B

View Changes
file base pr diff
es/languages/typescript.min.js 3.15 KB 3.16 KB +6 B
highlight.min.js 8.21 KB 8.21 KB -1 B
languages/typescript.min.js 3.16 KB 3.17 KB +7 B

github-actions[bot] avatar Feb 25 '24 03:02 github-actions[bot]

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

3 files changed

Total change +12 B

View Changes
file base pr diff
es/languages/typescript.min.js 3.15 KB 3.16 KB +6 B
highlight.min.js 8.21 KB 8.21 KB -1 B
languages/typescript.min.js 3.16 KB 3.17 KB +7 B

github-actions[bot] avatar Feb 25 '24 03:02 github-actions[bot]