@primeui-devkit/markdown-core 0.1.0-beta.1 → 0.1.0-rc.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/README.md CHANGED
@@ -48,14 +48,28 @@ const tree = await highlightTree(await parse(source));
48
48
  Both themes are emitted at once, so a page switches between light and dark without
49
49
  highlighting anything again.
50
50
 
51
- Only registered themes work. Passing a name the backend does not know produces
52
- unhighlighted output without reporting anything, so `highlightTree` checks first and
53
- throws with the list of what is available — `availableThemes()` returns the same list.
51
+ Passing a theme name the backend does not know produces unhighlighted output without
52
+ reporting anything, so `highlightTree` checks names first and throws with the list of what
53
+ is available — `availableThemes()` returns the same list.
54
54
 
55
55
  ```ts
56
56
  await highlightTree(tree, { themes: { light: 'material-theme-lighter', dark: 'material-theme-palenight' } });
57
57
  ```
58
58
 
59
+ A theme the backend does not ship is passed as a definition instead of a name. `languages`
60
+ preloads grammars, which keeps a build to the ones it uses rather than loading every one on
61
+ demand, and `transformers` is where line markers such as `[!code highlight]` come from.
62
+
63
+ ```ts
64
+ import { transformerNotationHighlight } from '@shikijs/transformers';
65
+
66
+ await highlightTree(tree, {
67
+ themes: { light: (await import('shiki/themes/github-light.mjs')).default, dark: 'material-theme-palenight' },
68
+ languages: [(await import('shiki/langs/vue.mjs')).default],
69
+ transformers: [transformerNotationHighlight()]
70
+ });
71
+ ```
72
+
59
73
  `@primeui-devkit/highlighter` is a separate package for highlighting a standalone snippet
60
74
  to HTML. Neither depends on the other: this one works on a parsed tree, that one on a
61
75
  string, and a repository takes whichever it needs.
@@ -18,18 +18,43 @@ import { ComarkPlugin, ComarkTree } from 'comark';
18
18
  * would tie every caller to that engine through a package whose whole purpose is to keep
19
19
  * it out of sight.
20
20
  */
21
+ /**
22
+ * A theme, either by name or as a full definition.
23
+ *
24
+ * The definition form is deliberately opaque: describing it would pull the highlighting
25
+ * engine's types into this package's public surface, which is what it exists to avoid.
26
+ * Pass the value a `shiki/themes/*` module default-exports.
27
+ */
28
+ type HighlightTheme = string | (object & {
29
+ name?: string;
30
+ });
31
+ /** A language definition, as a `shiki/langs/*` module default-exports. */
32
+ type HighlightLanguage = object;
33
+ /** A code-block transformer, as `@shikijs/transformers` returns. */
34
+ type HighlightTransformer = object;
21
35
  interface HighlightOptions {
22
36
  /**
23
37
  * Themes to render with. Both are emitted, so a page can switch between light and dark
24
38
  * without highlighting anything again.
25
39
  *
26
- * Only registered themes work. A name the backend does not know leaves every block
27
- * unhighlighted without reporting anything, so {@link highlightTree} checks first.
40
+ * A registered name works, as does a theme definition — pass the latter to use a theme
41
+ * the backend does not ship. Names are checked first, because a name the backend does
42
+ * not know leaves every block unhighlighted without reporting anything.
28
43
  */
29
44
  themes?: {
30
- light: string;
31
- dark: string;
45
+ light: HighlightTheme;
46
+ dark: HighlightTheme;
32
47
  };
48
+ /**
49
+ * Languages to preload. Left unset, languages load on demand, which needs the backend's
50
+ * full bundle; preloading keeps a build to the grammars it actually uses.
51
+ */
52
+ languages?: HighlightLanguage[];
53
+ /**
54
+ * Transformers applied to every block — line markers such as `[!code highlight]` come
55
+ * from these.
56
+ */
57
+ transformers?: HighlightTransformer[];
33
58
  /** Whether to inline the theme's background and colour on the block. Defaults to `false`. */
34
59
  inlineStyles?: boolean;
35
60
  }
@@ -64,4 +89,4 @@ declare function highlightTree(tree: ComarkTree, options?: HighlightOptions): Pr
64
89
  */
65
90
  declare function highlight(options?: HighlightOptions): ComarkPlugin<any, any>;
66
91
 
67
- export { type HighlightOptions, availableThemes, highlight as default, defaultThemes, highlightTree };
92
+ export { type HighlightLanguage, type HighlightOptions, type HighlightTheme, type HighlightTransformer, availableThemes, highlight as default, defaultThemes, highlightTree };
@@ -1 +1 @@
1
- import s,{getHighlighter,highlightCodeBlocks}from'comark/plugins/highlight';var c={light:"material-theme-lighter",dark:"material-theme-palenight"};async function g(){return (await getHighlighter()).getLoadedThemes?.()??[]}async function p(t,i={}){let{themes:e,inlineStyles:a=false}=i;if(e){let r=await g(),n=[e.light,e.dark].filter(l=>!r.includes(l));if(n.length>0)throw new Error(`Unknown theme${n.length>1?"s":""}: ${n.join(", ")}. Available: ${r.join(", ")}.`)}return await highlightCodeBlocks(t,{...e?{themes:e}:{},preStyles:a})}function m(t={}){let{themes:i,inlineStyles:e=false}=t;return s({...i?{themes:i}:{},preStyles:e})}export{g as availableThemes,m as default,c as defaultThemes,p as highlightTree};
1
+ import l,{getHighlighter,highlightCodeBlocks}from'comark/plugins/highlight';var c=e=>e?[e.light,e.dark].filter(t=>typeof t=="string"):[],y={light:"material-theme-lighter",dark:"material-theme-palenight"};async function d(){return (await getHighlighter()).getLoadedThemes?.()??[]}async function T(e,t={}){let{themes:i,languages:n,transformers:r,inlineStyles:s=false}=t,g=c(i);if(g.length>0){let h=await d(),a=g.filter(o=>!h.includes(o));if(a.length>0)throw new Error(`Unknown theme${a.length>1?"s":""}: ${a.join(", ")}. Available: ${h.join(", ")}.`)}return await highlightCodeBlocks(e,{...i?{themes:i}:{},...n?{languages:n}:{},...r?{transformers:r}:{},preStyles:s})}function f(e={}){let{themes:t,languages:i,transformers:n,inlineStyles:r=false}=e;return l({...t?{themes:t}:{},...i?{languages:i}:{},...n?{transformers:n}:{},preStyles:r})}export{d as availableThemes,f as default,y as defaultThemes,T as highlightTree};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primeui-devkit/markdown-core",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-rc.1",
4
4
  "description": "Framework-agnostic markdown engine. Parses markdown with component directives into a serializable tree consumed by the framework renderers. The parsing backend is an internal implementation detail.",
5
5
  "author": "PrimeTek Informatics",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -110,13 +110,14 @@
110
110
  }
111
111
  },
112
112
  "devDependencies": {
113
+ "@shikijs/transformers": "^4.4.2",
113
114
  "cross-env": "^10.1.0",
114
115
  "tsup": "^8.5.1",
115
116
  "typescript": "~6.0.0",
116
117
  "vitest": "4.1.10",
118
+ "@primeui-devkit/ts-config": "0.0.0",
117
119
  "@primeui-devkit/test-config": "0.0.0",
118
- "@primeui-devkit/bundler": "0.0.0",
119
- "@primeui-devkit/ts-config": "0.0.0"
120
+ "@primeui-devkit/bundler": "0.0.0"
120
121
  },
121
122
  "publishConfig": {
122
123
  "access": "public"