mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-03 20:48:55 +08:00
Migrate relative links to absolute in embedded markdown (#867)
Signed-off-by: Martin Mihálek <aenniw@gmail.com>
This commit is contained in:
parent
b53ea1e304
commit
291c99bc38
@ -19,6 +19,10 @@ export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) =>
|
||||
|
||||
href = router.toURL(href, null, router.getCurrentPath());
|
||||
} else {
|
||||
if (!isAbsolutePath(href) && href.startsWith('./')) {
|
||||
href =
|
||||
document.URL.replace(/\/(?!.*\/).*/, '/').replace('#/./', '') + href;
|
||||
}
|
||||
attrs.push(href.indexOf('mailto:') === 0 ? '' : `target="${linkTarget}"`);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,23 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
|
||||
let embedToken;
|
||||
if (text) {
|
||||
if (token.embed.type === 'markdown') {
|
||||
let path = token.embed.url.split('/');
|
||||
path.pop();
|
||||
path = path.join('/');
|
||||
// Resolves relative links to absolute
|
||||
text = text.replace(/\[([^[\]]+)\]\(([^)]+)\)/g, x => {
|
||||
const linkBeginIndex = x.indexOf('(');
|
||||
if (x.substring(linkBeginIndex).startsWith('(.')) {
|
||||
return (
|
||||
x.substring(0, linkBeginIndex) +
|
||||
`(${window.location.protocol}//${window.location.host}${path}/` +
|
||||
x.substring(linkBeginIndex + 1, x.length - 1) +
|
||||
')'
|
||||
);
|
||||
}
|
||||
return x;
|
||||
});
|
||||
|
||||
embedToken = compile.lexer(text);
|
||||
} else if (token.embed.type === 'code') {
|
||||
if (token.embed.fragment) {
|
||||
|
Loading…
Reference in New Issue
Block a user