-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
9 changed files
with
79 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+8.52 KB
...loader/src/remark/transformLinks/__tests__/fixtures/static/staticAssetImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const escapeHtml = require('escape-html'); | ||
const toString = require('mdast-util-to-string'); | ||
|
||
/** | ||
* @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); | ||
} | ||
|
||
module.exports = { | ||
toValue, | ||
}; |