Skip to content

enhance: absolute path support config. #1873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/render/compiler/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion src/core/router/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
8 changes: 8 additions & 0 deletions test/integration/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ describe('render', function () {
);
});

test('absolute', async function () {
const output = window.marked("![alt text](/imageUrl ':absolute')");

expect(output).toMatchInlineSnapshot(
`"<p><img src=\\"/imageUrl\\" data-origin=\\"/imageUrl\\" alt=\\"alt text\\"></p>"`
);
});

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

Expand Down