@vuepress/markdown 2.0.0-rc.11 → 2.0.0-rc.13

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/dist/index.d.ts CHANGED
@@ -33,46 +33,6 @@ interface AssetsPluginOptions {
33
33
  */
34
34
  declare const assetsPlugin: PluginWithOptions<AssetsPluginOptions>;
35
35
 
36
- interface CodePluginOptions {
37
- /**
38
- * Enable highlight lines or not
39
- */
40
- highlightLines?: boolean;
41
- /**
42
- * Enable line numbers or not
43
- *
44
- * - A `boolean` value is to enable line numbers or not.
45
- * - A `number` value is the minimum number of lines to enable line numbers
46
- */
47
- lineNumbers?: boolean | number;
48
- /**
49
- * Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
50
- * understand what's it for
51
- *
52
- * - Required for `highlightLines`
53
- * - Required for `lineNumbers`
54
- * - Required for title display of default theme
55
- */
56
- preWrapper?: boolean;
57
- /**
58
- * Add `v-pre` directive or not
59
- */
60
- vPre?: {
61
- /**
62
- * Add `v-pre` directive to `<pre>` tag of code block or not
63
- */
64
- block?: boolean;
65
- /**
66
- * Add `v-pre` directive to `<code>` tag of inline code or not
67
- */
68
- inline?: boolean;
69
- };
70
- }
71
- /**
72
- * Code plugin
73
- */
74
- declare const codePlugin: PluginWithOptions<CodePluginOptions>;
75
-
76
36
  type EmojiPluginOptions = Options;
77
37
 
78
38
  interface ImportCodePluginOptions {
@@ -111,12 +71,26 @@ interface LinksPluginOptions {
111
71
  */
112
72
  declare const linksPlugin: PluginWithOptions<LinksPluginOptions>;
113
73
 
74
+ interface VPrePluginOptions {
75
+ /**
76
+ * Add `v-pre` directive to `<pre>` tag of code block or not
77
+ */
78
+ block?: boolean;
79
+ /**
80
+ * Add `v-pre` directive to `<code>` tag of inline code or not
81
+ */
82
+ inline?: boolean;
83
+ }
84
+ /**
85
+ * v-pre plugin
86
+ */
87
+ declare const vPrePlugin: PluginWithOptions<VPrePluginOptions>;
88
+
114
89
  type Markdown = MarkdownIt;
115
90
 
116
91
  interface MarkdownOptions extends Options$1 {
117
92
  anchor?: false | AnchorPluginOptions;
118
93
  assets?: false | AssetsPluginOptions;
119
- code?: false | CodePluginOptions;
120
94
  component?: false;
121
95
  emoji?: false | EmojiPluginOptions;
122
96
  frontmatter?: false | FrontmatterPluginOptions;
@@ -127,6 +101,11 @@ interface MarkdownOptions extends Options$1 {
127
101
  sfc?: false | SfcPluginOptions;
128
102
  slugify?: MarkdownSlugifyFunction;
129
103
  toc?: false | TocPluginOptions;
104
+ vPre?: false | VPrePluginOptions;
105
+ /**
106
+ * @deprecated This feature has been removed. Please use `@vuepress/plugin-prismjs` or `@vuepress/plugin-shiki` instead.
107
+ */
108
+ code?: never;
130
109
  }
131
110
  /**
132
111
  * Headers in markdown file
@@ -183,6 +162,6 @@ type MarkdownSlugifyFunction = (str: string) => string;
183
162
  /**
184
163
  * Create vuepress customized markdown-it instance
185
164
  */
186
- declare const createMarkdown: ({ anchor, assets, code, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
165
+ declare const createMarkdown: ({ anchor, assets, code, vPre, component, emoji, frontmatter, headers, title, importCode, links, sfc, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
187
166
 
188
- export { type AnchorPluginOptions, type AssetsPluginOptions, type CodePluginOptions, type EmojiPluginOptions, type ImportCodePluginOptions, type LinksPluginOptions, type Markdown, type MarkdownEnv, type MarkdownHeader, type MarkdownLink, type MarkdownOptions, type MarkdownSlugifyFunction, assetsPlugin, codePlugin, createMarkdown, importCodePlugin, linksPlugin };
167
+ export { type AnchorPluginOptions, type AssetsPluginOptions, type EmojiPluginOptions, type ImportCodePluginOptions, type LinksPluginOptions, type Markdown, type MarkdownEnv, type MarkdownHeader, type MarkdownLink, type MarkdownOptions, type MarkdownSlugifyFunction, type VPrePluginOptions, assetsPlugin, createMarkdown, importCodePlugin, linksPlugin, vPrePlugin };
package/dist/index.js CHANGED
@@ -1,11 +1,6 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
1
  // src/markdown.ts
8
2
  import { slugify as defaultSlugify } from "@mdit-vue/shared";
3
+ import { logger as logger2 } from "@vuepress/utils";
9
4
  import MarkdownIt from "markdown-it";
10
5
 
11
6
  // src/plugins.ts
@@ -104,208 +99,6 @@ var assetsPlugin = (md, {
104
99
  md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
105
100
  };
106
101
 
107
- // src/plugins/codePlugin/resolveAttr.ts
108
- var resolveAttr = (info, attr) => {
109
- const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+?)\\k<quote>(\\s|$)`;
110
- const regex = new RegExp(pattern, "i");
111
- const match = info.match(regex);
112
- return match?.groups?.content ?? null;
113
- };
114
-
115
- // src/plugins/codePlugin/resolveHighlightLines.ts
116
- var resolveHighlightLines = (info) => {
117
- const match = info.match(/{([\d,-]+)}/);
118
- if (match === null) {
119
- return null;
120
- }
121
- return match[1].split(",").map((item) => {
122
- const range = item.split("-");
123
- if (range.length === 1) {
124
- range.push(range[0]);
125
- }
126
- return range.map((str) => Number.parseInt(str, 10));
127
- });
128
- };
129
- var isHighlightLine = (lineNumber, ranges) => ranges.some(([start, end]) => lineNumber >= start && lineNumber <= end);
130
-
131
- // src/plugins/codePlugin/languages.ts
132
- var languages_exports = {};
133
- __export(languages_exports, {
134
- languageBash: () => languageBash,
135
- languageCsharp: () => languageCsharp,
136
- languageDocker: () => languageDocker,
137
- languageFsharp: () => languageFsharp,
138
- languageJavascript: () => languageJavascript,
139
- languageKotlin: () => languageKotlin,
140
- languageMarkdown: () => languageMarkdown,
141
- languagePython: () => languagePython,
142
- languageRuby: () => languageRuby,
143
- languageRust: () => languageRust,
144
- languageStylus: () => languageStylus,
145
- languageTypescript: () => languageTypescript,
146
- languageYaml: () => languageYaml
147
- });
148
- var languageBash = {
149
- name: "bash",
150
- ext: "sh",
151
- aliases: ["bash", "sh", "shell", "zsh"]
152
- };
153
- var languageCsharp = {
154
- name: "csharp",
155
- ext: "cs",
156
- aliases: ["cs", "csharp"]
157
- };
158
- var languageDocker = {
159
- name: "docker",
160
- ext: "docker",
161
- aliases: ["docker", "dockerfile"]
162
- };
163
- var languageFsharp = {
164
- name: "fsharp",
165
- ext: "fs",
166
- aliases: ["fs", "fsharp"]
167
- };
168
- var languageJavascript = {
169
- name: "javascript",
170
- ext: "js",
171
- aliases: ["javascript", "js"]
172
- };
173
- var languageKotlin = {
174
- name: "kotlin",
175
- ext: "kt",
176
- aliases: ["kotlin", "kt"]
177
- };
178
- var languageMarkdown = {
179
- name: "markdown",
180
- ext: "md",
181
- aliases: ["markdown", "md"]
182
- };
183
- var languagePython = {
184
- name: "python",
185
- ext: "py",
186
- aliases: ["py", "python"]
187
- };
188
- var languageRuby = {
189
- name: "ruby",
190
- ext: "rb",
191
- aliases: ["rb", "ruby"]
192
- };
193
- var languageRust = {
194
- name: "rust",
195
- ext: "rs",
196
- aliases: ["rs", "rust"]
197
- };
198
- var languageStylus = {
199
- name: "stylus",
200
- ext: "styl",
201
- aliases: ["styl", "stylus"]
202
- };
203
- var languageTypescript = {
204
- name: "typescript",
205
- ext: "ts",
206
- aliases: ["ts", "typescript"]
207
- };
208
- var languageYaml = {
209
- name: "yaml",
210
- ext: "yml",
211
- aliases: ["yaml", "yml"]
212
- };
213
-
214
- // src/plugins/codePlugin/resolveLanguage.ts
215
- var languagesMap;
216
- var getLanguagesMap = () => {
217
- if (!languagesMap) {
218
- languagesMap = Object.values(languages_exports).reduce((result, item) => {
219
- item.aliases.forEach((alias) => {
220
- result[alias] = item;
221
- });
222
- return result;
223
- }, {});
224
- }
225
- return languagesMap;
226
- };
227
- var resolveLanguage = (info) => {
228
- const alias = info.match(/^([^ :[{]+)/)?.[1] || "text";
229
- return getLanguagesMap()[alias] ?? {
230
- name: alias,
231
- ext: alias,
232
- aliases: [alias]
233
- };
234
- };
235
-
236
- // src/plugins/codePlugin/resolveLineNumbers.ts
237
- var resolveLineNumbers = (info) => {
238
- if (/:line-numbers\b/.test(info)) {
239
- return true;
240
- }
241
- if (/:no-line-numbers\b/.test(info)) {
242
- return false;
243
- }
244
- return null;
245
- };
246
-
247
- // src/plugins/codePlugin/resolveVPre.ts
248
- var resolveVPre = (info) => {
249
- if (/:v-pre\b/.test(info)) {
250
- return true;
251
- }
252
- if (/:no-v-pre\b/.test(info)) {
253
- return false;
254
- }
255
- return null;
256
- };
257
-
258
- // src/plugins/codePlugin/codePlugin.ts
259
- var codePlugin = (md, {
260
- highlightLines = true,
261
- lineNumbers = true,
262
- preWrapper = true,
263
- vPre: { block: vPreBlock = true, inline: vPreInline = true } = {}
264
- } = {}) => {
265
- md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
266
- const token = tokens[idx];
267
- const info = token.info ? md.utils.unescapeAll(token.info).trim() : "";
268
- const language = resolveLanguage(info);
269
- const languageClass = `${options.langPrefix}${language.name}`;
270
- const code = options.highlight?.(token.content, language.name, "") || md.utils.escapeHtml(token.content);
271
- token.attrJoin("class", languageClass);
272
- let result = code.startsWith("<pre") ? code : `<pre${slf.renderAttrs(token)}><code>${code}</code></pre>`;
273
- const useVPre = resolveVPre(info) ?? vPreBlock;
274
- if (useVPre) {
275
- result = `<pre v-pre${result.slice("<pre".length)}`;
276
- }
277
- if (!preWrapper) {
278
- return result;
279
- }
280
- const lines = code.split("\n").slice(0, -1);
281
- const highlightLinesRanges = highlightLines ? resolveHighlightLines(info) : null;
282
- if (highlightLinesRanges) {
283
- const highlightLinesCode = lines.map((_, index) => {
284
- if (isHighlightLine(index + 1, highlightLinesRanges)) {
285
- return '<div class="highlight-line">&nbsp;</div>';
286
- }
287
- return "<br>";
288
- }).join("");
289
- result = `${result}<div class="highlight-lines">${highlightLinesCode}</div>`;
290
- }
291
- const useLineNumbers = resolveLineNumbers(info) ?? (typeof lineNumbers === "number" ? lines.length >= lineNumbers : lineNumbers);
292
- if (useLineNumbers) {
293
- const lineNumbersCode = lines.map(() => `<div class="line-number"></div>`).join("");
294
- result = `${result}<div class="line-numbers" aria-hidden="true">${lineNumbersCode}</div>`;
295
- }
296
- const title = resolveAttr(info, "title") ?? language.ext;
297
- result = `<div class="${languageClass}${useLineNumbers ? " line-numbers-mode" : ""}" data-ext="${language.ext}" data-title="${title}">${result}</div>`;
298
- return result;
299
- };
300
- if (vPreInline) {
301
- const rawInlineCodeRule = md.renderer.rules.code_inline;
302
- md.renderer.rules.code_inline = (tokens, idx, options, env, slf) => {
303
- const result = rawInlineCodeRule(tokens, idx, options, env, slf);
304
- return `<code v-pre${result.slice("<code".length)}`;
305
- };
306
- }
307
- };
308
-
309
102
  // src/plugins/emojiPlugin.ts
310
103
  import { full as emojiPlugin } from "markdown-it-emoji";
311
104
 
@@ -504,11 +297,45 @@ var linksPlugin = (md, options = {}) => {
504
297
  };
505
298
  };
506
299
 
300
+ // src/plugins/vPrePlugin/resolveVPre.ts
301
+ var resolveVPre = (info) => {
302
+ if (/:v-pre\b/.test(info)) {
303
+ return true;
304
+ }
305
+ if (/:no-v-pre\b/.test(info)) {
306
+ return false;
307
+ }
308
+ return null;
309
+ };
310
+
311
+ // src/plugins/vPrePlugin/vPrePlugin.ts
312
+ var vPrePlugin = (md, { inline = true, block = true } = {}) => {
313
+ const rawFence = md.renderer.rules.fence;
314
+ md.renderer.rules.fence = (...args) => {
315
+ const [tokens, idx] = args;
316
+ const token = tokens[idx];
317
+ const info = token.info ? md.utils.unescapeAll(token.info).trim() : "";
318
+ let result = rawFence(...args);
319
+ if (resolveVPre(info) ?? block) {
320
+ result = `<pre v-pre${result.slice("<pre".length)}`;
321
+ }
322
+ return result;
323
+ };
324
+ if (inline) {
325
+ const rawInlineCodeRule = md.renderer.rules.code_inline;
326
+ md.renderer.rules.code_inline = (...args) => {
327
+ const result = rawInlineCodeRule(...args);
328
+ return `<code v-pre${result.slice("<code".length)}`;
329
+ };
330
+ }
331
+ };
332
+
507
333
  // src/markdown.ts
508
334
  var createMarkdown = ({
509
335
  anchor,
510
336
  assets,
511
337
  code,
338
+ vPre,
512
339
  component,
513
340
  emoji,
514
341
  frontmatter,
@@ -541,8 +368,11 @@ var createMarkdown = ({
541
368
  if (assets !== false) {
542
369
  md.use(assetsPlugin, assets);
543
370
  }
544
- if (code !== false) {
545
- md.use(codePlugin, code);
371
+ if (code) {
372
+ logger2.warn(
373
+ `\`markdown.code\` option has been removed, please use '@vuepress/plugin-shiki' or '@vuepress/plugin-prismjs' instead.
374
+ See https://v2.vuepress.vuejs.org/reference/config.html#markdown-code`
375
+ );
546
376
  }
547
377
  if (component !== false) {
548
378
  md.use(componentPlugin);
@@ -586,12 +416,14 @@ var createMarkdown = ({
586
416
  if (title !== false) {
587
417
  md.use(titlePlugin);
588
418
  }
419
+ if (vPre !== false) {
420
+ md.use(vPrePlugin, vPre);
421
+ }
589
422
  return md;
590
423
  };
591
424
  export {
592
425
  anchorPlugin,
593
426
  assetsPlugin,
594
- codePlugin,
595
427
  componentPlugin,
596
428
  createMarkdown,
597
429
  emojiPlugin,
@@ -601,5 +433,6 @@ export {
601
433
  linksPlugin,
602
434
  sfcPlugin,
603
435
  titlePlugin,
604
- tocPlugin
436
+ tocPlugin,
437
+ vPrePlugin
605
438
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-rc.11",
3
+ "version": "2.0.0-rc.13",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -38,11 +38,11 @@
38
38
  "@types/markdown-it": "^14.1.1",
39
39
  "@types/markdown-it-emoji": "^3.0.1",
40
40
  "markdown-it": "^14.1.0",
41
- "markdown-it-anchor": "^8.6.7",
41
+ "markdown-it-anchor": "^9.0.1",
42
42
  "markdown-it-emoji": "^3.0.0",
43
43
  "mdurl": "^2.0.0",
44
- "@vuepress/shared": "2.0.0-rc.11",
45
- "@vuepress/utils": "2.0.0-rc.11"
44
+ "@vuepress/shared": "2.0.0-rc.13",
45
+ "@vuepress/utils": "2.0.0-rc.13"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/mdurl": "^2.0.0"