vite-plugin-svelte-md 0.4.1 → 0.5.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 +1 -1
- package/lib/markdown.js +20 -5
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -226,7 +226,7 @@ The class name of the div that wraps the content.
|
|
|
226
226
|
</tr>
|
|
227
227
|
<tr>
|
|
228
228
|
<td>Frontmatter</td>
|
|
229
|
-
<td
|
|
229
|
+
<td>✅ (YAML)<br>
|
|
230
230
|
Accessible through <code>{frontmatter.variable}</code></td>
|
|
231
231
|
<td>✅ (YAML, <a href="https://mdsvex.pngwn.io/docs#frontmatter">can be changed</a>)<br>
|
|
232
232
|
Accessible through <code>{variable}</code>
|
package/lib/markdown.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as devalue from "devalue";
|
|
1
2
|
import { createMarkdownExit } from "markdown-exit";
|
|
2
|
-
import
|
|
3
|
+
import * as yaml from "yaml";
|
|
3
4
|
import markdownItSvelteTags from "./markdown-it-svelte-tags/index.js";
|
|
4
5
|
import markdownItSvelteCurlyBracesEscape from "./markdown-it-svelte-curly-braces-escape/index.js";
|
|
5
6
|
import { toArray } from "./utils.js";
|
|
@@ -9,6 +10,21 @@ const SVELTE_TAGS_RE = /(<svelte:[a-z][^>]*>)([\s\S]*?)<\/svelte:[a-z]+>/gu;
|
|
|
9
10
|
const GET_SVELTE_TAG_NAME_RE = /^svelte:[a-z]+/u;
|
|
10
11
|
const IS_MODULE_CONTEXT_RE = /\bcontext\s*=\s*["']?module["']?/u;
|
|
11
12
|
const IS_SVELTE_TAG_NAME_RE = /^svelte:[a-z]+$/u;
|
|
13
|
+
const FRONTMATTER_RE = /^---(?:\r?\n|\r)(?:([\s\S]*?)(?:\r?\n|\r))?---(?:\r?\n|\r|$)/;
|
|
14
|
+
/**
|
|
15
|
+
* Adapted from https://github.com/vfile/vfile-matter/blob/20c6193bb118f4c65488e0daaf2e66f5cafc733f/lib/index.js
|
|
16
|
+
* under MIT License: Copyright (c) Titus Wormer <tituswormer@gmail.com>
|
|
17
|
+
*/
|
|
18
|
+
function grayMatter(input) {
|
|
19
|
+
const match = FRONTMATTER_RE.exec(input);
|
|
20
|
+
if (match) {
|
|
21
|
+
return {
|
|
22
|
+
data: yaml.parse(match[1] || "") || {},
|
|
23
|
+
content: input.slice(match[0].length),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { data: {}, content: input };
|
|
27
|
+
}
|
|
12
28
|
class TagContent {
|
|
13
29
|
startTag = "";
|
|
14
30
|
contents = [];
|
|
@@ -93,14 +109,13 @@ export function createMarkdownProcessor(options) {
|
|
|
93
109
|
const raw = text.trimEnd();
|
|
94
110
|
const { wrapperClasses, headEnabled } = options;
|
|
95
111
|
const parsedFrontmatter = grayMatter(raw);
|
|
96
|
-
|
|
97
|
-
let html = await markdownIt.renderAsync(plainMarkdown, { id });
|
|
112
|
+
let html = await markdownIt.renderAsync(parsedFrontmatter.content, { id });
|
|
98
113
|
if (wrapperClasses) {
|
|
99
114
|
html = `<div class="${wrapperClasses}">${html}</div>`;
|
|
100
115
|
}
|
|
101
116
|
const parsedHtml = parseHtml(html);
|
|
102
|
-
const { head, frontmatter } = frontmatterPreprocess(parsedFrontmatter
|
|
103
|
-
parsedHtml.moduleContext.prepend(`export const frontmatter = ${
|
|
117
|
+
const { head, frontmatter } = frontmatterPreprocess(parsedFrontmatter.data, options);
|
|
118
|
+
parsedHtml.moduleContext.prepend(`export const frontmatter = ${devalue.uneval(frontmatter)};`);
|
|
104
119
|
if (headEnabled && head) {
|
|
105
120
|
let svelteHead = parsedHtml.svelteTags.find((tag) => tag.tagName === "svelte:head");
|
|
106
121
|
if (!svelteHead) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svelte-md",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vite plugin to convert markdown to svelte template",
|
|
6
6
|
"files": [
|
|
@@ -54,8 +54,9 @@
|
|
|
54
54
|
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-beta.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"
|
|
58
|
-
"markdown-exit": "^1.0.0-beta.9"
|
|
57
|
+
"devalue": "^5.6.4",
|
|
58
|
+
"markdown-exit": "^1.0.0-beta.9",
|
|
59
|
+
"yaml": "^2.8.2 || ^3.0.0-0"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@changesets/cli": "^2.29.5",
|