@scalar/code-highlight 0.3.6 → 0.4.1

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @scalar/code-highlight
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#9659](https://github.com/scalar/scalar/pull/9659): fix: keep rendering Markdown when a code block fails to highlight
8
+
9
+ Syntax highlighting is now best-effort: if a highlight.js grammar throws at runtime (for example a Unicode regex that a production minifier mangles), the code block falls back to plain text instead of the error taking down the whole Markdown section.
10
+
11
+ ## 0.4.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#9590](https://github.com/scalar/scalar/pull/9590): Add syntax highlighting for the Mojo programming language
16
+
3
17
  ## 0.3.6
4
18
 
5
19
  ### Patch Changes
@@ -12686,6 +12686,104 @@ var curlLanguage = (hljs) => {
12686
12686
  };
12687
12687
  };
12688
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
12689
12787
  //#region src/languages/standard.ts
12690
12788
  /**
12691
12789
  * We group languages into three categories based on their popularity and usage.
@@ -12734,6 +12832,7 @@ var standardLanguages = {
12734
12832
  makefile,
12735
12833
  markdown,
12736
12834
  matlab,
12835
+ mojo,
12737
12836
  nginx,
12738
12837
  objectivec,
12739
12838
  ocaml,