mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-29 17:07:08 +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
|
@ -12,11 +12,11 @@ exports[`transformImage plugin pathname protocol 1`] = `
|
|||
exports[`transformImage plugin transform md images to <img /> 1`] = `
|
||||
"
|
||||
|
||||
<img src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
|
||||
<img src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
|
||||
|
||||
<img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
|
||||
<img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
|
||||
|
||||
<img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} title={\\"Title\\"} /> <img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/fixtures/img.png\\").default} />
|
||||
<img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} title=\\"Title\\" /> <img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/fixtures/img.png\\").default} />
|
||||
|
||||
## Heading
|
||||
|
||||
|
@ -24,6 +24,6 @@ exports[`transformImage plugin transform md images to <img /> 1`] = `
|
|||

|
||||
\`\`\`
|
||||
|
||||
<img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
|
||||
<img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} />
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -9,6 +9,7 @@ const visit = require('unist-util-visit');
|
|||
const path = require('path');
|
||||
const url = require('url');
|
||||
const fs = require('fs-extra');
|
||||
const escapeHtml = require('escape-html');
|
||||
const {getFileLoaderUtils} = require('@docusaurus/core/lib/webpack/utils');
|
||||
const {posixPath} = require('@docusaurus/utils');
|
||||
|
||||
|
@ -18,11 +19,11 @@ const {
|
|||
|
||||
const createJSX = (node, pathUrl) => {
|
||||
node.type = 'jsx';
|
||||
node.value = `<img ${node.alt ? `alt={"${node.alt}"}` : ''} ${
|
||||
node.value = `<img ${node.alt ? `alt={"${node.alt}"} ` : ''}${
|
||||
node.url
|
||||
? `src={require("${inlineMarkdownImageFileLoader}${pathUrl}").default}`
|
||||
: ''
|
||||
} ${node.title ? `title={"${node.title}"}` : ''} />`;
|
||||
}${node.title ? ` title="${escapeHtml(node.title)}"` : ''} />`;
|
||||
|
||||
if (node.url) {
|
||||
delete node.url;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue