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:
Alexey Pyltsyn 2020-10-30 18:21:58 +03:00 committed by GitHub
parent cf99862d29
commit 999ae5759c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 71 deletions

View file

@ -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.
/**