@vuepress/markdown 2.0.0-beta.45 → 2.0.0-beta.48
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/lib/markdown.d.ts +1 -1
- package/lib/markdown.js +4 -4
- package/lib/plugins/assetsPlugin/assetsPlugin.js +10 -1
- package/lib/plugins/extractHeadersPlugin.d.ts +2 -1
- package/lib/plugins/extractHeadersPlugin.js +1 -1
- package/lib/plugins/tocPlugin/tocPlugin.d.ts +2 -1
- package/lib/plugins/tocPlugin/tocPlugin.js +1 -1
- package/lib/types.d.ts +5 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/vuepressSlugify.d.ts +5 -0
- package/lib/utils/{slugify.js → vuepressSlugify.js} +6 -3
- package/package.json +4 -4
- package/lib/utils/slugify.d.ts +0 -1
package/lib/markdown.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import type { Markdown, MarkdownOptions } from './types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Create vuepress customized markdown-it instance
|
|
4
4
|
*/
|
|
5
|
-
export declare const createMarkdown: ({ anchor, assets, code, customComponent, emoji, extractHeaders, extractTitle, hoistTags, importCode, links, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
|
|
5
|
+
export declare const createMarkdown: ({ anchor, assets, code, customComponent, emoji, extractHeaders, extractTitle, hoistTags, importCode, links, slugify, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown;
|
package/lib/markdown.js
CHANGED
|
@@ -7,7 +7,7 @@ const utils_1 = require("./utils");
|
|
|
7
7
|
/**
|
|
8
8
|
* Create vuepress customized markdown-it instance
|
|
9
9
|
*/
|
|
10
|
-
const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractHeaders, extractTitle, hoistTags, importCode, links, toc, ...markdownItOptions } = {}) => {
|
|
10
|
+
const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractHeaders, extractTitle, hoistTags, importCode, links, slugify = utils_1.vuepressSlugify, toc, ...markdownItOptions } = {}) => {
|
|
11
11
|
// create raw markdown-it instance
|
|
12
12
|
const md = MarkdownIt({
|
|
13
13
|
...markdownItOptions,
|
|
@@ -25,7 +25,7 @@ const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractH
|
|
|
25
25
|
if (anchor !== false) {
|
|
26
26
|
md.use(plugins_1.anchorPlugin, {
|
|
27
27
|
level: [1, 2, 3, 4, 5, 6],
|
|
28
|
-
slugify
|
|
28
|
+
slugify,
|
|
29
29
|
permalink: plugins_1.anchorPlugin.permalink.ariaHidden({
|
|
30
30
|
class: 'header-anchor',
|
|
31
31
|
symbol: '#',
|
|
@@ -39,7 +39,7 @@ const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractH
|
|
|
39
39
|
if (toc !== false) {
|
|
40
40
|
md.use(plugins_1.tocPlugin, {
|
|
41
41
|
level: [2, 3],
|
|
42
|
-
slugify
|
|
42
|
+
slugify,
|
|
43
43
|
linkTag: 'RouterLink',
|
|
44
44
|
...toc,
|
|
45
45
|
});
|
|
@@ -48,7 +48,7 @@ const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractH
|
|
|
48
48
|
if (extractHeaders !== false) {
|
|
49
49
|
md.use(plugins_1.extractHeadersPlugin, {
|
|
50
50
|
level: [2, 3],
|
|
51
|
-
slugify
|
|
51
|
+
slugify,
|
|
52
52
|
...extractHeaders,
|
|
53
53
|
});
|
|
54
54
|
}
|
|
@@ -21,7 +21,16 @@ const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
|
|
|
21
21
|
// wrap raw html renderer rule
|
|
22
22
|
const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
|
|
23
23
|
// replace the original link with resolved link
|
|
24
|
-
tokens[idx].content = tokens[idx].content
|
|
24
|
+
tokens[idx].content = tokens[idx].content
|
|
25
|
+
// handle src
|
|
26
|
+
.replace(/(<img\b.*?src=")([^"]*)(")/gs, (_, prefix, src, suffix) => `${prefix}${(0, resolveLink_1.resolveLink)(src.trim(), relativePathPrefix, env)}${suffix}`)
|
|
27
|
+
// handle srcset
|
|
28
|
+
.replace(/(<img\b.*?srcset=")([^"]*)(")/gs, (_, prefix, srcset, suffix) => `${prefix}${srcset
|
|
29
|
+
.split(',')
|
|
30
|
+
.map((item) => item
|
|
31
|
+
.trim()
|
|
32
|
+
.replace(/^([^ ]*?)([ \n].*)?$/, (_, url, descriptor = '') => `${(0, resolveLink_1.resolveLink)(url.trim(), relativePathPrefix, env)}${descriptor.replace(/[ \n]+/g, ' ').trimEnd()}`))
|
|
33
|
+
.join(', ')}${suffix}`);
|
|
25
34
|
return rawHtmlRule(tokens, idx, options, env, self);
|
|
26
35
|
};
|
|
27
36
|
const rawHtmlBlockRule = md.renderer.rules.html_block;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginWithOptions } from 'markdown-it';
|
|
2
|
+
import type { MarkdownSlugifyFunction } from '../types';
|
|
2
3
|
export interface ExtractHeadersPluginOptions {
|
|
3
4
|
/**
|
|
4
5
|
* Heading level that going to be extracted to the `env`
|
|
@@ -13,7 +14,7 @@ export interface ExtractHeadersPluginOptions {
|
|
|
13
14
|
* Should use the same slugify function with markdown-it-anchor
|
|
14
15
|
* to ensure the link is matched
|
|
15
16
|
*/
|
|
16
|
-
slugify?:
|
|
17
|
+
slugify?: MarkdownSlugifyFunction;
|
|
17
18
|
/**
|
|
18
19
|
* A function for formatting headers
|
|
19
20
|
*/
|
|
@@ -7,7 +7,7 @@ const utils_1 = require("../utils");
|
|
|
7
7
|
*
|
|
8
8
|
* Would be used for generating sidebar nav and toc
|
|
9
9
|
*/
|
|
10
|
-
const extractHeadersPlugin = (md, { level = [2, 3], slugify = utils_1.
|
|
10
|
+
const extractHeadersPlugin = (md, { level = [2, 3], slugify = utils_1.vuepressSlugify, format, } = {}) => {
|
|
11
11
|
let headers;
|
|
12
12
|
// push the rule to the end of the chain
|
|
13
13
|
// resolve headers from the parsed tokens
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginWithOptions } from 'markdown-it';
|
|
2
|
+
import type { MarkdownSlugifyFunction } from '../../types';
|
|
2
3
|
export interface TocPluginOptions {
|
|
3
4
|
/**
|
|
4
5
|
* The pattern serving as the TOC placeholder in your markdown
|
|
@@ -10,7 +11,7 @@ export interface TocPluginOptions {
|
|
|
10
11
|
* Should use the same slugify function with markdown-it-anchor
|
|
11
12
|
* to ensure the link is matched
|
|
12
13
|
*/
|
|
13
|
-
slugify?:
|
|
14
|
+
slugify?: MarkdownSlugifyFunction;
|
|
14
15
|
/**
|
|
15
16
|
* A function for formatting headers
|
|
16
17
|
*/
|
|
@@ -15,7 +15,7 @@ const createTocBlockRule_1 = require("./createTocBlockRule");
|
|
|
15
15
|
*
|
|
16
16
|
* @see https://github.com/nagaozen/markdown-it-toc-done-right
|
|
17
17
|
*/
|
|
18
|
-
const tocPlugin = (md, { pattern = /^\[\[toc\]\]$/i, slugify = utils_1.
|
|
18
|
+
const tocPlugin = (md, { pattern = /^\[\[toc\]\]$/i, slugify = utils_1.vuepressSlugify, format, level = [2, 3], containerTag = 'nav', containerClass = 'table-of-contents', listTag = 'ul', listClass = '', itemClass = '', linkTag = 'a', linkClass = '', } = {}) => {
|
|
19
19
|
let headers;
|
|
20
20
|
// push the rule to the end of the chain
|
|
21
21
|
// resolve headers from the parsed tokens
|
package/lib/types.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface MarkdownOptions extends MarkdownIt.Options {
|
|
|
13
13
|
hoistTags?: false | HoistTagsPluginOptions;
|
|
14
14
|
importCode?: false | ImportCodePluginOptions;
|
|
15
15
|
links?: false | LinksPluginOptions;
|
|
16
|
+
slugify?: MarkdownSlugifyFunction;
|
|
16
17
|
toc?: false | TocPluginOptions;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
@@ -74,3 +75,7 @@ export interface MarkdownEnv {
|
|
|
74
75
|
*/
|
|
75
76
|
title?: string;
|
|
76
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Type of `slugify` function
|
|
80
|
+
*/
|
|
81
|
+
export declare type MarkdownSlugifyFunction = (str: string) => string;
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -16,4 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./resolveHeadersFromTokens"), exports);
|
|
18
18
|
__exportStar(require("./resolveTitleFromToken"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./vuepressSlugify"), exports);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.vuepressSlugify = void 0;
|
|
4
4
|
// eslint-disable-next-line no-control-regex
|
|
5
5
|
const rControl = /[\u0000-\u001f]/g;
|
|
6
6
|
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g;
|
|
7
7
|
const rCombining = /[\u0300-\u036F]/g;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Default slugify function of vuepress
|
|
10
|
+
*/
|
|
11
|
+
const vuepressSlugify = (str) => str
|
|
9
12
|
.normalize('NFKD')
|
|
10
13
|
// Remove accents
|
|
11
14
|
.replace(rCombining, '')
|
|
@@ -21,4 +24,4 @@ const slugify = (str) => str
|
|
|
21
24
|
.replace(/^(\d)/, '_$1')
|
|
22
25
|
// lowercase
|
|
23
26
|
.toLowerCase();
|
|
24
|
-
exports.
|
|
27
|
+
exports.vuepressSlugify = vuepressSlugify;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/markdown",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.48",
|
|
4
4
|
"description": "Markdown package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@types/markdown-it": "^12.2.3",
|
|
26
|
-
"@vuepress/shared": "2.0.0-beta.
|
|
27
|
-
"@vuepress/utils": "2.0.0-beta.
|
|
26
|
+
"@vuepress/shared": "2.0.0-beta.48",
|
|
27
|
+
"@vuepress/utils": "2.0.0-beta.48",
|
|
28
28
|
"markdown-it": "^13.0.1",
|
|
29
|
-
"markdown-it-anchor": "^8.6.
|
|
29
|
+
"markdown-it-anchor": "^8.6.4",
|
|
30
30
|
"markdown-it-emoji": "^2.0.2",
|
|
31
31
|
"mdurl": "^1.0.1"
|
|
32
32
|
},
|
package/lib/utils/slugify.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const slugify: (str: string) => string;
|