vue3-markdown-kit 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/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/NOTICE.md +16 -0
- package/README.md +177 -0
- package/SECURITY.md +14 -0
- package/lib/core.cjs +197 -0
- package/lib/core.cjs.map +7 -0
- package/lib/core.js +165 -0
- package/lib/core.js.map +7 -0
- package/lib/index.cjs +363 -0
- package/lib/index.cjs.map +7 -0
- package/lib/index.js +331 -0
- package/lib/index.js.map +7 -0
- package/lib/preview.cjs +325 -0
- package/lib/preview.cjs.map +7 -0
- package/lib/preview.js +295 -0
- package/lib/preview.js.map +7 -0
- package/lib/style/preview.css +23 -0
- package/lib/theme/github.cjs +143 -0
- package/lib/theme/github.cjs.map +7 -0
- package/lib/theme/github.js +111 -0
- package/lib/theme/github.js.map +7 -0
- package/lib/theme/style/github.css +187 -0
- package/package.json +112 -0
- package/types/core.d.ts +40 -0
- package/types/index.d.ts +20 -0
- package/types/preview.d.ts +39 -0
- package/types/theme-github.d.ts +15 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// src/core/renderer.js
|
|
2
|
+
import MarkdownIt from "markdown-it";
|
|
3
|
+
import markdownItAttrs from "markdown-it-attrs";
|
|
4
|
+
function escapeHtml(value) {
|
|
5
|
+
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
6
|
+
}
|
|
7
|
+
function slugifyHeading(value) {
|
|
8
|
+
const slug = String(value || "").normalize("NFKC").trim().toLowerCase().replace(/\s+/g, "-").replace(/[^\p{Letter}\p{Number}_-]+/gu, "").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
|
|
9
|
+
return slug || "section";
|
|
10
|
+
}
|
|
11
|
+
function highlightCode(code, language, options) {
|
|
12
|
+
const {
|
|
13
|
+
Hljs,
|
|
14
|
+
codeHighlightExtensionMap = {},
|
|
15
|
+
codeBlockClass = (lang) => `v-md-hljs-${lang || ""}`
|
|
16
|
+
} = options;
|
|
17
|
+
const normalizedLanguage = codeHighlightExtensionMap[language] || language;
|
|
18
|
+
let highlighted = escapeHtml(code);
|
|
19
|
+
if (Hljs && normalizedLanguage && typeof Hljs.getLanguage === "function" && Hljs.getLanguage(normalizedLanguage)) {
|
|
20
|
+
try {
|
|
21
|
+
highlighted = Hljs.highlight(code, {
|
|
22
|
+
language: normalizedLanguage,
|
|
23
|
+
ignoreIllegals: true
|
|
24
|
+
}).value;
|
|
25
|
+
} catch {
|
|
26
|
+
highlighted = Hljs.highlight(normalizedLanguage, code, true).value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return `<pre class="${escapeHtml(codeBlockClass(normalizedLanguage))}"><code>${highlighted}</code></pre>`;
|
|
30
|
+
}
|
|
31
|
+
function installHeadingAnchors(parser) {
|
|
32
|
+
parser.core.ruler.before("block", "vue_markdown_kit_heading_state", (state) => {
|
|
33
|
+
state.env.__vueMarkdownKitHeadingSlugs = /* @__PURE__ */ new Map();
|
|
34
|
+
});
|
|
35
|
+
const fallback = parser.renderer.rules.heading_open || ((tokens, index, options, _env, self) => self.renderToken(tokens, index, options));
|
|
36
|
+
parser.renderer.rules.heading_open = (tokens, index, options, env, self) => {
|
|
37
|
+
const inline = tokens[index + 1];
|
|
38
|
+
const baseSlug = slugifyHeading(inline && inline.content);
|
|
39
|
+
const slugs = env.__vueMarkdownKitHeadingSlugs || /* @__PURE__ */ new Map();
|
|
40
|
+
const count = slugs.get(baseSlug) || 0;
|
|
41
|
+
const slug = count === 0 ? baseSlug : `${baseSlug}-${count}`;
|
|
42
|
+
slugs.set(baseSlug, count + 1);
|
|
43
|
+
env.__vueMarkdownKitHeadingSlugs = slugs;
|
|
44
|
+
tokens[index].attrSet("id", slug);
|
|
45
|
+
tokens[index].attrSet("data-v-md-heading", slug);
|
|
46
|
+
return fallback(tokens, index, options, env, self);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function installSafeExternalLinks(parser) {
|
|
50
|
+
const fallback = parser.renderer.rules.link_open || ((tokens, index, options, _env, self) => self.renderToken(tokens, index, options));
|
|
51
|
+
parser.renderer.rules.link_open = (tokens, index, options, env, self) => {
|
|
52
|
+
const token = tokens[index];
|
|
53
|
+
const href = token.attrGet("href") || "";
|
|
54
|
+
if (/^https?:\/\//i.test(href)) {
|
|
55
|
+
token.attrSet("target", "_blank");
|
|
56
|
+
token.attrSet("rel", "noopener noreferrer");
|
|
57
|
+
}
|
|
58
|
+
return fallback(tokens, index, options, env, self);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function createMarkdownRenderer(options = {}) {
|
|
62
|
+
var _a, _b, _c, _d;
|
|
63
|
+
const parser = new MarkdownIt({
|
|
64
|
+
html: (_a = options.html) != null ? _a : true,
|
|
65
|
+
breaks: (_b = options.breaks) != null ? _b : true,
|
|
66
|
+
linkify: (_c = options.linkify) != null ? _c : false,
|
|
67
|
+
typographer: (_d = options.typographer) != null ? _d : true,
|
|
68
|
+
highlight: (code, language) => highlightCode(code, language, options)
|
|
69
|
+
});
|
|
70
|
+
if (options.attrs !== false) {
|
|
71
|
+
parser.use(markdownItAttrs, {
|
|
72
|
+
leftDelimiter: "{{{",
|
|
73
|
+
rightDelimiter: "}}}",
|
|
74
|
+
allowedAttributes: [
|
|
75
|
+
"class",
|
|
76
|
+
"height",
|
|
77
|
+
"id",
|
|
78
|
+
"title",
|
|
79
|
+
"width",
|
|
80
|
+
...options.allowedAttributes || []
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
installHeadingAnchors(parser);
|
|
85
|
+
installSafeExternalLinks(parser);
|
|
86
|
+
return parser;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/theme/github.js
|
|
90
|
+
function createGithubTheme(options = {}) {
|
|
91
|
+
const markdownParser = createMarkdownRenderer(options);
|
|
92
|
+
return {
|
|
93
|
+
name: "github",
|
|
94
|
+
previewClass: "github-markdown-body",
|
|
95
|
+
markdownParser,
|
|
96
|
+
extend(callback) {
|
|
97
|
+
callback(markdownParser, options.Hljs);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
var githubTheme = {
|
|
102
|
+
install(VMdPreview, options = {}) {
|
|
103
|
+
VMdPreview.theme(createGithubTheme(options));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var github_default = githubTheme;
|
|
107
|
+
export {
|
|
108
|
+
createGithubTheme,
|
|
109
|
+
github_default as default
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=github.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/core/renderer.js", "../../src/theme/github.js"],
|
|
4
|
+
"sourcesContent": ["import MarkdownIt from 'markdown-it'\nimport markdownItAttrs from 'markdown-it-attrs'\n\nfunction escapeHtml(value) {\n return String(value)\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n}\n\nexport function slugifyHeading(value) {\n const slug = String(value || '')\n .normalize('NFKC')\n .trim()\n .toLowerCase()\n .replace(/\\s+/g, '-')\n .replace(/[^\\p{Letter}\\p{Number}_-]+/gu, '')\n .replace(/-{2,}/g, '-')\n .replace(/^-|-$/g, '')\n\n return slug || 'section'\n}\n\nfunction highlightCode(code, language, options) {\n const {\n Hljs,\n codeHighlightExtensionMap = {},\n codeBlockClass = (lang) => `v-md-hljs-${lang || ''}`,\n } = options\n\n const normalizedLanguage = codeHighlightExtensionMap[language] || language\n let highlighted = escapeHtml(code)\n\n if (\n Hljs &&\n normalizedLanguage &&\n typeof Hljs.getLanguage === 'function' &&\n Hljs.getLanguage(normalizedLanguage)\n ) {\n try {\n highlighted = Hljs.highlight(code, {\n language: normalizedLanguage,\n ignoreIllegals: true,\n }).value\n } catch {\n // highlight.js 10 compatibility.\n highlighted = Hljs.highlight(normalizedLanguage, code, true).value\n }\n }\n\n return `<pre class=\"${escapeHtml(codeBlockClass(normalizedLanguage))}\"><code>${highlighted}</code></pre>`\n}\n\nfunction installHeadingAnchors(parser) {\n parser.core.ruler.before('block', 'vue_markdown_kit_heading_state', (state) => {\n state.env.__vueMarkdownKitHeadingSlugs = new Map()\n })\n\n const fallback =\n parser.renderer.rules.heading_open ||\n ((tokens, index, options, _env, self) => self.renderToken(tokens, index, options))\n\n parser.renderer.rules.heading_open = (tokens, index, options, env, self) => {\n const inline = tokens[index + 1]\n const baseSlug = slugifyHeading(inline && inline.content)\n const slugs = env.__vueMarkdownKitHeadingSlugs || new Map()\n const count = slugs.get(baseSlug) || 0\n const slug = count === 0 ? baseSlug : `${baseSlug}-${count}`\n\n slugs.set(baseSlug, count + 1)\n env.__vueMarkdownKitHeadingSlugs = slugs\n\n tokens[index].attrSet('id', slug)\n tokens[index].attrSet('data-v-md-heading', slug)\n\n return fallback(tokens, index, options, env, self)\n }\n}\n\nfunction installSafeExternalLinks(parser) {\n const fallback =\n parser.renderer.rules.link_open ||\n ((tokens, index, options, _env, self) => self.renderToken(tokens, index, options))\n\n parser.renderer.rules.link_open = (tokens, index, options, env, self) => {\n const token = tokens[index]\n const href = token.attrGet('href') || ''\n\n if (/^https?:\\/\\//i.test(href)) {\n token.attrSet('target', '_blank')\n token.attrSet('rel', 'noopener noreferrer')\n }\n\n return fallback(tokens, index, options, env, self)\n }\n}\n\nexport function createMarkdownRenderer(options = {}) {\n const parser = new MarkdownIt({\n html: options.html ?? true,\n breaks: options.breaks ?? true,\n linkify: options.linkify ?? false,\n typographer: options.typographer ?? true,\n highlight: (code, language) => highlightCode(code, language, options),\n })\n\n if (options.attrs !== false) {\n parser.use(markdownItAttrs, {\n leftDelimiter: '{{{',\n rightDelimiter: '}}}',\n allowedAttributes: [\n 'class',\n 'height',\n 'id',\n 'title',\n 'width',\n ...(options.allowedAttributes || []),\n ],\n })\n }\n\n installHeadingAnchors(parser)\n installSafeExternalLinks(parser)\n\n return parser\n}\n", "import { createMarkdownRenderer } from '../core/renderer.js'\n\nexport function createGithubTheme(options = {}) {\n const markdownParser = createMarkdownRenderer(options)\n\n return {\n name: 'github',\n previewClass: 'github-markdown-body',\n markdownParser,\n extend(callback) {\n callback(markdownParser, options.Hljs)\n },\n }\n}\n\nconst githubTheme = {\n install(VMdPreview, options = {}) {\n VMdPreview.theme(createGithubTheme(options))\n },\n}\n\nexport default githubTheme\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,gBAAgB;AACvB,OAAO,qBAAqB;AAE5B,SAAS,WAAW,OAAO;AACzB,SAAO,OAAO,KAAK,EAChB,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,QAAQ;AAC3B;AAEO,SAAS,eAAe,OAAO;AACpC,QAAM,OAAO,OAAO,SAAS,EAAE,EAC5B,UAAU,MAAM,EAChB,KAAK,EACL,YAAY,EACZ,QAAQ,QAAQ,GAAG,EACnB,QAAQ,gCAAgC,EAAE,EAC1C,QAAQ,UAAU,GAAG,EACrB,QAAQ,UAAU,EAAE;AAEvB,SAAO,QAAQ;AACjB;AAEA,SAAS,cAAc,MAAM,UAAU,SAAS;AAC9C,QAAM;AAAA,IACJ;AAAA,IACA,4BAA4B,CAAC;AAAA,IAC7B,iBAAiB,CAAC,SAAS,aAAa,QAAQ,EAAE;AAAA,EACpD,IAAI;AAEJ,QAAM,qBAAqB,0BAA0B,QAAQ,KAAK;AAClE,MAAI,cAAc,WAAW,IAAI;AAEjC,MACE,QACA,sBACA,OAAO,KAAK,gBAAgB,cAC5B,KAAK,YAAY,kBAAkB,GACnC;AACA,QAAI;AACF,oBAAc,KAAK,UAAU,MAAM;AAAA,QACjC,UAAU;AAAA,QACV,gBAAgB;AAAA,MAClB,CAAC,EAAE;AAAA,IACL,QAAQ;AAEN,oBAAc,KAAK,UAAU,oBAAoB,MAAM,IAAI,EAAE;AAAA,IAC/D;AAAA,E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,
|
|
6
|
+
BlinkMacSystemFont,
|
|
7
|
+
"Segoe UI",
|
|
8
|
+
Helvetica,
|
|
9
|
+
Arial,
|
|
10
|
+
sans-serif,
|
|
11
|
+
"Apple Color Emoji",
|
|
12
|
+
"Segoe UI Emoji";
|
|
13
|
+
font-size: 16px;
|
|
14
|
+
line-height: 1.5;
|
|
15
|
+
overflow-wrap: break-word;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.github-markdown-body::before,
|
|
19
|
+
.github-markdown-body::after {
|
|
20
|
+
display: table;
|
|
21
|
+
content: "";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.github-markdown-body::after {
|
|
25
|
+
clear: both;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.github-markdown-body > :first-child {
|
|
29
|
+
margin-top: 0 !important;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.github-markdown-body > :last-child {
|
|
33
|
+
margin-bottom: 0 !important;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.github-markdown-body a {
|
|
37
|
+
color: #0969da;
|
|
38
|
+
text-decoration: none;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.github-markdown-body a:hover {
|
|
42
|
+
text-decoration: underline;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.github-markdown-body h1,
|
|
46
|
+
.github-markdown-body h2,
|
|
47
|
+
.github-markdown-body h3,
|
|
48
|
+
.github-markdown-body h4,
|
|
49
|
+
.github-markdown-body h5,
|
|
50
|
+
.github-markdown-body h6 {
|
|
51
|
+
margin-top: 24px;
|
|
52
|
+
margin-bottom: 16px;
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
line-height: 1.25;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.github-markdown-body h1,
|
|
58
|
+
.github-markdown-body h2 {
|
|
59
|
+
padding-bottom: 0.3em;
|
|
60
|
+
border-bottom: 1px solid #d8dee4;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.github-markdown-body h1 {
|
|
64
|
+
font-size: 2em;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.github-markdown-body h2 {
|
|
68
|
+
font-size: 1.5em;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.github-markdown-body h3 {
|
|
72
|
+
font-size: 1.25em;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.github-markdown-body p,
|
|
76
|
+
.github-markdown-body blockquote,
|
|
77
|
+
.github-markdown-body ul,
|
|
78
|
+
.github-markdown-body ol,
|
|
79
|
+
.github-markdown-body table,
|
|
80
|
+
.github-markdown-body pre {
|
|
81
|
+
margin-top: 0;
|
|
82
|
+
margin-bottom: 16px;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.github-markdown-body blockquote {
|
|
86
|
+
padding: 0 1em;
|
|
87
|
+
color: #59636e;
|
|
88
|
+
border-left: 0.25em solid #d1d9e0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.github-markdown-body ul,
|
|
92
|
+
.github-markdown-body ol {
|
|
93
|
+
padding-left: 2em;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.github-markdown-body hr {
|
|
97
|
+
height: 0.25em;
|
|
98
|
+
padding: 0;
|
|
99
|
+
margin: 24px 0;
|
|
100
|
+
background-color: #d1d9e0;
|
|
101
|
+
border: 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.github-markdown-body table {
|
|
105
|
+
display: block;
|
|
106
|
+
width: max-content;
|
|
107
|
+
max-width: 100%;
|
|
108
|
+
overflow: auto;
|
|
109
|
+
border-spacing: 0;
|
|
110
|
+
border-collapse: collapse;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.github-markdown-body table th,
|
|
114
|
+
.github-markdown-body table td {
|
|
115
|
+
padding: 6px 13px;
|
|
116
|
+
border: 1px solid #d1d9e0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.github-markdown-body table th {
|
|
120
|
+
font-weight: 600;
|
|
121
|
+
background: #f6f8fa;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.github-markdown-body table tr:nth-child(2n) {
|
|
125
|
+
background-color: #f6f8fa;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.github-markdown-body code {
|
|
129
|
+
padding: 0.2em 0.4em;
|
|
130
|
+
margin: 0;
|
|
131
|
+
font-family:
|
|
132
|
+
ui-monospace,
|
|
133
|
+
SFMono-Regular,
|
|
134
|
+
SF Mono,
|
|
135
|
+
Menlo,
|
|
136
|
+
Consolas,
|
|
137
|
+
"Liberation Mono",
|
|
138
|
+
monospace;
|
|
139
|
+
font-size: 85%;
|
|
140
|
+
background-color: rgba(175, 184, 193, 0.2);
|
|
141
|
+
border-radius: 6px;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.github-markdown-body pre {
|
|
145
|
+
padding: 16px;
|
|
146
|
+
line-height: 1.45;
|
|
147
|
+
background-color: #f6f8fa;
|
|
148
|
+
border-radius: 6px;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.github-markdown-body pre code {
|
|
152
|
+
display: inline;
|
|
153
|
+
padding: 0;
|
|
154
|
+
margin: 0;
|
|
155
|
+
overflow: visible;
|
|
156
|
+
font-size: 100%;
|
|
157
|
+
line-height: inherit;
|
|
158
|
+
word-break: normal;
|
|
159
|
+
white-space: pre;
|
|
160
|
+
background: transparent;
|
|
161
|
+
border: 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.github-markdown-body img {
|
|
165
|
+
max-width: 100%;
|
|
166
|
+
height: auto;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.github-markdown-body .hljs-keyword,
|
|
170
|
+
.github-markdown-body .hljs-selector-tag,
|
|
171
|
+
.github-markdown-body .hljs-literal {
|
|
172
|
+
color: #cf222e;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.github-markdown-body .hljs-string,
|
|
176
|
+
.github-markdown-body .hljs-attr {
|
|
177
|
+
color: #0a3069;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.github-markdown-body .hljs-title,
|
|
181
|
+
.github-markdown-body .hljs-function {
|
|
182
|
+
color: #8250df;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.github-markdown-body .hljs-comment {
|
|
186
|
+
color: #6e7781;
|
|
187
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vue3-markdown-kit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A small, auditable Markdown preview toolkit for Vue 3.5.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vue",
|
|
7
|
+
"vue3",
|
|
8
|
+
"vue3.5",
|
|
9
|
+
"markdown",
|
|
10
|
+
"preview",
|
|
11
|
+
"renderer",
|
|
12
|
+
"markdown-it"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "eatmeatHJ",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/eatmeatHJ/vue3-markdown-kit.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/eatmeatHJ/vue3-markdown-kit/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/eatmeatHJ/vue3-markdown-kit#readme",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./lib/index.cjs",
|
|
26
|
+
"module": "./lib/index.js",
|
|
27
|
+
"types": "./types/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"lib",
|
|
30
|
+
"types",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"NOTICE.md",
|
|
33
|
+
"README.md",
|
|
34
|
+
"CHANGELOG.md",
|
|
35
|
+
"SECURITY.md"
|
|
36
|
+
],
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./types/index.d.ts",
|
|
40
|
+
"import": "./lib/index.js",
|
|
41
|
+
"require": "./lib/index.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./preview": {
|
|
44
|
+
"types": "./types/preview.d.ts",
|
|
45
|
+
"import": "./lib/preview.js",
|
|
46
|
+
"require": "./lib/preview.cjs"
|
|
47
|
+
},
|
|
48
|
+
"./core": {
|
|
49
|
+
"types": "./types/core.d.ts",
|
|
50
|
+
"import": "./lib/core.js",
|
|
51
|
+
"require": "./lib/core.cjs"
|
|
52
|
+
},
|
|
53
|
+
"./theme/github": {
|
|
54
|
+
"types": "./types/theme-github.d.ts",
|
|
55
|
+
"import": "./lib/theme/github.js",
|
|
56
|
+
"require": "./lib/theme/github.cjs"
|
|
57
|
+
},
|
|
58
|
+
"./style/preview.css": "./lib/style/preview.css",
|
|
59
|
+
"./theme/style/github.css": "./lib/theme/style/github.css",
|
|
60
|
+
"./lib/preview": {
|
|
61
|
+
"types": "./types/preview.d.ts",
|
|
62
|
+
"import": "./lib/preview.js",
|
|
63
|
+
"require": "./lib/preview.cjs"
|
|
64
|
+
},
|
|
65
|
+
"./lib/preview.js": {
|
|
66
|
+
"types": "./types/preview.d.ts",
|
|
67
|
+
"import": "./lib/preview.js",
|
|
68
|
+
"require": "./lib/preview.cjs"
|
|
69
|
+
},
|
|
70
|
+
"./lib/theme/github": {
|
|
71
|
+
"types": "./types/theme-github.d.ts",
|
|
72
|
+
"import": "./lib/theme/github.js",
|
|
73
|
+
"require": "./lib/theme/github.cjs"
|
|
74
|
+
},
|
|
75
|
+
"./lib/theme/github.js": {
|
|
76
|
+
"types": "./types/theme-github.d.ts",
|
|
77
|
+
"import": "./lib/theme/github.js",
|
|
78
|
+
"require": "./lib/theme/github.cjs"
|
|
79
|
+
},
|
|
80
|
+
"./lib/style/preview.css": "./lib/style/preview.css",
|
|
81
|
+
"./lib/theme/style/github.css": "./lib/theme/style/github.css",
|
|
82
|
+
"./package.json": "./package.json"
|
|
83
|
+
},
|
|
84
|
+
"sideEffects": [
|
|
85
|
+
"**/*.css"
|
|
86
|
+
],
|
|
87
|
+
"scripts": {
|
|
88
|
+
"build": "node scripts/build.mjs",
|
|
89
|
+
"test": "npm run build && node --test && npm run test:types",
|
|
90
|
+
"test:types": "tsc -p tsconfig.types.json",
|
|
91
|
+
"check": "npm run test && npm pack --dry-run",
|
|
92
|
+
"prepublishOnly": "npm run check"
|
|
93
|
+
},
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"dompurify": "3.4.15",
|
|
96
|
+
"highlight.js": "11.11.1",
|
|
97
|
+
"markdown-it": "14.3.0",
|
|
98
|
+
"markdown-it-attrs": "5.0.1"
|
|
99
|
+
},
|
|
100
|
+
"peerDependencies": {
|
|
101
|
+
"vue": "^3.5.0"
|
|
102
|
+
},
|
|
103
|
+
"devDependencies": {
|
|
104
|
+
"esbuild": "0.28.1",
|
|
105
|
+
"jsdom": "26.0.0",
|
|
106
|
+
"typescript": "7.0.2",
|
|
107
|
+
"vue": "3.5.38"
|
|
108
|
+
},
|
|
109
|
+
"engines": {
|
|
110
|
+
"node": ">=18"
|
|
111
|
+
}
|
|
112
|
+
}
|
package/types/core.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Config as DOMPurifyConfig } from 'dompurify'
|
|
2
|
+
|
|
3
|
+
export interface MarkdownRenderer {
|
|
4
|
+
render(source: string, environment?: Record<string, unknown>): string
|
|
5
|
+
use(plugin: unknown, ...options: unknown[]): this
|
|
6
|
+
set(options: Record<string, unknown>): this
|
|
7
|
+
renderer: {
|
|
8
|
+
rules: Record<string, unknown>
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MarkdownRendererOptions {
|
|
13
|
+
Hljs?: unknown
|
|
14
|
+
html?: boolean
|
|
15
|
+
breaks?: boolean
|
|
16
|
+
linkify?: boolean
|
|
17
|
+
typographer?: boolean
|
|
18
|
+
attrs?: boolean
|
|
19
|
+
allowedAttributes?: string[]
|
|
20
|
+
codeHighlightExtensionMap?: Record<string, string>
|
|
21
|
+
codeBlockClass?: (language?: string) => string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createMarkdownRenderer(
|
|
25
|
+
options?: MarkdownRendererOptions,
|
|
26
|
+
): MarkdownRenderer
|
|
27
|
+
|
|
28
|
+
export function slugifyHeading(value: string): string
|
|
29
|
+
|
|
30
|
+
export function sanitizeHtml(
|
|
31
|
+
dirtyHtml: string,
|
|
32
|
+
options?: DOMPurifyConfig,
|
|
33
|
+
windowLike?: Window,
|
|
34
|
+
): string
|
|
35
|
+
|
|
36
|
+
export const sanitizer: {
|
|
37
|
+
process(dirtyHtml: string, options?: DOMPurifyConfig): string
|
|
38
|
+
extend(options?: DOMPurifyConfig): typeof sanitizer
|
|
39
|
+
reset(): typeof sanitizer
|
|
40
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin } from 'vue'
|
|
2
|
+
import type { MarkdownRendererOptions } from './core'
|
|
3
|
+
import type { MarkdownTheme } from './preview'
|
|
4
|
+
|
|
5
|
+
export { default as VMdPreview } from './preview'
|
|
6
|
+
export * from './core'
|
|
7
|
+
|
|
8
|
+
export function createGithubTheme(
|
|
9
|
+
options?: MarkdownRendererOptions,
|
|
10
|
+
): MarkdownTheme
|
|
11
|
+
|
|
12
|
+
export const githubTheme: {
|
|
13
|
+
install(preview: unknown, options?: MarkdownRendererOptions): void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const VueMarkdownKit: Plugin & {
|
|
17
|
+
version: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default VueMarkdownKit
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { App, DefineComponent } from 'vue'
|
|
2
|
+
import type { Config as DOMPurifyConfig } from 'dompurify'
|
|
3
|
+
import type { MarkdownRenderer } from './core'
|
|
4
|
+
|
|
5
|
+
export interface MarkdownTheme {
|
|
6
|
+
name?: string
|
|
7
|
+
previewClass: string
|
|
8
|
+
markdownParser: MarkdownRenderer
|
|
9
|
+
extend(
|
|
10
|
+
callback: (parser: MarkdownRenderer, highlighter?: unknown) => void,
|
|
11
|
+
): void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface VMdPreviewPlugin {
|
|
15
|
+
name: 'v-md-preview'
|
|
16
|
+
version: string
|
|
17
|
+
install(app: App): void
|
|
18
|
+
theme(theme: MarkdownTheme): this
|
|
19
|
+
use(theme: unknown, options?: unknown): this
|
|
20
|
+
extendMarkdown(extender: (parser: MarkdownRenderer) => void): this
|
|
21
|
+
xss: {
|
|
22
|
+
process(dirtyHtml: string, options?: DOMPurifyConfig): string
|
|
23
|
+
extend(options?: DOMPurifyConfig): unknown
|
|
24
|
+
reset(): unknown
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type VMdPreviewComponent = DefineComponent<{
|
|
29
|
+
text?: string
|
|
30
|
+
theme?: MarkdownTheme
|
|
31
|
+
tabSize?: number
|
|
32
|
+
scrollContainer?: () => unknown
|
|
33
|
+
top?: number
|
|
34
|
+
sanitizeOptions?: DOMPurifyConfig
|
|
35
|
+
}> & VMdPreviewPlugin
|
|
36
|
+
|
|
37
|
+
declare const VMdPreview: VMdPreviewComponent
|
|
38
|
+
|
|
39
|
+
export default VMdPreview
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MarkdownRendererOptions } from './core'
|
|
2
|
+
import type { MarkdownTheme, VMdPreviewComponent } from './preview'
|
|
3
|
+
|
|
4
|
+
export function createGithubTheme(
|
|
5
|
+
options?: MarkdownRendererOptions,
|
|
6
|
+
): MarkdownTheme
|
|
7
|
+
|
|
8
|
+
declare const githubTheme: {
|
|
9
|
+
install(
|
|
10
|
+
preview: VMdPreviewComponent,
|
|
11
|
+
options?: MarkdownRendererOptions,
|
|
12
|
+
): void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default githubTheme
|