@vuepress/markdown 2.0.0-beta.18 → 2.0.0-beta.22

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.js CHANGED
@@ -26,9 +26,12 @@ const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractH
26
26
  md.use(plugins_1.anchorPlugin, {
27
27
  level: [1, 2, 3, 4, 5, 6],
28
28
  slugify: utils_1.slugify,
29
- permalink: true,
30
- permalinkBefore: true,
31
- permalinkSymbol: '#',
29
+ permalink: plugins_1.anchorPlugin.permalink.ariaHidden({
30
+ class: 'header-anchor',
31
+ symbol: '#',
32
+ space: true,
33
+ placement: 'before',
34
+ }),
32
35
  ...anchor,
33
36
  });
34
37
  }
@@ -1,62 +1,4 @@
1
- import type { PluginWithOptions } from 'markdown-it';
2
- import State = require('markdown-it/lib/rules_core/state_core');
3
- import Token = require('markdown-it/lib/token');
4
- /**
5
- * Options for markdown-it-anchor
6
- *
7
- * @see https://github.com/valeriangalliat/markdown-it-anchor
8
- */
9
- export interface AnchorPluginOptions {
10
- /**
11
- * Minimum level to apply anchors on or array of selected levels
12
- *
13
- * @default 1
14
- */
15
- level?: number | number[];
16
- /**
17
- * A custom slugification function
18
- */
19
- slugify?: (str: string) => string;
20
- /**
21
- * Whether to add permalinks next to titles
22
- *
23
- * @default false
24
- */
25
- permalink?: boolean;
26
- /**
27
- * A custom permalink rendering function
28
- */
29
- renderPermalink?: (slug: string, opts: AnchorPluginOptions, state: State, tokenIndex: number) => void;
30
- /**
31
- * The class of the permalink anchor
32
- */
33
- permalinkClass?: string;
34
- /**
35
- * Place space between the header text and the permalink anchor
36
- */
37
- permalinkSpace?: boolean;
38
- /**
39
- * The symbol in the permalink anchor
40
- */
41
- permalinkSymbol?: string;
42
- /**
43
- * Place the permalink before the title
44
- */
45
- permalinkBefore?: boolean;
46
- /**
47
- * A custom permalink `href` rendering function
48
- */
49
- permalinkHref?: (slug: string, state: State) => string;
50
- /**
51
- * A custom permalink attributes rendering function
52
- */
53
- permalinkAttrs?: (slug: string, state: State) => Record<string, string>;
54
- /**
55
- * Called with token and info after rendering
56
- */
57
- callback?: (token: Token, opts: {
58
- slug: string;
59
- title: string;
60
- }) => void;
61
- }
62
- export declare const anchorPlugin: PluginWithOptions<AnchorPluginOptions>;
1
+ import * as anchorPlugin from 'markdown-it-anchor';
2
+ import type { AnchorOptions } from 'markdown-it-anchor';
3
+ export declare type AnchorPluginOptions = AnchorOptions;
4
+ export { anchorPlugin };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.anchorPlugin = void 0;
4
- const rawAnchorPlugin = require("markdown-it-anchor");
5
- exports.anchorPlugin = rawAnchorPlugin;
4
+ const anchorPlugin = require("markdown-it-anchor");
5
+ exports.anchorPlugin = anchorPlugin;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assetsPlugin = void 0;
4
+ const resolveLink_1 = require("./resolveLink");
5
+ /**
6
+ * Plugin to handle assets links
7
+ */
8
+ const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
9
+ // wrap raw image renderer rule
10
+ const rawImageRule = md.renderer.rules.image;
11
+ md.renderer.rules.image = (tokens, idx, options, env, self) => {
12
+ const token = tokens[idx];
13
+ // get the image link
14
+ const link = token.attrGet('src');
15
+ if (link) {
16
+ // replace the original link with resolved link
17
+ token.attrSet('src', resolveLink_1.resolveLink(link, relativePathPrefix, env));
18
+ }
19
+ return rawImageRule(tokens, idx, options, env, self);
20
+ };
21
+ // wrap raw html renderer rule
22
+ const createHtmlRule = (rawHtmlRule) => (tokens, idx, options, env, self) => {
23
+ // replace the original link with resolved link
24
+ tokens[idx].content = tokens[idx].content.replace(/^( *<img\b.*src=")([^"]*)(")/s, (_, prefix, link, suffix) => `${prefix}${resolveLink_1.resolveLink(link, relativePathPrefix, env)}${suffix}`);
25
+ return rawHtmlRule(tokens, idx, options, env, self);
26
+ };
27
+ const rawHtmlBlockRule = md.renderer.rules.html_block;
28
+ const rawHtmlInlineRule = md.renderer.rules.html_inline;
29
+ md.renderer.rules.html_block = createHtmlRule(rawHtmlBlockRule);
30
+ md.renderer.rules.html_inline = createHtmlRule(rawHtmlInlineRule);
31
+ };
32
+ exports.assetsPlugin = assetsPlugin;
@@ -0,0 +1,2 @@
1
+ export * from './assetsPlugin';
2
+ export * from './resolveLink';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./assetsPlugin"), exports);
14
+ __exportStar(require("./resolveLink"), exports);
@@ -0,0 +1,2 @@
1
+ import type { MarkdownEnv } from '../../types';
2
+ export declare const resolveLink: (link: string, relativePathPrefix: string, env: MarkdownEnv) => string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveLink = void 0;
4
+ const utils_1 = require("@vuepress/utils");
5
+ const mdurl_1 = require("mdurl");
6
+ const resolveLink = (link, relativePathPrefix, env) => {
7
+ // decode link to ensure bundler can find the file correctly
8
+ let resolvedLink = mdurl_1.decode(link);
9
+ // if the link is relative path, and the `env.filePathRelative` exists
10
+ // add `@source` alias to the link
11
+ if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
12
+ resolvedLink = `${relativePathPrefix}/${utils_1.path.join(utils_1.path.dirname(env.filePathRelative), resolvedLink)}`;
13
+ }
14
+ return resolvedLink;
15
+ };
16
+ exports.resolveLink = resolveLink;
@@ -12,7 +12,8 @@ const hoistTagsPlugin = (md, { customBlocks = [] } = {}) => {
12
12
  // hoist <script>, <style> and other user defined tags
13
13
  const hoistTags = Array.from(new Set(['script', 'style', ...customBlocks]));
14
14
  const hoistTagsRegexp = new RegExp(`^<(${hoistTags.join('|')})(?=(\\s|>|$))`, 'i');
15
- md.renderer.rules.html_block = (tokens, idx, _, env) => {
15
+ const rawRule = md.renderer.rules.html_block;
16
+ md.renderer.rules.html_block = (tokens, idx, options, env, self) => {
16
17
  const content = tokens[idx].content;
17
18
  const hoistedTags = env.hoistedTags || (env.hoistedTags = []);
18
19
  // record the hoisted tags to env and do not render them
@@ -20,7 +21,7 @@ const hoistTagsPlugin = (md, { customBlocks = [] } = {}) => {
20
21
  hoistedTags.push(content);
21
22
  return '';
22
23
  }
23
- return content;
24
+ return rawRule(tokens, idx, options, env, self);
24
25
  };
25
26
  };
26
27
  exports.hoistTagsPlugin = hoistTagsPlugin;
@@ -1,4 +1,3 @@
1
- export * from './parseEmoji';
2
1
  export * from './resolveHeadersFromTokens';
3
2
  export * from './resolveTitleFromToken';
4
3
  export * from './slugify';
@@ -10,7 +10,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./parseEmoji"), exports);
14
13
  __exportStar(require("./resolveHeadersFromTokens"), exports);
15
14
  __exportStar(require("./resolveTitleFromToken"), exports);
16
15
  __exportStar(require("./slugify"), exports);
@@ -18,7 +18,12 @@ const resolveTitleFromToken = (token, { allowHtml, escapeText, }) => {
18
18
  titleTokenTypes.push('html_inline');
19
19
  }
20
20
  // filter the token type to be included in the title
21
- const titleTokens = children.filter((item) => titleTokenTypes.includes(item.type));
21
+ const titleTokens = children.filter((item) => {
22
+ var _a;
23
+ return titleTokenTypes.includes(item.type) &&
24
+ // filter permalink symbol that generated by markdown-it-anchor
25
+ !((_a = item.meta) === null || _a === void 0 ? void 0 : _a.isPermalinkSymbol);
26
+ });
22
27
  // get title from tokens
23
28
  return titleTokens
24
29
  .reduce((result, item) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/markdown",
3
- "version": "2.0.0-beta.18",
3
+ "version": "2.0.0-beta.22",
4
4
  "description": "Markdown package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -27,15 +27,15 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@types/markdown-it": "^12.0.2",
30
- "@vuepress/shared": "2.0.0-beta.18",
31
- "@vuepress/utils": "2.0.0-beta.18",
32
- "markdown-it": "^12.0.6",
33
- "markdown-it-anchor": "^7.1.0",
30
+ "@vuepress/shared": "2.0.0-beta.21",
31
+ "@vuepress/utils": "2.0.0-beta.21",
32
+ "markdown-it": "^12.1.0",
33
+ "markdown-it-anchor": "^8.1.0",
34
34
  "markdown-it-emoji": "^2.0.0",
35
35
  "mdurl": "^1.0.1"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "b74a98f3ebe57b5edf3443bf747834a767e67796"
40
+ "gitHead": "8db8d235df8914c70c864ae3f3f66f93cfd1a457"
41
41
  }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assetsPlugin = void 0;
4
- const mdurl_1 = require("mdurl");
5
- const utils_1 = require("@vuepress/utils");
6
- /**
7
- * Plugin to handle assets links
8
- */
9
- const assetsPlugin = (md, { relativePathPrefix = '@source' } = {}) => {
10
- const rawRule = md.renderer.rules.image;
11
- md.renderer.rules.image = (tokens, idx, options, env, self) => {
12
- const token = tokens[idx];
13
- // get the image link
14
- const link = token.attrGet('src');
15
- if (!link) {
16
- return rawRule(tokens, idx, options, env, self);
17
- }
18
- // decode link to ensure bundler can find the file correctly
19
- let resolvedLink = mdurl_1.decode(link);
20
- // if the link is relative path, and the `env.filePathRelative` exists
21
- // add `@source` alias to the link
22
- if (/^\.{1,2}\//.test(link) && env.filePathRelative) {
23
- resolvedLink = `${relativePathPrefix}/${utils_1.path.join(utils_1.path.dirname(env.filePathRelative), resolvedLink)}`;
24
- }
25
- // replace the original link with resolved link
26
- token.attrSet('src', resolvedLink);
27
- return rawRule(tokens, idx, options, env, self);
28
- };
29
- };
30
- exports.assetsPlugin = assetsPlugin;
@@ -1 +0,0 @@
1
- export declare const parseEmoji: (str: string) => string;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseEmoji = void 0;
4
- const emojiData = require("markdown-it-emoji/lib/data/full.json");
5
- const parseEmoji = (str) => str.replace(/:(.+?):/g, (placeholder, key) => emojiData[key] || placeholder);
6
- exports.parseEmoji = parseEmoji;