svelte-readme 3.6.2 → 4.0.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.
@@ -0,0 +1,10 @@
1
+ export declare function toArray<T>(value: T | T[] | undefined): T[];
2
+ export declare function getPackageJSON(): {
3
+ name: any;
4
+ svelte: any;
5
+ description: any;
6
+ homepage: any;
7
+ repoUrl: any;
8
+ };
9
+ export declare function collapseWhitespace(html: string): string;
10
+ export declare function logSSRFallback(error: unknown): void;
package/dist/yaml.css ADDED
@@ -0,0 +1,3 @@
1
+ .language-yaml {
2
+ color: #0550ae;
3
+ }
package/package.json CHANGED
@@ -1,47 +1,18 @@
1
1
  {
2
2
  "name": "svelte-readme",
3
- "version": "3.6.2",
3
+ "version": "4.0.0",
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)",
7
+ "type": "module",
7
8
  "main": "./dist/index.js",
8
9
  "types": "./dist/index.d.ts",
9
- "scripts": {
10
- "preprocess": "node scripts/preprocessStyles",
11
- "dev": "yarn preprocess && tsc -w",
12
- "prepack": "yarn preprocess && tsc",
13
- "format": "prettier --write '.'"
14
- },
15
- "dependencies": {
16
- "@rollup/plugin-node-resolve": "^11.1.0",
17
- "@rollup/plugin-virtual": "^2.0.3",
18
- "fs-extra": "^9.0.1",
19
- "html-minifier": "^4.0.0",
20
- "is-relative-url": "^3.0.0",
21
- "markdown-it": "^12.3.0",
22
- "markdown-it-anchor": "^6.0.1",
23
- "prettier": "^2.5.1",
24
- "prettier-plugin-svelte": "^2.5.1",
25
- "prism-svelte": "^0.4.7",
26
- "prismjs": "^1.23.0",
27
- "rollup": "^2.62.0",
28
- "rollup-plugin-svelte": "^7.0.0",
29
- "rollup-plugin-terser": "^7.0.2"
30
- },
31
- "devDependencies": {
32
- "@types/fs-extra": "^9.0.6",
33
- "@types/html-minifier": "^4.0.2",
34
- "@types/markdown-it": "^12.0.1",
35
- "@types/markdown-it-anchor": "^4.0.4",
36
- "@types/node": "^14.14.21",
37
- "@types/prettier": "^2.1.6",
38
- "@types/prismjs": "^1.16.2",
39
- "@types/rollup__plugin-virtual": "^2.0.1",
40
- "github-markdown-css": "4.0.0",
41
- "postcss": "^8.2.4",
42
- "svelte": "^3.31.2",
43
- "ts-node-dev": "^1.1.1",
44
- "typescript": "^4.1.3"
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
45
16
  },
46
17
  "repository": {
47
18
  "type": "git",
@@ -56,8 +27,5 @@
56
27
  ],
57
28
  "files": [
58
29
  "dist"
59
- ],
60
- "prettier": {
61
- "printWidth": 120
62
- }
30
+ ]
63
31
  }
package/CHANGELOG.md DELETED
@@ -1,193 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
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
-
24
- ## [3.4.1](https://github.com/metonym/svelte-readme/releases/tag/v3.4.1) - 2021-10-25
25
-
26
- - check if `instance` is undefined
27
-
28
- ## [3.4.0](https://github.com/metonym/svelte-readme/releases/tag/v3.4.0) - 2021-10-25
29
-
30
- - allow duplicate imports in `script` block
31
-
32
- ## [3.3.1](https://github.com/metonym/svelte-readme/releases/tag/v3.3.1) - 2021-08-28
33
-
34
- - escape back ticks in toc headings
35
-
36
- ## [3.3.0](https://github.com/metonym/svelte-readme/releases/tag/v3.3.0) - 2021-08-23
37
-
38
- - support yaml/yml Prism.js syntax highlighting
39
-
40
- ## [3.2.0](https://github.com/metonym/svelte-readme/releases/tag/v3.2.0) - 2021-07-20
41
-
42
- **Features**
43
-
44
- - support typescript/jsx Prism.js syntax highlighting
45
-
46
- **Fixes**
47
-
48
- - render code source as HTML if highlighting fails
49
-
50
- ## [3.1.0](https://github.com/metonym/svelte-readme/releases/tag/v3.1.0) - 2021-03-20
51
-
52
- - add `28px` minimum height to `p` tags
53
- - add `48px` margin bottom to `pre` tags
54
-
55
- ## [3.0.0](https://github.com/metonym/svelte-readme/releases/tag/v3.0.0) - 2021-01-18
56
-
57
- - Upgrade `prettier-plugin-svelte` version from ^1.4.2 to ^2.1.0
58
-
59
- ## [2.3.1](https://github.com/metonym/svelte-readme/releases/tag/v2.3.1) - 2021-01-17
60
-
61
- - Append code-fence button only if `disableDefaultCSS` is false
62
-
63
- ## [2.3.0](https://github.com/metonym/svelte-readme/releases/tag/v2.3.0) - 2021-01-17
64
-
65
- - Support head option in `createConfig`
66
-
67
- ## [2.2.0](https://github.com/metonym/svelte-readme/releases/tag/v2.2.0) - 2021-01-02
68
-
69
- - Add ability to link to git repo url if `package.json#repository.url` is specified
70
- - Style button by default
71
-
72
- ## [2.1.2](https://github.com/metonym/svelte-readme/releases/tag/v2.1.2) - 2020-12-31
73
-
74
- - Initialize default parameter value in `createConfig`
75
-
76
- ## [2.1.1](https://github.com/metonym/svelte-readme/releases/tag/v2.1.1) - 2020-12-30
77
-
78
- - Default `svelte.emitCss` to `false`
79
-
80
- ## [2.1.0](https://github.com/metonym/svelte-readme/releases/tag/v2.1.0) - 2020-12-30
81
-
82
- - Infer development mode if `process.env.ROLLUP_WATCH` is `true`
83
- - Automatically set `svelte.compilerOptions.dev`
84
- - Default `svelte.compilerOptions.immutable` to `true`
85
-
86
- ## [2.0.0](https://github.com/metonym/svelte-readme/releases/tag/v2.0.0) - 2020-12-30
87
-
88
- - Upgrade `rollup-plugin-svelte` to ^v7.0.0
89
-
90
- ## [1.3.1](https://github.com/metonym/svelte-readme/releases/tag/v1.3.1) - 2020-12-22
91
-
92
- **Fixes**
93
-
94
- - Add heading to TOC if text is defined
95
-
96
- ## [1.3.0](https://github.com/metonym/svelte-readme/releases/tag/v1.3.0) - 2020-12-21
97
-
98
- **Features**
99
-
100
- - Add option to inject auto-generated table of contents from the `h2` and `h3` headings
101
-
102
- ## [1.2.0](https://github.com/metonym/svelte-readme/releases/tag/v1.2.0) - 2020-12-21
103
-
104
- **Features**
105
-
106
- - Infer `prefixUrl` from `package.json#homepage`
107
- - Slugify headings
108
- - Add `disableDefaultCSS` option to omit default GitHub styles
109
-
110
- **Fixes**
111
-
112
- - Do not prefix anchor links that start with `#`
113
-
114
- ## [1.1.0](https://github.com/metonym/svelte-readme/releases/tag/v1.1.0) - 2020-11-28
115
-
116
- **Features**
117
-
118
- - Alias "sh", "js" languages to "bash," "javascript" for Prism syntax highlighting
119
- - Improve syntax highlighting colors (HTML, JS)
120
- - Optimize github CSS even more
121
-
122
- ## [1.0.0](https://github.com/metonym/svelte-readme/releases/tag/v1.0.0) - 2020-11-24
123
-
124
- **Features**
125
-
126
- - Preprocess `github-markdown-css` to reduce number of unused selectors, decrease CSS specificity, move to development dependencies
127
- - Make output directory configurable through `outDir`
128
-
129
- **Breaking Changes**
130
-
131
- - The default output directory is changed from "public" to "dist"
132
- - The output directory will first be deleted when building for production
133
-
134
- ## [0.4.1](https://github.com/metonym/svelte-readme/releases/tag/v0.4.1) - 2020-11-23
135
-
136
- **Fixes**
137
-
138
- - Remove `public/bundle.js` when building for production
139
-
140
- ## [0.4.0](https://github.com/metonym/svelte-readme/releases/tag/v0.4.0) - 2020-11-23
141
-
142
- **Features**
143
-
144
- - Autogenerate `public/index.html`; inject title/description in template HTML
145
- - Consume `github-markdown-css` from NPM, not CDN; inject styles in template HTML
146
- - Append optional `style` in `createConfig` method to template style block
147
- - Minify template HTML if `minify` is `true`
148
- - Hash `bundle.js` if `minify` is `true`
149
-
150
- ## [0.3.1](https://github.com/metonym/svelte-readme/releases/tag/v0.3.1) - 2020-11-23
151
-
152
- **Fixes**
153
-
154
- - Use URL API to resolve `prefixUrl` with relative URL
155
-
156
- ## [0.3.0](https://github.com/metonym/svelte-readme/releases/tag/v0.3.0) - 2020-11-23
157
-
158
- **Features**
159
-
160
- - Allow Rollup plugins in `createConfig`
161
-
162
- **Fixes**
163
-
164
- - Only prefix URL if value is relative
165
-
166
- ## [0.2.1](https://github.com/metonym/svelte-readme/releases/tag/v0.2.1) - 2020-11-23
167
-
168
- **Fixes**
169
-
170
- - Fix cursor setting when replacing anchor link URLs
171
-
172
- ## [0.2.0](https://github.com/metonym/svelte-readme/releases/tag/v0.2.0) - 2020-11-23
173
-
174
- **Features**
175
-
176
- - Automatically read "name", "svelte" fields from `package.json`
177
- - Prefix relative anchor link URLs with optional `prefixUrl` option
178
-
179
- ## [0.1.2](https://github.com/metonym/svelte-readme/releases/tag/v0.1.2) - 2020-11-22
180
-
181
- **Fixes**
182
-
183
- - Use the correct dependency "prismjs", not "prism"
184
-
185
- ## [0.1.1](https://github.com/metonym/svelte-readme/releases/tag/v0.1.1) - 2020-11-22
186
-
187
- **Fixes**
188
-
189
- - Add "markdown-body" class so that `github-markdown-css` styles are applied
190
-
191
- ## [0.1.0](https://github.com/metonym/svelte-readme/releases/tag/v0.1.0) - 2020-11-22
192
-
193
- - Initial release
@@ -1,50 +0,0 @@
1
- import { Options as RollupPluginSvelteOptions } from "rollup-plugin-svelte";
2
- import { Plugin, OutputOptions, InputOptions } from "rollup";
3
- interface CreateConfigOptions {
4
- /**
5
- * set to `true` to minify the HTML/JS
6
- * @default false
7
- */
8
- minify: boolean;
9
- /**
10
- * set the folder to emit the files
11
- * @default "dist"
12
- */
13
- outDir: string;
14
- /**
15
- * custom CSS appended to the <style> block
16
- * @default ""
17
- */
18
- style: string;
19
- /**
20
- * set to `true` to omit the default GitHub styles
21
- * @default false
22
- */
23
- disableDefaultCSS: boolean;
24
- /**
25
- * value to prepend to relative URLs (i.e. GitHub repo URL)
26
- * @default undefined
27
- */
28
- prefixUrl: string;
29
- /**
30
- * `rollup-plugin-svelte` options
31
- * @default {}
32
- */
33
- svelte: RollupPluginSvelteOptions;
34
- /**
35
- * Rollup plugins
36
- * @default {[]}
37
- */
38
- plugins: Plugin[];
39
- /**
40
- * Rollup output options
41
- * @default {{}}
42
- */
43
- output: OutputOptions;
44
- /**
45
- * Append content to the `head` element in `index.html`
46
- */
47
- head: string;
48
- }
49
- export default function createConfig(opts?: Partial<CreateConfigOptions>): InputOptions;
50
- export {};
@@ -1,141 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
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));
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- exports.__esModule = true;
42
- var plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
43
- var rollup_plugin_svelte_1 = __importDefault(require("rollup-plugin-svelte"));
44
- var plugin_virtual_1 = __importDefault(require("@rollup/plugin-virtual"));
45
- var rollup_plugin_terser_1 = require("rollup-plugin-terser");
46
- var preprocessReadme_1 = require("./preprocessReadme");
47
- var fs_extra_1 = __importDefault(require("fs-extra"));
48
- var path_1 = __importDefault(require("path"));
49
- var crypto_1 = require("crypto");
50
- var html_minifier_1 = __importDefault(require("html-minifier"));
51
- var style_1 = require("./style");
52
- function hashREADME() {
53
- try {
54
- var path_readme = path_1["default"].join(process.cwd(), "README.md");
55
- var readme = fs_extra_1["default"].readFileSync(path_readme);
56
- return "." + (0, crypto_1.createHash)("md5").update(readme).digest("hex").slice(0, 8);
57
- }
58
- catch (error) {
59
- console.log(error);
60
- process.exit(1);
61
- }
62
- }
63
- function getPackageJSON() {
64
- var _a;
65
- try {
66
- var path_pkg = path_1["default"].join(process.cwd(), "package.json");
67
- var pkg = JSON.parse(fs_extra_1["default"].readFileSync(path_pkg, "utf-8"));
68
- if (!pkg.name)
69
- throw Error("Package name is required as \"name\".");
70
- if (!pkg.svelte)
71
- throw Error("Svelte code entry is required as \"svelte\".");
72
- return {
73
- name: pkg.name,
74
- svelte: pkg.svelte,
75
- description: pkg.description,
76
- homepage: pkg.homepage,
77
- repoUrl: (_a = pkg.repository) === null || _a === void 0 ? void 0 : _a.url
78
- };
79
- }
80
- catch (error) {
81
- console.log(error);
82
- process.exit(1);
83
- }
84
- }
85
- var custom_css = "\n .language-yaml { color: #0550ae; }\n .language-typescript { color: #0550ae; }\n .language-typescript .string { color: #0a3069; }\n .language-typescript .number { color: #005cc5; }\n .language-typescript .class-name { color: #24292f; }\n .token.keyword { color: #d73a49; }\n\n .token.language-javascript { color: #24292e; }\n .token.language-javascript .function { color: #005cc5; }\n .token.language-javascript .string { color: #032f62; }\n .token.language-javascript .number { color: #005cc5; }\n .token.language-javascript .keyword { color: #d73a49; }\n .token.each { color: #d73a49; }\n .token.punctuation { color: #24292e }\n .token.tag { color: #22863a; }\n .token.attr-name { color: #6f42c1; }\n .token.attr-value { color: #032f62; }\n .token.operator { color: #d73a49; }\n .token.comment { color: #6a737d; }\n .token.function { color: #6f42c1; }\n .token.string { color: #032f62; }\n\n .token.each .language-javascript:last-child { color: #e36209; }\n\n .language-css { color: #032f62; }\n .language-css .selector { color: #22863a; }\n .language-css .property { color: #005cc5; }\n\n .code-fence { padding: 24px 15px; border: 1px solid #eaecef; border-bottom: 0; }\n\n main {\n box-sizing: border-box;\n max-width: 980px;\n margin: 0 auto;\n padding: 45px;\n }\n\n @media (max-width: 767px) {\n main { padding: 15px; }\n }\n\n \n";
86
- function createConfig(opts) {
87
- var _a, _b, _c, _d, _e, _f, _g, _h;
88
- if (opts === void 0) { opts = {}; }
89
- var DEV = process.env.ROLLUP_WATCH === "true";
90
- var minify = opts.minify === true || !DEV;
91
- var pkg = getPackageJSON();
92
- var hash = minify ? hashREADME() : "";
93
- var output_dir = opts.outDir || "dist";
94
- var svelte = {
95
- emitCss: (_b = (_a = opts.svelte) === null || _a === void 0 ? void 0 : _a.emitCss) !== null && _b !== void 0 ? _b : false,
96
- compilerOptions: __assign({ dev: DEV, immutable: true }, (_c = opts.svelte) === null || _c === void 0 ? void 0 : _c.compilerOptions),
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)
101
- };
102
- console.log("[createConfig] Running in " + (DEV ? "development" : "production"));
103
- console.log("[createConfig] options:");
104
- console.group();
105
- console.log("minify:", minify);
106
- console.log("outDir:", output_dir);
107
- console.log("svelte:", svelte);
108
- console.groupEnd();
109
- var css = style_1.css;
110
- if (!opts.disableDefaultCSS) {
111
- css += "/**\n * GitHub Primer button CSS\n * https://primer.style/css/components/buttons\n **/\n .code-fence button {\n font-family: inherit;\n text-transform: none;\n position: relative;\n display: inline-block;\n padding: 5px 16px;\n font-size: 14px;\n font-weight: 500;\n line-height: 20px;\n white-space: nowrap;\n vertical-align: middle;\n cursor: pointer;\n user-select: none;\n border: 1px solid;\n border-radius: 6px;\n appearance: none;\n color: #24292e;\n background-color: #fafbfc;\n border-color: rgba(27,31,35,0.15);\n box-shadow: 0 1px 0 rgba(27,31,35,0.04), inset 0 1px 0 rgba(255,255,255,0.25);\n transition: background-color 0.2s cubic-bezier(0.3, 0, 0.5, 1);\n }";
112
- }
113
- var template = "\n <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta name=\"description\" content=\"" + (pkg.description || pkg.name + " demo") + "\" />\n <title>" + pkg.name + "</title>\n <style>\n " + (!opts.disableDefaultCSS ? css : "") + "\n " + custom_css + "\n " + (opts.style || "") + "\n </style>\n " + ((_h = opts === null || opts === void 0 ? void 0 : opts.head) !== null && _h !== void 0 ? _h : "") + "\n </head>\n <body>\n <noscript>You need to enable JavaScript to run this app.</noscript>\n <script src=\"s" + hash + ".js\"></script>\n </body>\n </html>\n";
114
- if (minify)
115
- fs_extra_1["default"].removeSync(output_dir);
116
- fs_extra_1["default"].ensureFileSync(output_dir + "/index.html");
117
- fs_extra_1["default"].writeFileSync(output_dir + "/index.html", minify
118
- ? html_minifier_1["default"].minify(template, {
119
- collapseWhitespace: true,
120
- conservativeCollapse: true,
121
- minifyCSS: true,
122
- removeEmptyAttributes: true
123
- })
124
- : template);
125
- return {
126
- watch: { clearScreen: false },
127
- input: "entry",
128
- // @ts-ignore
129
- output: __assign({ format: "iife", name: "app", file: output_dir + "/s" + hash + ".js" }, (opts.output || {})),
130
- plugins: __spreadArray(__spreadArray([
131
- (0, plugin_virtual_1["default"])({
132
- entry: "import App from \"./README.md\";\n const app = new App({ target: document.body });\n export default app;"
133
- }),
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)
139
- };
140
- }
141
- exports["default"] = createConfig;
@@ -1,182 +0,0 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
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));
26
- };
27
- var __importDefault = (this && this.__importDefault) || function (mod) {
28
- return (mod && mod.__esModule) ? mod : { "default": mod };
29
- };
30
- exports.__esModule = true;
31
- exports.preprocessReadme = void 0;
32
- var compiler_1 = require("svelte/compiler");
33
- var markdown_it_1 = __importDefault(require("markdown-it"));
34
- var markdown_it_anchor_1 = __importDefault(require("markdown-it-anchor"));
35
- var prettier_1 = __importDefault(require("prettier"));
36
- var prismjs_1 = __importDefault(require("prismjs"));
37
- require("prismjs/components/prism-bash");
38
- require("prismjs/components/prism-typescript");
39
- require("prismjs/components/prism-jsx");
40
- require("prismjs/components/prism-yaml");
41
- require("prism-svelte");
42
- var is_relative_url_1 = __importDefault(require("is-relative-url"));
43
- var url_1 = require("url");
44
- var aliases = {
45
- sh: "bash",
46
- js: "javascript",
47
- ts: "typescript",
48
- tsx: "typescript",
49
- yml: "yaml"
50
- };
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
- };
59
- function preprocessReadme(opts) {
60
- var prefixUrl = opts.prefixUrl || opts.homepage + "/tree/master/";
61
- var script_content = [];
62
- if (!md) {
63
- md = new markdown_it_1["default"]({
64
- html: true,
65
- linkify: true,
66
- typographer: true,
67
- highlight: function (source, lang, attrs) {
68
- if (lang === "svelte") {
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
74
- .slice(instance.start, instance.end)
75
- .split("\n")
76
- .slice(1, -1)
77
- .map(function (line) { return line.trim().replace(new RegExp(opts.name, "g"), opts.svelte); })), false);
78
- }
79
- var regex = new RegExp('"' + opts.name + '"', "g");
80
- var modifiedSource = encodeURI(source.replace(regex, '"' + opts.svelte + '"'));
81
- var formattedCode = prettier_1["default"].format(source, {
82
- parser: "svelte"
83
- });
84
- var svelteCode = prismjs_1["default"].highlight(formattedCode, prismjs_1["default"].languages.svelte, "svelte");
85
- return "<pre class=\"language-" + lang + "\" " + (noEval || noDisplay ? "" : "data-svelte=\"" + modifiedSource + "\"") + ">{@html `" + svelteCode + "`}</pre>";
86
- }
87
- try {
88
- var alias_lang = aliases[lang] || lang;
89
- return "<pre class=\"language-" + alias_lang + "\">{@html `" + prismjs_1["default"].highlight(source, prismjs_1["default"].languages[alias_lang], alias_lang) + "`}</pre>";
90
- }
91
- catch (e) {
92
- console.error("Could not highlight language \"" + lang + "\".");
93
- return "<pre class=\"language-" + lang + "\">{@html `" + source + "`}</pre>";
94
- }
95
- }
96
- });
97
- md.use(markdown_it_anchor_1["default"]);
98
- }
99
- return {
100
- // @ts-ignore
101
- markup: function (_a) {
102
- var content = _a.content, filename = _a.filename;
103
- if (/node_modules/.test(filename) || !filename.endsWith(".md"))
104
- return null;
105
- if (opts.repoUrl) {
106
- content = content.replace("<!-- REPO_URL -->", "[GitHub repo](" + opts.repoUrl + ")");
107
- }
108
- content = content.replace("<!-- TOC -->", "\n## Table of Contents\n ");
109
- var style_content = "";
110
- var result = md.render(content);
111
- var cursor = 0;
112
- var ast = (0, compiler_1.parse)(result);
113
- var headings = [];
114
- var prev = undefined;
115
- (0, compiler_1.walk)(ast, {
116
- enter: function (node, parent) {
117
- if (node.type === "Attribute" && node.name === "href") {
118
- var value = node.value[0];
119
- if (value && !value.raw.startsWith("#") && (0, is_relative_url_1["default"])(value.raw)) {
120
- var relative_path = new url_1.URL(value.raw, prefixUrl).href;
121
- result = result.replace(value.raw, relative_path);
122
- cursor += relative_path.length - value.raw.length;
123
- }
124
- }
125
- if (node.type === "Style") {
126
- style_content += result.slice(node.content.start, node.content.end);
127
- var replace_style = result.slice(node.start + cursor, node.end + cursor);
128
- result = result.replace(replace_style, "");
129
- cursor -= replace_style.length;
130
- }
131
- if (node.type === "Element" && node.name === "h2") {
132
- // @ts-ignore
133
- var id = node.attributes.find(function (attr) { return attr.name === "id"; }).value[0].raw;
134
- if (id === "table-of-contents")
135
- return;
136
- var text = getChildNodeText(node);
137
- if (text !== undefined) {
138
- if (prev === "h3") {
139
- headings.push("</ul><li><a href=\"#" + id + "\">" + text + "</a></li>");
140
- }
141
- else {
142
- headings.push("<li><a href=\"#" + id + "\">" + text + "</a></li>");
143
- }
144
- prev = "h2";
145
- }
146
- }
147
- if (node.type === "Element" && node.name === "h3") {
148
- // @ts-ignore
149
- var id = node.attributes.find(function (attr) { return attr.name === "id"; }).value[0].raw;
150
- var text = getChildNodeText(node);
151
- if (text !== undefined) {
152
- if (prev === "h2") {
153
- headings.push("<ul><li><a href=\"#" + id + "\">" + text + "</a></li>");
154
- }
155
- else {
156
- headings.push("<li><a href=\"#" + id + "\">" + text + "</a></li>");
157
- }
158
- prev = "h3";
159
- }
160
- }
161
- if (node.type === "Attribute" && node.name === "data-svelte") {
162
- var raw_value = node.value[0].raw;
163
- var value = decodeURI(raw_value);
164
- var value_ast = (0, compiler_1.parse)(value);
165
- var markup = "<div class=\"code-fence\">" + value.slice(value_ast.html.start, value_ast.html.end) + "</div>";
166
- var replace = result.slice(parent.start + cursor, parent.end + cursor);
167
- result = result.replace(replace, markup + replace.replace(raw_value, ""));
168
- cursor += markup.length - raw_value.length;
169
- }
170
- }
171
- });
172
- if (prev === "h3") {
173
- headings.push("</ul>");
174
- }
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>");
176
- return {
177
- code: "<script>" + __spreadArray([], __read(new Set(script_content)), false).join("") + "</script>\n <style>" + style_content + "</style>\n <main class=\"markdown-body\">" + result + "</main>"
178
- };
179
- }
180
- };
181
- }
182
- exports.preprocessReadme = preprocessReadme;
package/dist/style.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const css = ".anchor {\n float: left;\n line-height: 1;\n margin-left: -20px;\n padding-right: 4px;\n}\n\n.anchor:focus {\n outline: none;\n}\n\nh1:hover .anchor,\nh2:hover .anchor,\nh3:hover .anchor,\nh4:hover .anchor,\nh5:hover .anchor,\nh6:hover .anchor {\n text-decoration: none;\n}main {\n -ms-text-size-adjust: 100%;\n -webkit-text-size-adjust: 100%;\n line-height: 1.5;\n color: #24292e;\n font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;\n font-size: 16px;\n line-height: 1.5;\n word-wrap: break-word;\n}\n\ndetails {\n display: block;\n}\n\nsummary {\n display: list-item;\n}\n\na {\n background-color: initial;\n}\n\na:active,\na:hover {\n outline-width: 0;\n}\n\nstrong {\n font-weight: inherit;\n font-weight: bolder;\n}\n\nh1 {\n font-size: 2em;\n margin: .67em 0;\n}\n\nimg {\n border-style: none;\n}\n\ncode,\nkbd,\npre {\n font-family: monospace,monospace;\n font-size: 1em;\n}\n\nhr {\n box-sizing: initial;\n height: 0;\n overflow: visible;\n}\n\ninput {\n font: inherit;\n margin: 0;\n}\n\ninput {\n overflow: visible;\n}\n\n[type=checkbox] {\n box-sizing: border-box;\n padding: 0;\n}\n\n* {\n box-sizing: border-box;\n}\n\ninput {\n font-family: inherit;\n font-size: inherit;\n line-height: inherit;\n}\n\na {\n color: #0366d6;\n text-decoration: none;\n}\n\na:hover {\n text-decoration: underline;\n}\n\nstrong {\n font-weight: 600;\n}\n\nhr {\n height: 0;\n margin: 15px 0;\n overflow: hidden;\n background: transparent;\n border: 0;\n border-bottom: 1px solid #dfe2e5;\n}\n\nhr:after,\nhr:before {\n display: table;\n content: \"\";\n}\n\nhr:after {\n clear: both;\n}\n\ntable {\n border-spacing: 0;\n border-collapse: collapse;\n}\n\ntd,\nth {\n padding: 0;\n}\n\ndetails summary {\n cursor: pointer;\n}\n\nkbd {\n display: inline-block;\n padding: 3px 5px;\n font: 11px SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;\n line-height: 10px;\n color: #444d56;\n vertical-align: middle;\n background-color: #fafbfc;\n border: 1px solid #d1d5da;\n border-radius: 3px;\n box-shadow: inset 0 -1px 0 #d1d5da;\n}\n\nh1,\nh2,\nh3,\nh4,\nh5,\nh6 {\n margin-top: 0;\n margin-bottom: 0;\n}\n\nh1 {\n font-size: 32px;\n}\n\nh1,\nh2 {\n font-weight: 600;\n}\n\nh2 {\n font-size: 24px;\n}\n\nh3 {\n font-size: 20px;\n}\n\nh3,\nh4 {\n font-weight: 600;\n}\n\nh4 {\n font-size: 16px;\n}\n\nh5 {\n font-size: 14px;\n}\n\nh5,\nh6 {\n font-weight: 600;\n}\n\nh6 {\n font-size: 12px;\n}\n\np {\n margin-top: 0;\n margin-bottom: 10px;\n}\n\nblockquote {\n margin: 0;\n}\n\nol,\nul {\n padding-left: 0;\n margin-top: 0;\n margin-bottom: 0;\n}\n\nol ol,\nul ol {\n list-style-type: lower-roman;\n}\n\nol ol ol,\nol ul ol,\nul ol ol,\nul ul ol {\n list-style-type: lower-alpha;\n}\n\ndd {\n margin-left: 0;\n}\n\ncode,\npre {\n font-family: SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;\n font-size: 12px;\n}\n\npre {\n margin-top: 0;\n margin-bottom: 0;\n}\n\ninput::-webkit-inner-spin-button,\ninput::-webkit-outer-spin-button {\n margin: 0;\n -webkit-appearance: none;\n appearance: none;\n}\n\n:checked+.radio-label {\n position: relative;\n z-index: 1;\n border-color: #0366d6;\n}\n\nhr {\n border-bottom-color: #eee;\n}\n\nkbd {\n display: inline-block;\n padding: 3px 5px;\n font: 11px SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;\n line-height: 10px;\n color: #444d56;\n vertical-align: middle;\n background-color: #fafbfc;\n border: 1px solid #d1d5da;\n border-radius: 3px;\n box-shadow: inset 0 -1px 0 #d1d5da;\n}\n\nmain:after,\n.markdown-body:before {\n display: table;\n content: \"\";\n}\n\nmain:after {\n clear: both;\n}\n\nmain>:first-child {\n margin-top: 0!important;\n}\n\nmain>:last-child {\n margin-bottom: 0!important;\n}\n\na:not([href]) {\n color: inherit;\n text-decoration: none;\n}\n\nblockquote,\ndetails,\ndl,\nol,\np,\npre,\ntable,\nul {\n margin-top: 0;\n margin-bottom: 16px;\n}\n\nhr {\n height: .25em;\n padding: 0;\n margin: 24px 0;\n background-color: #e1e4e8;\n border: 0;\n}\n\nblockquote {\n padding: 0 1em;\n color: #6a737d;\n border-left: .25em solid #dfe2e5;\n}\n\nblockquote>:first-child {\n margin-top: 0;\n}\n\nblockquote>:last-child {\n margin-bottom: 0;\n}\n\nh1,\nh2,\nh3,\nh4,\nh5,\nh6 {\n margin-top: 24px;\n margin-bottom: 16px;\n font-weight: 600;\n line-height: 1.25;\n}\n\nh1 {\n font-size: 2em;\n}\n\nh1,\nh2 {\n padding-bottom: .3em;\n border-bottom: 1px solid #eaecef;\n}\n\nh2 {\n font-size: 1.5em;\n}\n\nh3 {\n font-size: 1.25em;\n}\n\nh4 {\n font-size: 1em;\n}\n\nh5 {\n font-size: .875em;\n}\n\nh6 {\n font-size: .85em;\n color: #6a737d;\n}\n\nol,\nul {\n padding-left: 2em;\n}\n\nol ol,\nol ul,\nul ol,\nul ul {\n margin-top: 0;\n margin-bottom: 0;\n}\n\nli {\n word-wrap: break-all;\n}\n\nli>p {\n margin-top: 16px;\n}\n\nli+li {\n margin-top: .25em;\n}\n\ndl {\n padding: 0;\n}\n\ndl dt {\n padding: 0;\n margin-top: 16px;\n font-size: 1em;\n font-style: italic;\n font-weight: 600;\n}\n\ndl dd {\n padding: 0 16px;\n margin-bottom: 16px;\n}\n\ntable {\n display: block;\n width: 100%;\n overflow: auto;\n}\n\ntable th {\n font-weight: 600;\n}\n\ntable td,\ntable th {\n padding: 6px 13px;\n border: 1px solid #dfe2e5;\n}\n\ntable tr {\n background-color: #fff;\n border-top: 1px solid #c6cbd1;\n}\n\ntable tr:nth-child(2n) {\n background-color: #f6f8fa;\n}\n\nimg {\n max-width: 100%;\n box-sizing: initial;\n background-color: #fff;\n}\n\nimg[align=right] {\n padding-left: 20px;\n}\n\nimg[align=left] {\n padding-right: 20px;\n}\n\ncode {\n padding: .2em .4em;\n margin: 0;\n font-size: 85%;\n background-color: rgba(27,31,35,.05);\n border-radius: 3px;\n}\n\npre {\n word-wrap: normal;\n}\n\npre>code {\n padding: 0;\n margin: 0;\n font-size: 100%;\n word-break: normal;\n white-space: pre;\n background: transparent;\n border: 0;\n}\n\n.highlight {\n margin-bottom: 16px;\n}\n\n.highlight pre {\n margin-bottom: 0;\n word-break: normal;\n}\n\n.highlight pre,\npre {\n padding: 16px;\n overflow: auto;\n font-size: 85%;\n line-height: 1.45;\n background-color: #f6f8fa;\n border-radius: 3px;\n}\n\npre code {\n display: inline;\n max-width: auto;\n padding: 0;\n margin: 0;\n overflow: visible;\n line-height: inherit;\n word-wrap: normal;\n background-color: initial;\n border: 0;\n}\n\n p { min-height: 28px; }\n pre { margin-bottom: 48px; }\n";