svelte-readme 3.4.1 → 3.6.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/CHANGELOG.md +16 -0
- package/README.md +13 -0
- package/dist/createConfig.js +20 -15
- package/dist/preprocessReadme.js +31 -23
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.6.2](https://github.com/metonym/svelte-readme/releases/tag/v3.6.2) - 2021-12-29
|
|
9
|
+
|
|
10
|
+
- remove deprecated `svelteBracketNewLine` prettier option
|
|
11
|
+
|
|
12
|
+
## [3.6.1](https://github.com/metonym/svelte-readme/releases/tag/v3.6.1) - 2021-11-14
|
|
13
|
+
|
|
14
|
+
- correctly render `h3` node text in table of contents
|
|
15
|
+
|
|
16
|
+
## [3.6.0](https://github.com/metonym/svelte-readme/releases/tag/v3.6.0) - 2021-10-27
|
|
17
|
+
|
|
18
|
+
- evaluate but omit result if `no-display` attribute is present in Svelte code fence block
|
|
19
|
+
|
|
20
|
+
## [3.5.0](https://github.com/metonym/svelte-readme/releases/tag/v3.5.0) - 2021-10-26
|
|
21
|
+
|
|
22
|
+
- omit evaluating Svelte code if `no-eval` attribute is present in Svelte code fence block
|
|
23
|
+
|
|
8
24
|
## [3.4.1](https://github.com/metonym/svelte-readme/releases/tag/v3.4.1) - 2021-10-25
|
|
9
25
|
|
|
10
26
|
- check if `instance` is undefined
|
package/README.md
CHANGED
|
@@ -145,6 +145,19 @@ interface CreateConfigOptions {
|
|
|
145
145
|
}
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
+
## Limitations
|
|
149
|
+
|
|
150
|
+
### Comments in script blocks
|
|
151
|
+
|
|
152
|
+
Single line comments in Svelte script blocks are not supported.
|
|
153
|
+
|
|
154
|
+
Use multi-line comments instead.
|
|
155
|
+
|
|
156
|
+
```diff
|
|
157
|
+
- let toggled; // comment
|
|
158
|
+
+ let toggled; /** comment */
|
|
159
|
+
```
|
|
160
|
+
|
|
148
161
|
## Prior art
|
|
149
162
|
|
|
150
163
|
This project is inspired by [MDsveX](https://github.com/pngwn/mdsvex).
|
package/dist/createConfig.js
CHANGED
|
@@ -26,9 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
26
26
|
}
|
|
27
27
|
return ar;
|
|
28
28
|
};
|
|
29
|
-
var
|
|
30
|
-
for (var
|
|
31
|
-
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
37
|
};
|
|
33
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
34
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -48,7 +53,7 @@ function hashREADME() {
|
|
|
48
53
|
try {
|
|
49
54
|
var path_readme = path_1["default"].join(process.cwd(), "README.md");
|
|
50
55
|
var readme = fs_extra_1["default"].readFileSync(path_readme);
|
|
51
|
-
return "." + crypto_1.createHash("md5").update(readme).digest("hex").slice(0, 8);
|
|
56
|
+
return "." + (0, crypto_1.createHash)("md5").update(readme).digest("hex").slice(0, 8);
|
|
52
57
|
}
|
|
53
58
|
catch (error) {
|
|
54
59
|
console.log(error);
|
|
@@ -89,10 +94,10 @@ function createConfig(opts) {
|
|
|
89
94
|
var svelte = {
|
|
90
95
|
emitCss: (_b = (_a = opts.svelte) === null || _a === void 0 ? void 0 : _a.emitCss) !== null && _b !== void 0 ? _b : false,
|
|
91
96
|
compilerOptions: __assign({ dev: DEV, immutable: true }, (_c = opts.svelte) === null || _c === void 0 ? void 0 : _c.compilerOptions),
|
|
92
|
-
extensions:
|
|
93
|
-
preprocess:
|
|
94
|
-
preprocessReadme_1.preprocessReadme(__assign(__assign({}, pkg), { prefixUrl: opts.prefixUrl })),
|
|
95
|
-
])
|
|
97
|
+
extensions: __spreadArray([".svelte", ".md"], __read(((_e = (_d = opts.svelte) === null || _d === void 0 ? void 0 : _d.extensions) !== null && _e !== void 0 ? _e : [])), false),
|
|
98
|
+
preprocess: __spreadArray(__spreadArray([], __read(((_g = (_f = opts.svelte) === null || _f === void 0 ? void 0 : _f.preprocess) !== null && _g !== void 0 ? _g : [])), false), [
|
|
99
|
+
(0, preprocessReadme_1.preprocessReadme)(__assign(__assign({}, pkg), { prefixUrl: opts.prefixUrl })),
|
|
100
|
+
], false)
|
|
96
101
|
};
|
|
97
102
|
console.log("[createConfig] Running in " + (DEV ? "development" : "production"));
|
|
98
103
|
console.log("[createConfig] options:");
|
|
@@ -122,15 +127,15 @@ function createConfig(opts) {
|
|
|
122
127
|
input: "entry",
|
|
123
128
|
// @ts-ignore
|
|
124
129
|
output: __assign({ format: "iife", name: "app", file: output_dir + "/s" + hash + ".js" }, (opts.output || {})),
|
|
125
|
-
plugins:
|
|
126
|
-
plugin_virtual_1["default"]({
|
|
130
|
+
plugins: __spreadArray(__spreadArray([
|
|
131
|
+
(0, plugin_virtual_1["default"])({
|
|
127
132
|
entry: "import App from \"./README.md\";\n const app = new App({ target: document.body });\n export default app;"
|
|
128
133
|
}),
|
|
129
|
-
rollup_plugin_svelte_1["default"](svelte),
|
|
130
|
-
plugin_node_resolve_1["default"]()
|
|
131
|
-
], (opts.plugins || []), [
|
|
132
|
-
minify && rollup_plugin_terser_1.terser(),
|
|
133
|
-
]).filter(Boolean)
|
|
134
|
+
(0, rollup_plugin_svelte_1["default"])(svelte),
|
|
135
|
+
(0, plugin_node_resolve_1["default"])()
|
|
136
|
+
], __read((opts.plugins || [])), false), [
|
|
137
|
+
minify && (0, rollup_plugin_terser_1.terser)(),
|
|
138
|
+
], false).filter(Boolean)
|
|
134
139
|
};
|
|
135
140
|
}
|
|
136
141
|
exports["default"] = createConfig;
|
package/dist/preprocessReadme.js
CHANGED
|
@@ -15,9 +15,14 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
15
15
|
}
|
|
16
16
|
return ar;
|
|
17
17
|
};
|
|
18
|
-
var
|
|
19
|
-
for (var
|
|
20
|
-
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
26
|
};
|
|
22
27
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -44,6 +49,13 @@ var aliases = {
|
|
|
44
49
|
yml: "yaml"
|
|
45
50
|
};
|
|
46
51
|
var md;
|
|
52
|
+
var getChildNodeText = function (node) {
|
|
53
|
+
return node.children
|
|
54
|
+
.flatMap(function (child) { return (child.type === "Element" ? child.children : child); })
|
|
55
|
+
.filter(function (child) { return child.type === "Text"; })
|
|
56
|
+
.map(function (child) { return child.raw; })
|
|
57
|
+
.join("");
|
|
58
|
+
};
|
|
47
59
|
function preprocessReadme(opts) {
|
|
48
60
|
var prefixUrl = opts.prefixUrl || opts.homepage + "/tree/master/";
|
|
49
61
|
var script_content = [];
|
|
@@ -52,25 +64,25 @@ function preprocessReadme(opts) {
|
|
|
52
64
|
html: true,
|
|
53
65
|
linkify: true,
|
|
54
66
|
typographer: true,
|
|
55
|
-
highlight: function (source, lang) {
|
|
67
|
+
highlight: function (source, lang, attrs) {
|
|
56
68
|
if (lang === "svelte") {
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
var noEval = /no-eval/.test(attrs);
|
|
70
|
+
var noDisplay = /no-display/.test(attrs);
|
|
71
|
+
var instance = (0, compiler_1.parse)(source).instance;
|
|
72
|
+
if (instance !== undefined && !noEval) {
|
|
73
|
+
script_content = __spreadArray(__spreadArray([], __read(script_content), false), __read(source
|
|
60
74
|
.slice(instance.start, instance.end)
|
|
61
75
|
.split("\n")
|
|
62
76
|
.slice(1, -1)
|
|
63
|
-
.map(function (line) { return line.trim().replace(new RegExp(opts.name, "g"), opts.svelte); }));
|
|
77
|
+
.map(function (line) { return line.trim().replace(new RegExp(opts.name, "g"), opts.svelte); })), false);
|
|
64
78
|
}
|
|
65
79
|
var regex = new RegExp('"' + opts.name + '"', "g");
|
|
66
80
|
var modifiedSource = encodeURI(source.replace(regex, '"' + opts.svelte + '"'));
|
|
67
81
|
var formattedCode = prettier_1["default"].format(source, {
|
|
68
|
-
parser: "svelte"
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
svelteBracketNewLine: true
|
|
82
|
+
parser: "svelte"
|
|
71
83
|
});
|
|
72
84
|
var svelteCode = prismjs_1["default"].highlight(formattedCode, prismjs_1["default"].languages.svelte, "svelte");
|
|
73
|
-
return "<pre class=\"language-" + lang + "\" data-svelte=\"" + modifiedSource + "\">{@html `" + svelteCode + "`}</pre>";
|
|
85
|
+
return "<pre class=\"language-" + lang + "\" " + (noEval || noDisplay ? "" : "data-svelte=\"" + modifiedSource + "\"") + ">{@html `" + svelteCode + "`}</pre>";
|
|
74
86
|
}
|
|
75
87
|
try {
|
|
76
88
|
var alias_lang = aliases[lang] || lang;
|
|
@@ -97,14 +109,14 @@ function preprocessReadme(opts) {
|
|
|
97
109
|
var style_content = "";
|
|
98
110
|
var result = md.render(content);
|
|
99
111
|
var cursor = 0;
|
|
100
|
-
var ast = compiler_1.parse(result);
|
|
112
|
+
var ast = (0, compiler_1.parse)(result);
|
|
101
113
|
var headings = [];
|
|
102
114
|
var prev = undefined;
|
|
103
|
-
compiler_1.walk(ast, {
|
|
115
|
+
(0, compiler_1.walk)(ast, {
|
|
104
116
|
enter: function (node, parent) {
|
|
105
117
|
if (node.type === "Attribute" && node.name === "href") {
|
|
106
118
|
var value = node.value[0];
|
|
107
|
-
if (value && !value.raw.startsWith("#") && is_relative_url_1["default"](value.raw)) {
|
|
119
|
+
if (value && !value.raw.startsWith("#") && (0, is_relative_url_1["default"])(value.raw)) {
|
|
108
120
|
var relative_path = new url_1.URL(value.raw, prefixUrl).href;
|
|
109
121
|
result = result.replace(value.raw, relative_path);
|
|
110
122
|
cursor += relative_path.length - value.raw.length;
|
|
@@ -121,11 +133,7 @@ function preprocessReadme(opts) {
|
|
|
121
133
|
var id = node.attributes.find(function (attr) { return attr.name === "id"; }).value[0].raw;
|
|
122
134
|
if (id === "table-of-contents")
|
|
123
135
|
return;
|
|
124
|
-
var text = node
|
|
125
|
-
.flatMap(function (child) { return (child.type === "Element" ? child.children : child); })
|
|
126
|
-
.filter(function (child) { return child.type === "Text"; })
|
|
127
|
-
.map(function (child) { return child.raw; })
|
|
128
|
-
.join("");
|
|
136
|
+
var text = getChildNodeText(node);
|
|
129
137
|
if (text !== undefined) {
|
|
130
138
|
if (prev === "h3") {
|
|
131
139
|
headings.push("</ul><li><a href=\"#" + id + "\">" + text + "</a></li>");
|
|
@@ -139,7 +147,7 @@ function preprocessReadme(opts) {
|
|
|
139
147
|
if (node.type === "Element" && node.name === "h3") {
|
|
140
148
|
// @ts-ignore
|
|
141
149
|
var id = node.attributes.find(function (attr) { return attr.name === "id"; }).value[0].raw;
|
|
142
|
-
var text = node
|
|
150
|
+
var text = getChildNodeText(node);
|
|
143
151
|
if (text !== undefined) {
|
|
144
152
|
if (prev === "h2") {
|
|
145
153
|
headings.push("<ul><li><a href=\"#" + id + "\">" + text + "</a></li>");
|
|
@@ -153,7 +161,7 @@ function preprocessReadme(opts) {
|
|
|
153
161
|
if (node.type === "Attribute" && node.name === "data-svelte") {
|
|
154
162
|
var raw_value = node.value[0].raw;
|
|
155
163
|
var value = decodeURI(raw_value);
|
|
156
|
-
var value_ast = compiler_1.parse(value);
|
|
164
|
+
var value_ast = (0, compiler_1.parse)(value);
|
|
157
165
|
var markup = "<div class=\"code-fence\">" + value.slice(value_ast.html.start, value_ast.html.end) + "</div>";
|
|
158
166
|
var replace = result.slice(parent.start + cursor, parent.end + cursor);
|
|
159
167
|
result = result.replace(replace, markup + replace.replace(raw_value, ""));
|
|
@@ -166,7 +174,7 @@ function preprocessReadme(opts) {
|
|
|
166
174
|
}
|
|
167
175
|
result = result.replace("<h2 id=\"table-of-contents\">Table of Contents</h2>", "<p><strong>Table of Contents</strong></p><ul>" + headings.join("\n") + "</ul>");
|
|
168
176
|
return {
|
|
169
|
-
code: "<script>" +
|
|
177
|
+
code: "<script>" + __spreadArray([], __read(new Set(script_content)), false).join("") + "</script>\n <style>" + style_content + "</style>\n <main class=\"markdown-body\">" + result + "</main>"
|
|
170
178
|
};
|
|
171
179
|
}
|
|
172
180
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-readme",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Develop and demo your Svelte components in your README.md",
|
|
6
6
|
"author": "Eric Liu (https://github.com/metonym)",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"preprocess": "node scripts/preprocessStyles",
|
|
11
11
|
"dev": "yarn preprocess && tsc -w",
|
|
12
|
-
"prepack": "yarn preprocess && tsc"
|
|
12
|
+
"prepack": "yarn preprocess && tsc",
|
|
13
|
+
"format": "prettier --write '.'"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
16
|
"@rollup/plugin-node-resolve": "^11.1.0",
|
|
@@ -17,19 +18,19 @@
|
|
|
17
18
|
"fs-extra": "^9.0.1",
|
|
18
19
|
"html-minifier": "^4.0.0",
|
|
19
20
|
"is-relative-url": "^3.0.0",
|
|
20
|
-
"markdown-it": "^12.0
|
|
21
|
+
"markdown-it": "^12.3.0",
|
|
21
22
|
"markdown-it-anchor": "^6.0.1",
|
|
22
|
-
"prettier": "^2.
|
|
23
|
-
"prettier-plugin-svelte": "^2.1
|
|
23
|
+
"prettier": "^2.5.1",
|
|
24
|
+
"prettier-plugin-svelte": "^2.5.1",
|
|
24
25
|
"prism-svelte": "^0.4.7",
|
|
25
26
|
"prismjs": "^1.23.0",
|
|
26
|
-
"rollup": "^2.
|
|
27
|
+
"rollup": "^2.62.0",
|
|
27
28
|
"rollup-plugin-svelte": "^7.0.0",
|
|
28
29
|
"rollup-plugin-terser": "^7.0.2"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/fs-extra": "^9.0.6",
|
|
32
|
-
"@types/html-minifier": "^4.0.
|
|
33
|
+
"@types/html-minifier": "^4.0.2",
|
|
33
34
|
"@types/markdown-it": "^12.0.1",
|
|
34
35
|
"@types/markdown-it-anchor": "^4.0.4",
|
|
35
36
|
"@types/node": "^14.14.21",
|