|
|
@ -6,15 +6,23 @@ const CODEPEN_PROTOCOL = 'codepen://'; |
|
|
|
const DEFAULT_LINK_TEXT = 'Try it on CodePen'; |
|
|
|
|
|
|
|
// TODO target="_blank"
|
|
|
|
module.exports = ({markdownAST}) => { |
|
|
|
module.exports = ({markdownAST}, {directory}) => { |
|
|
|
map(markdownAST, (node, index, parent) => { |
|
|
|
if (!directory.startsWith('/')) { |
|
|
|
directory = `/${directory}`; |
|
|
|
} |
|
|
|
|
|
|
|
if (!directory.endsWith('/')) { |
|
|
|
directory = `${directory}/`; |
|
|
|
} |
|
|
|
|
|
|
|
// eg convert
|
|
|
|
// from: [](codepen:introducing-jsx)
|
|
|
|
// to: <a href="/codepen/introducing-jsx" target="_blank">Try it on CodePen</a>
|
|
|
|
// to: <a href="/<directory>/introducing-jsx" target="_blank">Try it on CodePen</a>
|
|
|
|
// from: [Try the Hello World example on CodePen](codepen:hello-world)
|
|
|
|
// to: <a href="/codepen/hello-world" target="_blank">Try the Hello World example on CodePen</a>
|
|
|
|
// to: <a href="/<directory>/hello-world" target="_blank">Try the Hello World example on CodePen</a>
|
|
|
|
if (node.type === 'link' && node.url.startsWith(CODEPEN_PROTOCOL)) { |
|
|
|
const href = node.url.replace(CODEPEN_PROTOCOL, '/codepen/'); |
|
|
|
const href = node.url.replace(CODEPEN_PROTOCOL, `${directory}`); |
|
|
|
const text = |
|
|
|
node.children.length === 0 ? DEFAULT_LINK_TEXT : node.children[0].value; |
|
|
|
|
|
|
|