vite-plugin-svelte-md 0.1.5 → 0.1.7

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.
Files changed (3) hide show
  1. package/lib/index.js +74 -19
  2. package/lib/index.mjs +73 -18
  3. package/package.json +9 -10
package/lib/index.js CHANGED
@@ -1,10 +1,27 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
9
  var __getProtoOf = Object.getPrototypeOf;
7
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8
25
  var __export = (target, all) => {
9
26
  for (var name in all)
10
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,8 +34,31 @@ var __copyProps = (to, from, except, desc) => {
17
34
  }
18
35
  return to;
19
36
  };
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));
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
21
41
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+ var __async = (__this, __arguments, generator) => {
43
+ return new Promise((resolve, reject) => {
44
+ var fulfilled = (value) => {
45
+ try {
46
+ step(generator.next(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var rejected = (value) => {
52
+ try {
53
+ step(generator.throw(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ };
58
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
59
+ step((generator = generator.apply(__this, __arguments)).next());
60
+ });
61
+ };
22
62
 
23
63
  // src/index.ts
24
64
  var src_exports = {};
@@ -134,7 +174,7 @@ function headObjToTags(obj) {
134
174
  if (key === "title") {
135
175
  tags.push(`<title>${obj[key]}</title>`);
136
176
  } else if (key === "base") {
137
- tags.push(`<base ${attrs({ key: "default", ...obj[key] })}>`);
177
+ tags.push(`<base ${attrs(__spreadValues({ key: "default" }, obj[key]))}>`);
138
178
  } else if (headProperties.includes(key)) {
139
179
  const value = obj[key];
140
180
  if (Array.isArray(value)) {
@@ -196,7 +236,9 @@ function parseHtml(html) {
196
236
  return "";
197
237
  });
198
238
  newHtml = newHtml.replace(SVELTE_TAGS_RE2, (_, startTag, inner) => {
199
- const tagName = GET_SVELTE_TAG_NAME_RE.exec(startTag.slice(1))[0].toLowerCase();
239
+ const tagName = GET_SVELTE_TAG_NAME_RE.exec(
240
+ startTag.slice(1)
241
+ )[0].toLowerCase();
200
242
  let svelteTag = svelteTags.find((tag) => tag.tagName === tagName);
201
243
  if (!svelteTag) {
202
244
  svelteTag = new TagContent(tagName);
@@ -208,12 +250,11 @@ function parseHtml(html) {
208
250
  return { html: newHtml, moduleContext, instanceScript, svelteTags };
209
251
  }
210
252
  function createMarkdownProcessor(options) {
211
- const markdownIt = new import_markdown_it.default({
253
+ const markdownIt = new import_markdown_it.default(__spreadValues({
212
254
  html: true,
213
255
  linkify: true,
214
- typographer: true,
215
- ...options.markdownItOptions
216
- });
256
+ typographer: true
257
+ }, options.markdownItOptions));
217
258
  markdownIt.linkify.set({ fuzzyLink: false });
218
259
  const originalValidateLink = markdownIt.validateLink;
219
260
  markdownIt.validateLink = (url) => {
@@ -228,19 +269,27 @@ function createMarkdownProcessor(options) {
228
269
  markdownIt.use(plugin3, ...options2);
229
270
  });
230
271
  return (id, text) => {
272
+ var _a, _b;
231
273
  const raw = text.trimEnd();
232
274
  const { wrapperClasses, headEnabled } = options;
233
275
  const parsedFrontmatter = (0, import_gray_matter.default)(raw);
234
- const plainMarkdown = (parsedFrontmatter == null ? void 0 : parsedFrontmatter.content) ?? raw;
276
+ const plainMarkdown = (_a = parsedFrontmatter == null ? void 0 : parsedFrontmatter.content) != null ? _a : raw;
235
277
  let html = markdownIt.render(plainMarkdown, { id });
236
278
  if (wrapperClasses) {
237
279
  html = `<div class="${wrapperClasses}">${html}</div>`;
238
280
  }
239
281
  const parsedHtml = parseHtml(html);
240
- const { head, frontmatter } = frontmatterPreprocess((parsedFrontmatter == null ? void 0 : parsedFrontmatter.data) ?? {}, options);
241
- parsedHtml.moduleContext.prepend(`export const frontmatter = ${JSON.stringify(frontmatter)}`);
282
+ const { head, frontmatter } = frontmatterPreprocess(
283
+ (_b = parsedFrontmatter == null ? void 0 : parsedFrontmatter.data) != null ? _b : {},
284
+ options
285
+ );
286
+ parsedHtml.moduleContext.prepend(
287
+ `export const frontmatter = ${JSON.stringify(frontmatter)}`
288
+ );
242
289
  if (headEnabled && head) {
243
- let svelteHead = parsedHtml.svelteTags.find((tag) => tag.tagName === "svelte:head");
290
+ let svelteHead = parsedHtml.svelteTags.find(
291
+ (tag) => tag.tagName === "svelte:head"
292
+ );
244
293
  if (!svelteHead) {
245
294
  svelteHead = new TagContent("svelte:head");
246
295
  parsedHtml.svelteTags.push(svelteHead);
@@ -261,15 +310,16 @@ function frontmatterPreprocess(frontmatter, options) {
261
310
 
262
311
  // src/options.ts
263
312
  function resolveOptions(userOptions) {
264
- const options = {
313
+ var _a;
314
+ const options = __spreadProps(__spreadValues({
265
315
  headEnabled: true,
266
316
  markdownItOptions: {},
267
317
  markdownItUses: [],
268
318
  include: null,
269
- exclude: null,
270
- ...userOptions,
271
- wrapperClasses: toArray(userOptions.wrapperClasses ?? "markdown-body").filter((i) => i).join(" ")
272
- };
319
+ exclude: null
320
+ }, userOptions), {
321
+ wrapperClasses: toArray((_a = userOptions.wrapperClasses) != null ? _a : "markdown-body").filter((i) => i).join(" ")
322
+ });
273
323
  return options;
274
324
  }
275
325
 
@@ -277,7 +327,10 @@ function resolveOptions(userOptions) {
277
327
  function src_default(options = {}) {
278
328
  const resolvedOptions = resolveOptions(options);
279
329
  const mdToSvelte = createMarkdownProcessor(resolvedOptions);
280
- const filter = (0, import_pluginutils.createFilter)(resolvedOptions.include || /\.md$/, resolvedOptions.exclude);
330
+ const filter = (0, import_pluginutils.createFilter)(
331
+ resolvedOptions.include || /\.md$/,
332
+ resolvedOptions.exclude
333
+ );
281
334
  return {
282
335
  name: "vite-plugin-svelte-md",
283
336
  enforce: "pre",
@@ -295,8 +348,10 @@ function src_default(options = {}) {
295
348
  if (!filter(ctx.file))
296
349
  return;
297
350
  const defaultRead = ctx.read;
298
- ctx.read = async function() {
299
- return mdToSvelte(ctx.file, await defaultRead());
351
+ ctx.read = function() {
352
+ return __async(this, null, function* () {
353
+ return mdToSvelte(ctx.file, yield defaultRead());
354
+ });
300
355
  };
301
356
  }
302
357
  };
package/lib/index.mjs CHANGED
@@ -1,3 +1,43 @@
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
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+
1
41
  // src/index.ts
2
42
  import { createFilter } from "@rollup/pluginutils";
3
43
 
@@ -107,7 +147,7 @@ function headObjToTags(obj) {
107
147
  if (key === "title") {
108
148
  tags.push(`<title>${obj[key]}</title>`);
109
149
  } else if (key === "base") {
110
- tags.push(`<base ${attrs({ key: "default", ...obj[key] })}>`);
150
+ tags.push(`<base ${attrs(__spreadValues({ key: "default" }, obj[key]))}>`);
111
151
  } else if (headProperties.includes(key)) {
112
152
  const value = obj[key];
113
153
  if (Array.isArray(value)) {
@@ -169,7 +209,9 @@ function parseHtml(html) {
169
209
  return "";
170
210
  });
171
211
  newHtml = newHtml.replace(SVELTE_TAGS_RE2, (_, startTag, inner) => {
172
- const tagName = GET_SVELTE_TAG_NAME_RE.exec(startTag.slice(1))[0].toLowerCase();
212
+ const tagName = GET_SVELTE_TAG_NAME_RE.exec(
213
+ startTag.slice(1)
214
+ )[0].toLowerCase();
173
215
  let svelteTag = svelteTags.find((tag) => tag.tagName === tagName);
174
216
  if (!svelteTag) {
175
217
  svelteTag = new TagContent(tagName);
@@ -181,12 +223,11 @@ function parseHtml(html) {
181
223
  return { html: newHtml, moduleContext, instanceScript, svelteTags };
182
224
  }
183
225
  function createMarkdownProcessor(options) {
184
- const markdownIt = new MarkdownIt({
226
+ const markdownIt = new MarkdownIt(__spreadValues({
185
227
  html: true,
186
228
  linkify: true,
187
- typographer: true,
188
- ...options.markdownItOptions
189
- });
229
+ typographer: true
230
+ }, options.markdownItOptions));
190
231
  markdownIt.linkify.set({ fuzzyLink: false });
191
232
  const originalValidateLink = markdownIt.validateLink;
192
233
  markdownIt.validateLink = (url) => {
@@ -201,19 +242,27 @@ function createMarkdownProcessor(options) {
201
242
  markdownIt.use(plugin3, ...options2);
202
243
  });
203
244
  return (id, text) => {
245
+ var _a, _b;
204
246
  const raw = text.trimEnd();
205
247
  const { wrapperClasses, headEnabled } = options;
206
248
  const parsedFrontmatter = grayMatter(raw);
207
- const plainMarkdown = (parsedFrontmatter == null ? void 0 : parsedFrontmatter.content) ?? raw;
249
+ const plainMarkdown = (_a = parsedFrontmatter == null ? void 0 : parsedFrontmatter.content) != null ? _a : raw;
208
250
  let html = markdownIt.render(plainMarkdown, { id });
209
251
  if (wrapperClasses) {
210
252
  html = `<div class="${wrapperClasses}">${html}</div>`;
211
253
  }
212
254
  const parsedHtml = parseHtml(html);
213
- const { head, frontmatter } = frontmatterPreprocess((parsedFrontmatter == null ? void 0 : parsedFrontmatter.data) ?? {}, options);
214
- parsedHtml.moduleContext.prepend(`export const frontmatter = ${JSON.stringify(frontmatter)}`);
255
+ const { head, frontmatter } = frontmatterPreprocess(
256
+ (_b = parsedFrontmatter == null ? void 0 : parsedFrontmatter.data) != null ? _b : {},
257
+ options
258
+ );
259
+ parsedHtml.moduleContext.prepend(
260
+ `export const frontmatter = ${JSON.stringify(frontmatter)}`
261
+ );
215
262
  if (headEnabled && head) {
216
- let svelteHead = parsedHtml.svelteTags.find((tag) => tag.tagName === "svelte:head");
263
+ let svelteHead = parsedHtml.svelteTags.find(
264
+ (tag) => tag.tagName === "svelte:head"
265
+ );
217
266
  if (!svelteHead) {
218
267
  svelteHead = new TagContent("svelte:head");
219
268
  parsedHtml.svelteTags.push(svelteHead);
@@ -234,15 +283,16 @@ function frontmatterPreprocess(frontmatter, options) {
234
283
 
235
284
  // src/options.ts
236
285
  function resolveOptions(userOptions) {
237
- const options = {
286
+ var _a;
287
+ const options = __spreadProps(__spreadValues({
238
288
  headEnabled: true,
239
289
  markdownItOptions: {},
240
290
  markdownItUses: [],
241
291
  include: null,
242
- exclude: null,
243
- ...userOptions,
244
- wrapperClasses: toArray(userOptions.wrapperClasses ?? "markdown-body").filter((i) => i).join(" ")
245
- };
292
+ exclude: null
293
+ }, userOptions), {
294
+ wrapperClasses: toArray((_a = userOptions.wrapperClasses) != null ? _a : "markdown-body").filter((i) => i).join(" ")
295
+ });
246
296
  return options;
247
297
  }
248
298
 
@@ -250,7 +300,10 @@ function resolveOptions(userOptions) {
250
300
  function src_default(options = {}) {
251
301
  const resolvedOptions = resolveOptions(options);
252
302
  const mdToSvelte = createMarkdownProcessor(resolvedOptions);
253
- const filter = createFilter(resolvedOptions.include || /\.md$/, resolvedOptions.exclude);
303
+ const filter = createFilter(
304
+ resolvedOptions.include || /\.md$/,
305
+ resolvedOptions.exclude
306
+ );
254
307
  return {
255
308
  name: "vite-plugin-svelte-md",
256
309
  enforce: "pre",
@@ -268,8 +321,10 @@ function src_default(options = {}) {
268
321
  if (!filter(ctx.file))
269
322
  return;
270
323
  const defaultRead = ctx.read;
271
- ctx.read = async function() {
272
- return mdToSvelte(ctx.file, await defaultRead());
324
+ ctx.read = function() {
325
+ return __async(this, null, function* () {
326
+ return mdToSvelte(ctx.file, yield defaultRead());
327
+ });
273
328
  };
274
329
  }
275
330
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-svelte-md",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Vite plugin to convert markdown to svelte template",
5
5
  "files": [
6
6
  "lib"
@@ -46,21 +46,20 @@
46
46
  },
47
47
  "homepage": "https://github.com/ota-meshi/vite-plugin-svelte-md#readme",
48
48
  "peerDependencies": {
49
- "vite": "^2.0.0"
49
+ "vite": "^2.0.0 || ^3.0.0 || ^4.0.0"
50
50
  },
51
51
  "dependencies": {
52
- "@rollup/pluginutils": "^4.1.1",
52
+ "@rollup/pluginutils": "^5.0.0",
53
53
  "gray-matter": "^4.0.3",
54
54
  "markdown-it": "^13.0.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@ota-meshi/eslint-plugin": "^0.11.0",
57
+ "@ota-meshi/eslint-plugin": "^0.13.0",
58
58
  "@types/chai": "^4.2.22",
59
59
  "@types/escape-html": "^1.0.1",
60
- "@types/estree": "0.0.52",
61
60
  "@types/markdown-it": "^12.2.3",
62
- "@types/mocha": "^9.0.0",
63
- "@types/node": "^16.11.11",
61
+ "@types/mocha": "^10.0.0",
62
+ "@types/node": "^18.0.0",
64
63
  "@types/prismjs": "^1.16.6",
65
64
  "@typescript-eslint/eslint-plugin": "^5.5.0",
66
65
  "@typescript-eslint/parser": "^5.5.0",
@@ -69,10 +68,10 @@
69
68
  "eslint": "^8.3.0",
70
69
  "eslint-config-prettier": "^8.3.0",
71
70
  "eslint-plugin-eslint-comments": "^3.2.0",
72
- "eslint-plugin-json-schema-validator": "^3.0.0",
71
+ "eslint-plugin-json-schema-validator": "^4.0.0",
73
72
  "eslint-plugin-jsonc": "^2.0.0",
74
73
  "eslint-plugin-node": "^11.1.0",
75
- "eslint-plugin-node-dependencies": "^0.9.0",
74
+ "eslint-plugin-node-dependencies": "^0.10.0",
76
75
  "eslint-plugin-prettier": "^4.0.0",
77
76
  "eslint-plugin-regexp": "^1.0.0",
78
77
  "mocha": "^10.0.0",
@@ -87,6 +86,6 @@
87
86
  "ts-node": "^10.4.0",
88
87
  "tsup": "^6.0.0",
89
88
  "typescript": "^4.5.2",
90
- "vite": "^2.6.14"
89
+ "vite": "^4.0.0"
91
90
  }
92
91
  }