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
relative baseUrl #1526
relative baseUrl #1526
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://markedjs-git-fork-uzitech-baseurl-null.markedjs.now.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK from a regex perspective.
Hello, is there a way to turn off this behaviour via options? I have a lot of relative links in my markdown files, which come from the external (not the one in which marked is used) website. |
@EdwardEisenhauer baseUrl is |
after setting marked.setOptions({
baseUrl: 'https://external.domain/some/path/',
}); when using: marked('[some_link](/i/want/to/go/there)'); I receive: "<p><a href=\"https://external.domain/i/want/to/go/there\">some_link</a></p>" when I would like to get: "<p><a href=\"https://external.domain/some/path/i/want/to/go/there\">some_link</a></p>" as if calling: marked('[some_link](i/want/to/go/there)'); I would like to be able to turn off relative link generation if there is a leading slash. |
@EdwardEisenhauer your best bet would be to walk the tokens and update the href marked.use({
walkTokens(token) {
if (token.type === 'link') {
token.href = 'https://external.domain/some/path' + token.href;
}
}
});
marked('[some_link](/i/want/to/go/there)'); |
@UziTech I modified it to: if (token.type === 'link' && token.href[0] === '/') {
token.href = 'https://external.domain/some/path' + token.href;
} And now it works as expected (as I have some links to the external webpages too). Thanks for help! |
relative baseUrl
Marked version: master
Description
Allow
baseUrl
option to be a relative url.Expectation
Result
What was attempted
Contributor
Committer
In most cases, this should be a different person than the contributor.