From b6643a5f2c844827a8f3416f908e2064906b5b82 Mon Sep 17 00:00:00 2001 From: i544693 <369491420@qq.com> Date: Sat, 3 Sep 2022 19:22:05 +0800 Subject: [PATCH] enhance: absolute path support config. --- src/core/render/compiler/image.js | 2 +- src/core/router/util.js | 6 +++++- test/integration/render.test.js | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/render/compiler/image.js b/src/core/render/compiler/image.js index 982e5e55e..f6f820911 100644 --- a/src/core/render/compiler/image.js +++ b/src/core/render/compiler/image.js @@ -34,7 +34,7 @@ export const imageCompiler = ({ renderer, contentBase, router }) => attrs.push(`id="${config.id}"`); } - if (!isAbsolutePath(href)) { + if (!isAbsolutePath(href, config.absolute)) { url = getPath(contentBase, getParentPath(router.getCurrentPath()), href); } diff --git a/src/core/router/util.js b/src/core/router/util.js index b4a85d89e..6cf92df2b 100644 --- a/src/core/router/util.js +++ b/src/core/router/util.js @@ -40,7 +40,11 @@ export function stringifyQuery(obj, ignores = []) { return qs.length ? `?${qs.join('&')}` : ''; } -export const isAbsolutePath = cached(path => { +export const isAbsolutePath = (path = '', absoluteConfig = false) => { + return !!absoluteConfig || absolutePath(path); +}; + +const absolutePath = cached(path => { return /(:|(\/{2}))/g.test(path); }); diff --git a/test/integration/render.test.js b/test/integration/render.test.js index f1335a064..b8889704c 100644 --- a/test/integration/render.test.js +++ b/test/integration/render.test.js @@ -128,6 +128,14 @@ describe('render', function () { ); }); + test('absolute', async function () { + const output = window.marked("![alt text](/imageUrl ':absolute')"); + + expect(output).toMatchInlineSnapshot( + `"

\\"alt

"` + ); + }); + test('no-zoom', async function () { const output = window.marked("![alt text](http://imageUrl ':no-zoom')");