vite-plugin-svelte-md 0.1.3 → 0.1.6

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 CHANGED
@@ -89,35 +89,42 @@ import svelteMd from "vite-plugin-svelte-md";
89
89
 
90
90
  export default defineConfig({
91
91
  plugins: [
92
+ svelteMd(), // <--
92
93
  svelte({
93
94
  extensions: [".svelte", ".md"], // <--
94
95
  }),
95
- svelteMd(), // <--
96
96
  ],
97
97
  });
98
98
  ```
99
99
 
100
100
  ### with [SvelteKit]
101
101
 
102
- Add it to `svelte.config.js`
102
+ Edit `svelte.config.js`
103
103
 
104
104
  ```js
105
105
  // svelte.config.js
106
- import svelteMd from "vite-plugin-svelte-md";
107
-
108
106
  /** @type {import('@sveltejs/kit').Config} */
109
107
  const config = {
110
108
  extensions: [".svelte", ".md"], // <--
111
- kit: {
112
- vite: {
113
- plugins: [
114
- svelteMd(), // <--
115
- ],
116
- },
117
- },
118
109
  };
119
110
  ```
120
111
 
112
+ Add it to `vite.config.js`
113
+
114
+ ```ts
115
+ // vite.config.js
116
+ import { defineConfig } from "vite";
117
+ import { sveltekit } from "@sveltejs/kit/vite"
118
+ import svelteMd from "vite-plugin-svelte-md";
119
+
120
+ export default defineConfig({
121
+ plugins: [
122
+ svelteMd(), // <--
123
+ sveltekit(),
124
+ ],
125
+ });
126
+ ```
127
+
121
128
  [sveltekit]: https://kit.svelte.dev/
122
129
  [vite]: https://vitejs.dev/
123
130
 
package/lib/index.d.ts CHANGED
@@ -32,4 +32,4 @@ interface Options {
32
32
  */
33
33
  declare function export_default(options?: Options): Plugin;
34
34
 
35
- export { export_default as default };
35
+ export { Options, export_default as default };
package/lib/index.js CHANGED
@@ -1,53 +1,36 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
6
  var __getProtoOf = Object.getPrototypeOf;
9
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
8
  var __export = (target, all) => {
26
- __markAsModule(target);
27
9
  for (var name in all)
28
10
  __defProp(target, name, { get: all[name], enumerable: true });
29
11
  };
30
- var __reExport = (target, module2, desc) => {
31
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
32
- for (let key of __getOwnPropNames(module2))
33
- if (!__hasOwnProp.call(target, key) && key !== "default")
34
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
35
17
  }
36
- return target;
37
- };
38
- var __toModule = (module2) => {
39
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
18
+ return to;
40
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
22
 
42
23
  // src/index.ts
43
- __export(exports, {
24
+ var src_exports = {};
25
+ __export(src_exports, {
44
26
  default: () => src_default
45
27
  });
46
- var import_pluginutils = __toModule(require("@rollup/pluginutils"));
28
+ module.exports = __toCommonJS(src_exports);
29
+ var import_pluginutils = require("@rollup/pluginutils");
47
30
 
48
31
  // src/markdown.ts
49
- var import_markdown_it = __toModule(require("markdown-it"));
50
- var import_gray_matter = __toModule(require("gray-matter"));
32
+ var import_markdown_it = __toESM(require("markdown-it"));
33
+ var import_gray_matter = __toESM(require("gray-matter"));
51
34
 
52
35
  // src/markdown-it-svelte-tags/index.ts
53
36
  var SVELTE_TAGS_RE = /^(?:<svelte:[a-z][^>]*>|<\/svelte:[a-z]+>)/u;
@@ -151,7 +134,7 @@ function headObjToTags(obj) {
151
134
  if (key === "title") {
152
135
  tags.push(`<title>${obj[key]}</title>`);
153
136
  } else if (key === "base") {
154
- tags.push(`<base ${attrs(__spreadValues({ key: "default" }, obj[key]))}>`);
137
+ tags.push(`<base ${attrs({ key: "default", ...obj[key] })}>`);
155
138
  } else if (headProperties.includes(key)) {
156
139
  const value = obj[key];
157
140
  if (Array.isArray(value)) {
@@ -225,11 +208,12 @@ function parseHtml(html) {
225
208
  return { html: newHtml, moduleContext, instanceScript, svelteTags };
226
209
  }
227
210
  function createMarkdownProcessor(options) {
228
- const markdownIt = new import_markdown_it.default(__spreadValues({
211
+ const markdownIt = new import_markdown_it.default({
229
212
  html: true,
230
213
  linkify: true,
231
- typographer: true
232
- }, options.markdownItOptions));
214
+ typographer: true,
215
+ ...options.markdownItOptions
216
+ });
233
217
  markdownIt.linkify.set({ fuzzyLink: false });
234
218
  const originalValidateLink = markdownIt.validateLink;
235
219
  markdownIt.validateLink = (url) => {
@@ -244,17 +228,16 @@ function createMarkdownProcessor(options) {
244
228
  markdownIt.use(plugin3, ...options2);
245
229
  });
246
230
  return (id, text) => {
247
- var _a, _b;
248
231
  const raw = text.trimEnd();
249
232
  const { wrapperClasses, headEnabled } = options;
250
233
  const parsedFrontmatter = (0, import_gray_matter.default)(raw);
251
- const plainMarkdown = (_a = parsedFrontmatter == null ? void 0 : parsedFrontmatter.content) != null ? _a : raw;
234
+ const plainMarkdown = (parsedFrontmatter == null ? void 0 : parsedFrontmatter.content) ?? raw;
252
235
  let html = markdownIt.render(plainMarkdown, { id });
253
236
  if (wrapperClasses) {
254
237
  html = `<div class="${wrapperClasses}">${html}</div>`;
255
238
  }
256
239
  const parsedHtml = parseHtml(html);
257
- const { head, frontmatter } = frontmatterPreprocess((_b = parsedFrontmatter == null ? void 0 : parsedFrontmatter.data) != null ? _b : {}, options);
240
+ const { head, frontmatter } = frontmatterPreprocess((parsedFrontmatter == null ? void 0 : parsedFrontmatter.data) ?? {}, options);
258
241
  parsedHtml.moduleContext.prepend(`export const frontmatter = ${JSON.stringify(frontmatter)}`);
259
242
  if (headEnabled && head) {
260
243
  let svelteHead = parsedHtml.svelteTags.find((tag) => tag.tagName === "svelte:head");
@@ -278,16 +261,15 @@ function frontmatterPreprocess(frontmatter, options) {
278
261
 
279
262
  // src/options.ts
280
263
  function resolveOptions(userOptions) {
281
- var _a;
282
- const options = __spreadProps(__spreadValues({
264
+ const options = {
283
265
  headEnabled: true,
284
266
  markdownItOptions: {},
285
267
  markdownItUses: [],
286
268
  include: null,
287
- exclude: null
288
- }, userOptions), {
289
- wrapperClasses: toArray((_a = userOptions.wrapperClasses) != null ? _a : "markdown-body").filter((i) => i).join(" ")
290
- });
269
+ exclude: null,
270
+ ...userOptions,
271
+ wrapperClasses: toArray(userOptions.wrapperClasses ?? "markdown-body").filter((i) => i).join(" ")
272
+ };
291
273
  return options;
292
274
  }
293
275
 
package/lib/index.mjs CHANGED
@@ -1,23 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
-
21
1
  // src/index.ts
22
2
  import { createFilter } from "@rollup/pluginutils";
23
3
 
@@ -127,7 +107,7 @@ function headObjToTags(obj) {
127
107
  if (key === "title") {
128
108
  tags.push(`<title>${obj[key]}</title>`);
129
109
  } else if (key === "base") {
130
- tags.push(`<base ${attrs(__spreadValues({ key: "default" }, obj[key]))}>`);
110
+ tags.push(`<base ${attrs({ key: "default", ...obj[key] })}>`);
131
111
  } else if (headProperties.includes(key)) {
132
112
  const value = obj[key];
133
113
  if (Array.isArray(value)) {
@@ -201,11 +181,12 @@ function parseHtml(html) {
201
181
  return { html: newHtml, moduleContext, instanceScript, svelteTags };
202
182
  }
203
183
  function createMarkdownProcessor(options) {
204
- const markdownIt = new MarkdownIt(__spreadValues({
184
+ const markdownIt = new MarkdownIt({
205
185
  html: true,
206
186
  linkify: true,
207
- typographer: true
208
- }, options.markdownItOptions));
187
+ typographer: true,
188
+ ...options.markdownItOptions
189
+ });
209
190
  markdownIt.linkify.set({ fuzzyLink: false });
210
191
  const originalValidateLink = markdownIt.validateLink;
211
192
  markdownIt.validateLink = (url) => {
@@ -220,17 +201,16 @@ function createMarkdownProcessor(options) {
220
201
  markdownIt.use(plugin3, ...options2);
221
202
  });
222
203
  return (id, text) => {
223
- var _a, _b;
224
204
  const raw = text.trimEnd();
225
205
  const { wrapperClasses, headEnabled } = options;
226
206
  const parsedFrontmatter = grayMatter(raw);
227
- const plainMarkdown = (_a = parsedFrontmatter == null ? void 0 : parsedFrontmatter.content) != null ? _a : raw;
207
+ const plainMarkdown = (parsedFrontmatter == null ? void 0 : parsedFrontmatter.content) ?? raw;
228
208
  let html = markdownIt.render(plainMarkdown, { id });
229
209
  if (wrapperClasses) {
230
210
  html = `<div class="${wrapperClasses}">${html}</div>`;
231
211
  }
232
212
  const parsedHtml = parseHtml(html);
233
- const { head, frontmatter } = frontmatterPreprocess((_b = parsedFrontmatter == null ? void 0 : parsedFrontmatter.data) != null ? _b : {}, options);
213
+ const { head, frontmatter } = frontmatterPreprocess((parsedFrontmatter == null ? void 0 : parsedFrontmatter.data) ?? {}, options);
234
214
  parsedHtml.moduleContext.prepend(`export const frontmatter = ${JSON.stringify(frontmatter)}`);
235
215
  if (headEnabled && head) {
236
216
  let svelteHead = parsedHtml.svelteTags.find((tag) => tag.tagName === "svelte:head");
@@ -254,16 +234,15 @@ function frontmatterPreprocess(frontmatter, options) {
254
234
 
255
235
  // src/options.ts
256
236
  function resolveOptions(userOptions) {
257
- var _a;
258
- const options = __spreadProps(__spreadValues({
237
+ const options = {
259
238
  headEnabled: true,
260
239
  markdownItOptions: {},
261
240
  markdownItUses: [],
262
241
  include: null,
263
- exclude: null
264
- }, userOptions), {
265
- wrapperClasses: toArray((_a = userOptions.wrapperClasses) != null ? _a : "markdown-body").filter((i) => i).join(" ")
266
- });
242
+ exclude: null,
243
+ ...userOptions,
244
+ wrapperClasses: toArray(userOptions.wrapperClasses ?? "markdown-body").filter((i) => i).join(" ")
245
+ };
267
246
  return options;
268
247
  }
269
248
 
package/package.json CHANGED
@@ -1,92 +1,92 @@
1
1
  {
2
- "name": "vite-plugin-svelte-md",
3
- "version": "0.1.3",
4
- "description": "Vite plugin to convert markdown to svelte template",
5
- "files": [
6
- "lib"
7
- ],
8
- "main": "./lib/index.js",
9
- "module": "./lib/index.mjs",
10
- "exports": {
11
- ".": {
12
- "import": "./lib/index.mjs",
13
- "require": "./lib/index.js"
14
- }
15
- },
16
- "types": "./lib/index.d.ts",
17
- "scripts": {
18
- "prebuild": "npm run -s clean",
19
- "build": "tsup",
20
- "clean": "rimraf .nyc_output lib coverage",
21
- "lint": "eslint . --ext .js,.ts,.json",
22
- "eslint-fix": "npm run lint -- --fix",
23
- "format:docs": "prettier README.md --write",
24
- "test": "mocha --require ts-node/register \"tests/**/*.ts\" --reporter dot --timeout 60000",
25
- "cover": "nyc --reporter=lcov npm run test",
26
- "debug": "mocha --require ts-node/register/transpile-only \"tests/**/*.ts\" --reporter dot",
27
- "update-snap": "mocha --require ts-node/register/transpile-only \"tests/**/*.ts\" --reporter dot --update",
28
- "preversion": "npm run lint && npm test"
29
- },
30
- "repository": {
31
- "type": "git",
32
- "url": "git+https://github.com/ota-meshi/vite-plugin-svelte-md.git"
33
- },
34
- "keywords": [
35
- "vite",
36
- "vite-plugin",
37
- "svelte",
38
- "markdown",
39
- "markdown-it"
40
- ],
41
- "author": "Yosuke Ota",
42
- "funding": "https://github.com/sponsors/ota-meshi",
43
- "license": "MIT",
44
- "bugs": {
45
- "url": "https://github.com/ota-meshi/vite-plugin-svelte-md/issues"
46
- },
47
- "homepage": "https://github.com/ota-meshi/vite-plugin-svelte-md#readme",
48
- "peerDependencies": {
49
- "vite": "^2.0.0"
50
- },
51
- "dependencies": {
52
- "@rollup/pluginutils": "^4.1.1",
53
- "gray-matter": "^4.0.3",
54
- "markdown-it": "^12.2.0"
55
- },
56
- "devDependencies": {
57
- "@ota-meshi/eslint-plugin": "^0.10.0",
58
- "@types/chai": "^4.2.22",
59
- "@types/escape-html": "^1.0.1",
60
- "@types/estree": "0.0.50",
61
- "@types/markdown-it": "^12.2.3",
62
- "@types/mocha": "^9.0.0",
63
- "@types/node": "^16.11.11",
64
- "@types/prismjs": "^1.16.6",
65
- "@typescript-eslint/eslint-plugin": "^5.5.0",
66
- "@typescript-eslint/parser": "^5.5.0",
67
- "chai": "^4.3.4",
68
- "escape-html": "^1.0.3",
69
- "eslint": "^8.3.0",
70
- "eslint-config-prettier": "^8.3.0",
71
- "eslint-plugin-eslint-comments": "^3.2.0",
72
- "eslint-plugin-json-schema-validator": "^2.1.10",
73
- "eslint-plugin-jsonc": "^2.0.0",
74
- "eslint-plugin-node": "^11.1.0",
75
- "eslint-plugin-node-dependencies": "^0.6.0",
76
- "eslint-plugin-prettier": "^4.0.0",
77
- "eslint-plugin-regexp": "^1.0.0",
78
- "mocha": "^9.1.3",
79
- "mocha-chai-jest-snapshot": "^1.1.3",
80
- "nyc": "^15.1.0",
81
- "prettier": "^2.5.0",
82
- "prettier-plugin-svelte": "^2.5.0",
83
- "prism-svelte": "^0.4.7",
84
- "prismjs": "^1.25.0",
85
- "rimraf": "^3.0.2",
86
- "svelte": "^3.44.2",
87
- "ts-node": "^10.4.0",
88
- "tsup": "^5.10.0",
89
- "typescript": "^4.5.2",
90
- "vite": "^2.6.14"
2
+ "name": "vite-plugin-svelte-md",
3
+ "version": "0.1.6",
4
+ "description": "Vite plugin to convert markdown to svelte template",
5
+ "files": [
6
+ "lib"
7
+ ],
8
+ "main": "./lib/index.js",
9
+ "module": "./lib/index.mjs",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./lib/index.mjs",
13
+ "require": "./lib/index.js"
91
14
  }
15
+ },
16
+ "types": "./lib/index.d.ts",
17
+ "scripts": {
18
+ "prebuild": "npm run -s clean",
19
+ "build": "tsup",
20
+ "clean": "rimraf .nyc_output lib coverage",
21
+ "lint": "eslint . --ext .js,.ts,.json",
22
+ "eslint-fix": "npm run lint -- --fix",
23
+ "format:docs": "prettier README.md --write",
24
+ "test": "mocha --require ts-node/register \"tests/**/*.ts\" --reporter dot --timeout 60000",
25
+ "cover": "nyc --reporter=lcov npm run test",
26
+ "debug": "mocha --require ts-node/register/transpile-only \"tests/**/*.ts\" --reporter dot",
27
+ "update-snap": "mocha --require ts-node/register/transpile-only \"tests/**/*.ts\" --reporter dot --update",
28
+ "preversion": "npm run lint && npm test"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/ota-meshi/vite-plugin-svelte-md.git"
33
+ },
34
+ "keywords": [
35
+ "vite",
36
+ "vite-plugin",
37
+ "svelte",
38
+ "markdown",
39
+ "markdown-it"
40
+ ],
41
+ "author": "Yosuke Ota",
42
+ "funding": "https://github.com/sponsors/ota-meshi",
43
+ "license": "MIT",
44
+ "bugs": {
45
+ "url": "https://github.com/ota-meshi/vite-plugin-svelte-md/issues"
46
+ },
47
+ "homepage": "https://github.com/ota-meshi/vite-plugin-svelte-md#readme",
48
+ "peerDependencies": {
49
+ "vite": "^2.0.0 || ^3.0.0"
50
+ },
51
+ "dependencies": {
52
+ "@rollup/pluginutils": "^4.1.1",
53
+ "gray-matter": "^4.0.3",
54
+ "markdown-it": "^13.0.0"
55
+ },
56
+ "devDependencies": {
57
+ "@ota-meshi/eslint-plugin": "^0.11.0",
58
+ "@types/chai": "^4.2.22",
59
+ "@types/escape-html": "^1.0.1",
60
+ "@types/estree": "1.0.0",
61
+ "@types/markdown-it": "^12.2.3",
62
+ "@types/mocha": "^9.0.0",
63
+ "@types/node": "^16.11.11",
64
+ "@types/prismjs": "^1.16.6",
65
+ "@typescript-eslint/eslint-plugin": "^5.5.0",
66
+ "@typescript-eslint/parser": "^5.5.0",
67
+ "chai": "^4.3.4",
68
+ "escape-html": "^1.0.3",
69
+ "eslint": "^8.3.0",
70
+ "eslint-config-prettier": "^8.3.0",
71
+ "eslint-plugin-eslint-comments": "^3.2.0",
72
+ "eslint-plugin-json-schema-validator": "^3.0.0",
73
+ "eslint-plugin-jsonc": "^2.0.0",
74
+ "eslint-plugin-node": "^11.1.0",
75
+ "eslint-plugin-node-dependencies": "^0.9.0",
76
+ "eslint-plugin-prettier": "^4.0.0",
77
+ "eslint-plugin-regexp": "^1.0.0",
78
+ "mocha": "^10.0.0",
79
+ "mocha-chai-jest-snapshot": "^1.1.3",
80
+ "nyc": "^15.1.0",
81
+ "prettier": "^2.5.0",
82
+ "prettier-plugin-svelte": "^2.5.0",
83
+ "prism-svelte": "^0.4.7",
84
+ "prismjs": "^1.25.0",
85
+ "rimraf": "^3.0.2",
86
+ "svelte": "^3.44.2",
87
+ "ts-node": "^10.4.0",
88
+ "tsup": "^6.0.0",
89
+ "typescript": "^4.5.2",
90
+ "vite": "^3.0.0"
91
+ }
92
92
  }