@vuepress/markdown
Advanced tools
Comparing version 2.0.0-beta.15 to 2.0.0-beta.18
@@ -5,2 +5,2 @@ import type { Markdown, MarkdownOptions } from './types'; | ||
*/ | ||
export declare const createMarkdown: ({ anchor, assets, code, customComponent, emoji, extractHeaders, hoistTags, importCode, links, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown; | ||
export declare const createMarkdown: ({ anchor, assets, code, customComponent, emoji, extractHeaders, extractTitle, hoistTags, importCode, links, toc, ...markdownItOptions }?: MarkdownOptions) => Markdown; |
@@ -10,3 +10,3 @@ "use strict"; | ||
*/ | ||
const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractHeaders, hoistTags, importCode, links, toc, ...markdownItOptions } = {}) => { | ||
const createMarkdown = ({ anchor, assets, code, customComponent, emoji, extractHeaders, extractTitle, hoistTags, importCode, links, toc, ...markdownItOptions } = {}) => { | ||
// create raw markdown-it instance | ||
@@ -21,3 +21,3 @@ const md = MarkdownIt({ | ||
// the order to use them is important | ||
// parse emoji (before anchor and toc plugin) | ||
// parse emoji | ||
if (emoji !== false) { | ||
@@ -37,3 +37,3 @@ md.use(plugins_1.emojiPlugin, emoji); | ||
} | ||
// allow toc syntax (after anchor plugin) | ||
// allow toc syntax | ||
if (toc !== false) { | ||
@@ -47,3 +47,3 @@ md.use(plugins_1.tocPlugin, { | ||
} | ||
// extract headers into env (after anchor plugin) | ||
// extract headers into env | ||
if (extractHeaders !== false) { | ||
@@ -56,2 +56,6 @@ md.use(plugins_1.extractHeadersPlugin, { | ||
} | ||
// extract title into env | ||
if (extractTitle !== false) { | ||
md.use(plugins_1.extractTitlePlugin); | ||
} | ||
// ===================================================== | ||
@@ -58,0 +62,0 @@ // following plugins modify or replace the rule in place |
@@ -28,3 +28,3 @@ "use strict"; | ||
const result = render(src, env); | ||
env.headers = headers !== null && headers !== void 0 ? headers : []; | ||
env.headers = headers; | ||
return result; | ||
@@ -31,0 +31,0 @@ }; |
@@ -7,2 +7,3 @@ export * from './anchorPlugin'; | ||
export * from './extractHeadersPlugin'; | ||
export * from './extractTitlePlugin'; | ||
export * from './hoistTagsPlugin'; | ||
@@ -9,0 +10,0 @@ export * from './importCodePlugin'; |
@@ -19,2 +19,3 @@ "use strict"; | ||
__exportStar(require("./extractHeadersPlugin"), exports); | ||
__exportStar(require("./extractTitlePlugin"), exports); | ||
__exportStar(require("./hoistTagsPlugin"), exports); | ||
@@ -21,0 +22,0 @@ __exportStar(require("./importCodePlugin"), exports); |
@@ -12,2 +12,3 @@ import * as MarkdownIt from 'markdown-it'; | ||
extractHeaders?: false | ExtractHeadersPluginOptions; | ||
extractTitle?: false; | ||
hoistTags?: false | HoistTagsPluginOptions; | ||
@@ -72,2 +73,6 @@ importCode?: false | ImportCodePluginOptions; | ||
links?: MarkdownLink[]; | ||
/** | ||
* Title that extracted by extractTitlePlugin | ||
*/ | ||
title?: string; | ||
} |
export * from './parseEmoji'; | ||
export * from './resolveHeadersFromTokens'; | ||
export * from './resolveTitleFromToken'; | ||
export * from './slugify'; |
@@ -15,2 +15,3 @@ "use strict"; | ||
__exportStar(require("./resolveHeadersFromTokens"), exports); | ||
__exportStar(require("./resolveTitleFromToken"), exports); | ||
__exportStar(require("./slugify"), exports); |
import * as Token from 'markdown-it/lib/token'; | ||
import { MarkdownHeader } from '../types'; | ||
import type { MarkdownHeader } from '../types'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Resolve headers from markdown-it tokens |
@@ -5,2 +5,3 @@ "use strict"; | ||
const shared_1 = require("@vuepress/shared"); | ||
const resolveTitleFromToken_1 = require("./resolveTitleFromToken"); | ||
/** | ||
@@ -29,5 +30,5 @@ * Resolve headers from markdown-it tokens | ||
tokens.forEach((_, idx) => { | ||
var _a, _b; | ||
var _a; | ||
const token = tokens[idx]; | ||
// if the token type is not matched, skip | ||
// if the token type does not match, skip | ||
if ((token === null || token === void 0 ? void 0 : token.type) !== 'heading_open') { | ||
@@ -48,29 +49,9 @@ return; | ||
} | ||
// children of the next token contains the parsed result of the heading title | ||
const nextTokenChildren = (_a = nextToken.children) !== null && _a !== void 0 ? _a : []; | ||
// filter tokens for generating heading title | ||
// 'text' and 'code_inline' should be escaped to avoid being treated as html | ||
// 'emoji' and 'html_inline' should be used directly | ||
const titleTokenTypes = ['text', 'emoji', 'code_inline']; | ||
// include 'html_inline' or not | ||
if (allowHtml) { | ||
titleTokenTypes.push('html_inline'); | ||
} | ||
const titleTokens = nextTokenChildren.filter((item) => titleTokenTypes.includes(item.type)); | ||
// get title from tokens | ||
const title = titleTokens | ||
.reduce((result, item) => { | ||
if (escapeText) { | ||
// escape the content of 'code_inline' and 'text' | ||
if (item.type === 'code_inline' || item.type === 'text') { | ||
return `${result}${shared_1.htmlEscape(item.content)}`; | ||
} | ||
} | ||
// keep the content of 'emoji' and 'html_inline' | ||
return `${result}${item.content}`; | ||
}, '') | ||
.trim(); | ||
const title = resolveTitleFromToken_1.resolveTitleFromToken(nextToken, { | ||
allowHtml, | ||
escapeText, | ||
}); | ||
// the id of the heading anchor is the slugify result of markdown-it-anchor | ||
// if the id does not exist, slugify the title ourselves | ||
const slug = (_b = token.attrGet('id')) !== null && _b !== void 0 ? _b : slugify(title); | ||
const slug = (_a = token.attrGet('id')) !== null && _a !== void 0 ? _a : slugify(title); | ||
// push the header to tree | ||
@@ -77,0 +58,0 @@ push({ |
{ | ||
"name": "@vuepress/markdown", | ||
"version": "2.0.0-beta.15", | ||
"version": "2.0.0-beta.18", | ||
"description": "Markdown package of VuePress", | ||
@@ -29,5 +29,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@types/markdown-it": "^12.0.1", | ||
"@vuepress/shared": "2.0.0-beta.7", | ||
"@vuepress/utils": "2.0.0-beta.15", | ||
"@types/markdown-it": "^12.0.2", | ||
"@vuepress/shared": "2.0.0-beta.18", | ||
"@vuepress/utils": "2.0.0-beta.18", | ||
"markdown-it": "^12.0.6", | ||
@@ -41,3 +41,3 @@ "markdown-it-anchor": "^7.1.0", | ||
}, | ||
"gitHead": "b796eac6cc6379c996ac576e10d5bf46e33cfb99" | ||
"gitHead": "b74a98f3ebe57b5edf3443bf747834a767e67796" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84
1965
71666
+ Added@vuepress/shared@2.0.0-beta.18(transitive)
+ Added@vuepress/utils@2.0.0-beta.18(transitive)
- Removed@vuepress/shared@2.0.0-beta.7(transitive)
- Removed@vuepress/utils@2.0.0-beta.15(transitive)
Updated@types/markdown-it@^12.0.2