diff --git a/src/core/render/compiler/link.js b/src/core/render/compiler/link.js index 91b292715..2c4b0cd79 100644 --- a/src/core/render/compiler/link.js +++ b/src/core/render/compiler/link.js @@ -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}"`); } diff --git a/src/core/render/embed.js b/src/core/render/embed.js index 2b5826f15..b64d11a8b 100644 --- a/src/core/render/embed.js +++ b/src/core/render/embed.js @@ -1,6 +1,6 @@ +import stripIndent from 'strip-indent'; import { get } from '../fetch/ajax'; import { merge } from '../util/core'; -import stripIndent from 'strip-indent'; const cached = {}; @@ -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) {