mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-25 23:17:06 +02:00
fix(v2): handle multiple asset links in one line properly (#3653)
* fix(v2): handle multiple asset links in one line properly * Fixes and improvements * Make TypeScript happy * Use relative path for image link * Add example for JSX element inside asset link
This commit is contained in:
parent
cf99862d29
commit
999ae5759c
9 changed files with 79 additions and 71 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
const toString = require('mdast-util-to-string');
|
||||
const visit = require('unist-util-visit');
|
||||
const escapeHtml = require('escape-html');
|
||||
const {toValue} = require('../utils');
|
||||
|
||||
/** @typedef {import('@docusaurus/types').MarkdownRightTableOfContents} TOC */
|
||||
/** @typedef {import('unist').Node} Node */
|
||||
|
@ -23,33 +23,6 @@ const escapeHtml = require('escape-html');
|
|||
* @property {StringValuedNode[]} children
|
||||
*/
|
||||
|
||||
// https://github.com/syntax-tree/mdast#heading
|
||||
/**
|
||||
* @param {StringValuedNode | undefined} node
|
||||
* @returns {string}
|
||||
*/
|
||||
function toValue(node) {
|
||||
if (node && node.type) {
|
||||
switch (node.type) {
|
||||
case 'text':
|
||||
return escapeHtml(node.value);
|
||||
case 'heading':
|
||||
return node.children.map(toValue).join('');
|
||||
case 'inlineCode':
|
||||
return `<code>${escapeHtml(node.value)}</code>`;
|
||||
case 'emphasis':
|
||||
return `<em>${node.children.map(toValue).join('')}</em>`;
|
||||
case 'strong':
|
||||
return `<strong>${node.children.map(toValue).join('')}</strong>`;
|
||||
case 'delete':
|
||||
return `<del>${node.children.map(toValue).join('')}</del>`;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
return toString(node);
|
||||
}
|
||||
|
||||
// Visit all headings. We `slug` all headings (to account for
|
||||
// duplicates), but only take h2 and h3 headings.
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue