@primeui-devkit/markdown-core 0.1.0-beta.1 → 0.1.0-beta.2
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 +17 -3
- package/dist/plugins/highlight.d.ts +30 -5
- package/dist/plugins/highlight.js +1 -1
- package/package.json +4 -3
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
*
|
|
27
|
-
*
|
|
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:
|
|
31
|
-
dark:
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
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",
|
|
117
|
-
"@primeui-devkit/test-config": "0.0.0",
|
|
118
118
|
"@primeui-devkit/bundler": "0.0.0",
|
|
119
|
-
"@primeui-devkit/ts-config": "0.0.0"
|
|
119
|
+
"@primeui-devkit/ts-config": "0.0.0",
|
|
120
|
+
"@primeui-devkit/test-config": "0.0.0"
|
|
120
121
|
},
|
|
121
122
|
"publishConfig": {
|
|
122
123
|
"access": "public"
|