@scalar/code-highlight 0.3.5 → 0.3.6

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,12 @@
1
1
  # @scalar/code-highlight
2
2
 
3
+ ## 0.3.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#9508](https://github.com/scalar/scalar/pull/9508): Fix Python code samples appearing mostly unstyled by highlighting function and method call sites
8
+ - [#9506](https://github.com/scalar/scalar/pull/9506): Add Scalar scrollbar styling to highlighted Markdown code blocks.
9
+
3
10
  ## 0.3.5
4
11
 
5
12
  ### Patch Changes
@@ -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,