@rcarls/rc-textarea-plugin-markdown 0.1.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/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @rcarls/rc-textarea-plugin-markdown
|
|
2
|
+
|
|
3
|
+
Markdown decoration plugin for [@rcarls/rc-textarea](../rc-textarea/). Usable standalone
|
|
4
|
+
on any `rc-textarea` instance.
|
|
5
|
+
|
|
6
|
+
Part of the [rc-webcomponents](https://github.com/richardcarls/rc-webcomponents) library.
|
|
7
|
+
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
10
|
+
Full API, usage examples, and keyboard/accessibility notes are on the
|
|
11
|
+
[rc-webcomponents docs site](https://richardcarls.github.io/rc-webcomponents/).
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { fromMarkdown as l } from "mdast-util-from-markdown";
|
|
2
|
+
import { visit as m } from "unist-util-visit";
|
|
3
|
+
import { micromark as d } from "micromark";
|
|
4
|
+
const u = {
|
|
5
|
+
heading: { bold: !0, className: "rte-heading" },
|
|
6
|
+
emphasis: { italic: !0 },
|
|
7
|
+
strong: { bold: !0 },
|
|
8
|
+
inlineCode: { className: "rte-code" },
|
|
9
|
+
link: { underline: "solid", className: "rte-link" },
|
|
10
|
+
blockquote: { className: "rte-blockquote" }
|
|
11
|
+
};
|
|
12
|
+
function f(t) {
|
|
13
|
+
return d(t);
|
|
14
|
+
}
|
|
15
|
+
function s() {
|
|
16
|
+
return {
|
|
17
|
+
getPreviewHtml: f,
|
|
18
|
+
update(t, a) {
|
|
19
|
+
const c = l(t), e = [];
|
|
20
|
+
m(c, (o) => {
|
|
21
|
+
const r = u[o.type], i = o.position?.start.offset, n = o.position?.end.offset;
|
|
22
|
+
r !== void 0 && i !== void 0 && n !== void 0 && e.push({ type: "mark", from: i, to: n, ...r });
|
|
23
|
+
}), a.setDecorations(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const v = s();
|
|
28
|
+
function w() {
|
|
29
|
+
return s();
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
w as createMarkdownPlugin,
|
|
33
|
+
f as getMarkdownPreviewHtml,
|
|
34
|
+
v as markdownPlugin
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=rc-textarea-plugin-markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rc-textarea-plugin-markdown.js","sources":["../src/markdown-plugin.ts"],"sourcesContent":["import { fromMarkdown } from 'mdast-util-from-markdown';\nimport { visit } from 'unist-util-visit';\nimport { micromark } from 'micromark';\n\nimport type { RCTextareaPlugin, RCTextareaPluginAPI, DecorationInput } from '@rcarls/rc-textarea';\n\n/** Minimal shape of a unist node as used by visit(). */\ninterface VisitNode {\n type: string;\n position?: {\n start: { offset?: number };\n end: { offset?: number };\n };\n}\n\n\n/** Decoration styles applied per MDAST node type. */\nconst DECORATION_MAP: Record<string, Partial<Omit<DecorationInput, 'type' | 'from' | 'to'>>> = {\n heading: { bold: true, className: 'rte-heading' },\n emphasis: { italic: true },\n strong: { bold: true },\n inlineCode: { className: 'rte-code' },\n link: { underline: 'solid', className: 'rte-link' },\n blockquote: { className: 'rte-blockquote' },\n};\n\n/** Render a markdown string to safe HTML using micromark (no raw HTML passthrough). */\nexport function getMarkdownPreviewHtml(value: string): string {\n return micromark(value);\n}\n\nfunction buildPlugin(): RCTextareaPlugin & { getPreviewHtml(value: string): string } {\n return {\n getPreviewHtml: getMarkdownPreviewHtml,\n\n update(value: string, api: RCTextareaPluginAPI): void {\n const tree = fromMarkdown(value);\n const decorations: DecorationInput[] = [];\n\n visit(tree, (node: VisitNode) => {\n const style = DECORATION_MAP[node.type];\n const start = node.position?.start.offset;\n const end = node.position?.end.offset;\n\n if (style !== undefined && start !== undefined && end !== undefined) {\n decorations.push({ type: 'mark', from: start, to: end, ...style } as DecorationInput);\n }\n });\n\n api.setDecorations(decorations);\n },\n };\n}\n\n/** Singleton markdown plugin. Use when a single instance is sufficient. */\nexport const markdownPlugin = buildPlugin();\n\n/** Factory for cases where multiple independent instances are needed. */\nexport function createMarkdownPlugin(): RCTextareaPlugin & {\n getPreviewHtml(value: string): string;\n} {\n return buildPlugin();\n}\n"],"names":["DECORATION_MAP","getMarkdownPreviewHtml","value","micromark","buildPlugin","api","tree","fromMarkdown","decorations","visit","node","style","start","end","markdownPlugin","createMarkdownPlugin"],"mappings":";;;AAiBA,MAAMA,IAAyF;AAAA,EAC7F,SAAY,EAAE,MAAM,IAAM,WAAW,cAAA;AAAA,EACrC,UAAY,EAAE,QAAQ,GAAA;AAAA,EACtB,QAAY,EAAE,MAAM,GAAA;AAAA,EACpB,YAAY,EAAE,WAAW,WAAA;AAAA,EACzB,MAAY,EAAE,WAAW,SAAS,WAAW,WAAA;AAAA,EAC7C,YAAY,EAAE,WAAW,iBAAA;AAC3B;AAGO,SAASC,EAAuBC,GAAuB;AAC5D,SAAOC,EAAUD,CAAK;AACxB;AAEA,SAASE,IAA4E;AACnF,SAAO;AAAA,IACL,gBAAgBH;AAAA,IAEhB,OAAOC,GAAeG,GAAgC;AACpD,YAAMC,IAAOC,EAAaL,CAAK,GACzBM,IAAiC,CAAA;AAEvC,MAAAC,EAAMH,GAAM,CAACI,MAAoB;AAC/B,cAAMC,IAAQX,EAAeU,EAAK,IAAI,GAChCE,IAAQF,EAAK,UAAU,MAAM,QAC7BG,IAAMH,EAAK,UAAU,IAAI;AAE/B,QAAIC,MAAU,UAAaC,MAAU,UAAaC,MAAQ,UACxDL,EAAY,KAAK,EAAE,MAAM,QAAQ,MAAMI,GAAO,IAAIC,GAAK,GAAGF,GAA0B;AAAA,MAExF,CAAC,GAEDN,EAAI,eAAeG,CAAW;AAAA,IAChC;AAAA,EAAA;AAEJ;AAGO,MAAMM,IAAiBV,EAAA;AAGvB,SAASW,IAEd;AACA,SAAOX,EAAA;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { markdownPlugin, createMarkdownPlugin, getMarkdownPreviewHtml } from './markdown-plugin.ts';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RCTextareaPlugin } from '@rcarls/rc-textarea';
|
|
2
|
+
/** Render a markdown string to safe HTML using micromark (no raw HTML passthrough). */
|
|
3
|
+
export declare function getMarkdownPreviewHtml(value: string): string;
|
|
4
|
+
/** Singleton markdown plugin. Use when a single instance is sufficient. */
|
|
5
|
+
export declare const markdownPlugin: RCTextareaPlugin & {
|
|
6
|
+
getPreviewHtml(value: string): string;
|
|
7
|
+
};
|
|
8
|
+
/** Factory for cases where multiple independent instances are needed. */
|
|
9
|
+
export declare function createMarkdownPlugin(): RCTextareaPlugin & {
|
|
10
|
+
getPreviewHtml(value: string): string;
|
|
11
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rcarls/rc-textarea-plugin-markdown",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"description": "Markdown decoration plugin for rc-textarea",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/richardcarls/rc-webcomponents.git",
|
|
11
|
+
"directory": "packages/rc-textarea-plugin-markdown"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/richardcarls/rc-webcomponents#readme",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"module": "./dist/rc-textarea-plugin-markdown.js",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/types/packages/rc-textarea-plugin-markdown/src/index.d.ts",
|
|
24
|
+
"default": "./dist/rc-textarea-plugin-markdown.js"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"types": "./dist/types/packages/rc-textarea-plugin-markdown/src/index.d.ts",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc && vite build",
|
|
32
|
+
"yalc:publish": "yalc publish --push"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@rcarls/rc-textarea": "workspace:^",
|
|
36
|
+
"mdast-util-from-markdown": "^2.0.2",
|
|
37
|
+
"micromark": "^4.0.2",
|
|
38
|
+
"typescript": "~5.9.3",
|
|
39
|
+
"unist-util-visit": "^5.0.0",
|
|
40
|
+
"vite": "^7.1.7",
|
|
41
|
+
"vite-plugin-dts": "^4.5.4"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@rcarls/rc-textarea": "workspace:^",
|
|
45
|
+
"mdast-util-from-markdown": ">=2.0.0",
|
|
46
|
+
"micromark": ">=4.0.0",
|
|
47
|
+
"unist-util-visit": ">=5.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|