@scalar/code-highlight 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/chunks/languages.js +142 -1
- package/dist/chunks/languages.js.map +1 -1
- package/dist/chunks/markdown.js +2 -1
- package/dist/chunks/markdown.js.map +1 -1
- package/dist/chunks/rehype-highlight.js +2 -0
- package/dist/chunks/rehype-highlight.js.map +1 -1
- package/dist/css/code.css +0 -4
- package/dist/languages/basic.d.ts.map +1 -1
- package/dist/languages/mojo.d.ts +18 -0
- package/dist/languages/mojo.d.ts.map +1 -0
- package/dist/languages/python.d.ts +22 -0
- package/dist/languages/python.d.ts.map +1 -0
- package/dist/languages/standard.d.ts +1 -0
- package/dist/languages/standard.d.ts.map +1 -1
- package/dist/markdown/markdown.d.ts.map +1 -1
- package/dist/rehype-highlight/rehype-highlight.d.ts +2 -0
- package/dist/rehype-highlight/rehype-highlight.d.ts.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @scalar/code-highlight
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#9590](https://github.com/scalar/scalar/pull/9590): Add syntax highlighting for the Mojo programming language
|
|
8
|
+
|
|
9
|
+
## 0.3.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#9508](https://github.com/scalar/scalar/pull/9508): Fix Python code samples appearing mostly unstyled by highlighting function and method call sites
|
|
14
|
+
- [#9506](https://github.com/scalar/scalar/pull/9506): Add Scalar scrollbar styling to highlighted Markdown code blocks.
|
|
15
|
+
|
|
3
16
|
## 0.3.5
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/chunks/languages.js
CHANGED
|
@@ -8191,7 +8191,7 @@ function plaintext(hljs) {
|
|
|
8191
8191
|
}
|
|
8192
8192
|
//#endregion
|
|
8193
8193
|
//#region ../../node_modules/.pnpm/highlight.js@11.11.1/node_modules/highlight.js/es/languages/python.js
|
|
8194
|
-
function python(hljs) {
|
|
8194
|
+
function python$1(hljs) {
|
|
8195
8195
|
const regex = hljs.regex;
|
|
8196
8196
|
const IDENT_RE = /[\p{XID_Start}_]\p{XID_Continue}*/u;
|
|
8197
8197
|
const RESERVED_WORDS = [
|
|
@@ -12540,6 +12540,48 @@ function yaml(hljs) {
|
|
|
12540
12540
|
};
|
|
12541
12541
|
}
|
|
12542
12542
|
//#endregion
|
|
12543
|
+
//#region src/languages/python.ts
|
|
12544
|
+
/**
|
|
12545
|
+
* Python grammar that extends highlight.js' bundled grammar with call-site
|
|
12546
|
+
* highlighting.
|
|
12547
|
+
*
|
|
12548
|
+
* The grammar shipped with highlight.js only scopes function and class
|
|
12549
|
+
* *definitions* (`def name`, `class Name`) plus a fixed list of built-ins. It
|
|
12550
|
+
* never scopes *call sites*, unlike the JavaScript, Go, and Ruby grammars which
|
|
12551
|
+
* colour every `.method()` as a function title. Because real-world API snippets
|
|
12552
|
+
* are almost entirely method calls (for example `conn.request(...)` or
|
|
12553
|
+
* `response.json()`), Python code rendered as a wall of unstyled grey text and
|
|
12554
|
+
* looked far less highlighted than other languages (DOC-5618).
|
|
12555
|
+
*
|
|
12556
|
+
* We add a single rule that colours any identifier immediately followed by `(`
|
|
12557
|
+
* as a function title, mirroring how highlight.js' own JavaScript grammar
|
|
12558
|
+
* handles this. Reserved words and the grammar's known built-ins, literals, and
|
|
12559
|
+
* types are excluded so they keep their existing scopes, and the leading word
|
|
12560
|
+
* boundary prevents the rule from matching the tail end of an excluded word.
|
|
12561
|
+
*/
|
|
12562
|
+
var python = (hljs) => {
|
|
12563
|
+
const language = python$1(hljs);
|
|
12564
|
+
const { regex } = hljs;
|
|
12565
|
+
const IDENT_RE = /[\p{XID_Start}_]\p{XID_Continue}*/u;
|
|
12566
|
+
const keywords = language.keywords;
|
|
12567
|
+
const reserved = [
|
|
12568
|
+
...keywords.keyword ?? [],
|
|
12569
|
+
...keywords.built_in ?? [],
|
|
12570
|
+
...keywords.literal ?? [],
|
|
12571
|
+
...keywords.type ?? []
|
|
12572
|
+
].map((word) => word.replace(/\|\d+$/, ""));
|
|
12573
|
+
const notReserved = regex.concat("(?!(?:", reserved.join("|"), ")\\b)");
|
|
12574
|
+
const functionCall = {
|
|
12575
|
+
scope: "title.function",
|
|
12576
|
+
relevance: 0,
|
|
12577
|
+
match: regex.concat(/\b/, notReserved, IDENT_RE, regex.lookahead(/\s*\(/))
|
|
12578
|
+
};
|
|
12579
|
+
return {
|
|
12580
|
+
...language,
|
|
12581
|
+
contains: [...language.contains ?? [], functionCall]
|
|
12582
|
+
};
|
|
12583
|
+
};
|
|
12584
|
+
//#endregion
|
|
12543
12585
|
//#region src/languages/basic.ts
|
|
12544
12586
|
var basicLanguages = {
|
|
12545
12587
|
bash,
|
|
@@ -12644,6 +12686,104 @@ var curlLanguage = (hljs) => {
|
|
|
12644
12686
|
};
|
|
12645
12687
|
};
|
|
12646
12688
|
//#endregion
|
|
12689
|
+
//#region src/languages/mojo.ts
|
|
12690
|
+
/**
|
|
12691
|
+
* Mojo grammar.
|
|
12692
|
+
*
|
|
12693
|
+
* highlight.js does not ship a Mojo grammar and there is no community package
|
|
12694
|
+
* for it (the only upstream "mojo" grammar is the unrelated Perl Mojolicious
|
|
12695
|
+
* framework). We build one here. Mojo is a superset of Python, so we start from
|
|
12696
|
+
* the bundled Python grammar and layer on the extra keywords, argument-convention
|
|
12697
|
+
* modifiers, and standard-library types that Mojo adds. The keyword and type
|
|
12698
|
+
* lists mirror Modular's official TextMate grammar (github.com/modular/mojo-syntax).
|
|
12699
|
+
*
|
|
12700
|
+
* As with our custom Python grammar, we also colour call sites as function
|
|
12701
|
+
* titles so that API snippets, which are mostly method calls, do not render as a
|
|
12702
|
+
* wall of unstyled grey text.
|
|
12703
|
+
*/
|
|
12704
|
+
var mojo = (hljs) => {
|
|
12705
|
+
const language = python$1(hljs);
|
|
12706
|
+
const { regex } = hljs;
|
|
12707
|
+
const IDENT_RE = /[\p{XID_Start}_]\p{XID_Continue}*/u;
|
|
12708
|
+
const keywords = language.keywords;
|
|
12709
|
+
const mojoKeywords = [
|
|
12710
|
+
"fn",
|
|
12711
|
+
"struct",
|
|
12712
|
+
"trait",
|
|
12713
|
+
"var",
|
|
12714
|
+
"let",
|
|
12715
|
+
"alias",
|
|
12716
|
+
"comptime",
|
|
12717
|
+
"owned",
|
|
12718
|
+
"borrowed",
|
|
12719
|
+
"inout",
|
|
12720
|
+
"ref",
|
|
12721
|
+
"mut",
|
|
12722
|
+
"read",
|
|
12723
|
+
"out",
|
|
12724
|
+
"raises",
|
|
12725
|
+
"capturing"
|
|
12726
|
+
];
|
|
12727
|
+
const mojoTypes = [
|
|
12728
|
+
"Int",
|
|
12729
|
+
"UInt",
|
|
12730
|
+
"Int8",
|
|
12731
|
+
"Int16",
|
|
12732
|
+
"Int32",
|
|
12733
|
+
"Int64",
|
|
12734
|
+
"UInt8",
|
|
12735
|
+
"UInt16",
|
|
12736
|
+
"UInt32",
|
|
12737
|
+
"UInt64",
|
|
12738
|
+
"Float16",
|
|
12739
|
+
"Float32",
|
|
12740
|
+
"Float64",
|
|
12741
|
+
"Bool",
|
|
12742
|
+
"String",
|
|
12743
|
+
"StringLiteral",
|
|
12744
|
+
"StringSlice",
|
|
12745
|
+
"SIMD",
|
|
12746
|
+
"DType",
|
|
12747
|
+
"Scalar",
|
|
12748
|
+
"List",
|
|
12749
|
+
"Dict",
|
|
12750
|
+
"Set",
|
|
12751
|
+
"Tuple",
|
|
12752
|
+
"Optional",
|
|
12753
|
+
"Variant",
|
|
12754
|
+
"Span",
|
|
12755
|
+
"Pointer",
|
|
12756
|
+
"UnsafePointer",
|
|
12757
|
+
"Reference",
|
|
12758
|
+
"Error"
|
|
12759
|
+
];
|
|
12760
|
+
const dedupe = (...lists) => Array.from(new Set(lists.flat()));
|
|
12761
|
+
const mergedKeywords = {
|
|
12762
|
+
...keywords,
|
|
12763
|
+
keyword: dedupe(keywords.keyword ?? [], mojoKeywords),
|
|
12764
|
+
type: dedupe(keywords.type ?? [], mojoTypes)
|
|
12765
|
+
};
|
|
12766
|
+
const reserved = [
|
|
12767
|
+
...mergedKeywords.keyword ?? [],
|
|
12768
|
+
...keywords.built_in ?? [],
|
|
12769
|
+
...keywords.literal ?? [],
|
|
12770
|
+
...mergedKeywords.type ?? []
|
|
12771
|
+
].map((word) => word.replace(/\|\d+$/, ""));
|
|
12772
|
+
const notReserved = regex.concat("(?!(?:", reserved.join("|"), ")\\b)");
|
|
12773
|
+
const functionCall = {
|
|
12774
|
+
scope: "title.function",
|
|
12775
|
+
relevance: 0,
|
|
12776
|
+
match: regex.concat(/\b/, notReserved, IDENT_RE, regex.lookahead(/\(/))
|
|
12777
|
+
};
|
|
12778
|
+
return {
|
|
12779
|
+
...language,
|
|
12780
|
+
name: "Mojo",
|
|
12781
|
+
aliases: ["mojo", "🔥"],
|
|
12782
|
+
keywords: mergedKeywords,
|
|
12783
|
+
contains: [...language.contains ?? [], functionCall]
|
|
12784
|
+
};
|
|
12785
|
+
};
|
|
12786
|
+
//#endregion
|
|
12647
12787
|
//#region src/languages/standard.ts
|
|
12648
12788
|
/**
|
|
12649
12789
|
* We group languages into three categories based on their popularity and usage.
|
|
@@ -12692,6 +12832,7 @@ var standardLanguages = {
|
|
|
12692
12832
|
makefile,
|
|
12693
12833
|
markdown,
|
|
12694
12834
|
matlab,
|
|
12835
|
+
mojo,
|
|
12695
12836
|
nginx,
|
|
12696
12837
|
objectivec,
|
|
12697
12838
|
ocaml,
|