vue-simple-markdown
vue-simple-markdown copied to clipboard
Links default to target="_blank" ?
All links (even internal) seem to default to target="_blank", which is not nice for internal links.
I do not see any option to configure that
You can override the rules (i use typescript). I took this function from "src/rules/link.js" in this project.
<vue-simple-markdown :source="component" :postrender="postRender" />
methods: {
postRender(source: string) {
const LINK_REGEX = /\[(.+?)\]\(((?:(http[s]?|ftp):\/{2})?[\w\/\-+?#=.:!%&]+)\)/g;
return source.replace(LINK_REGEX, "<a href="$2">$1</a>");
}
}
@Spanri postrender happens after the links have already been converted to the target blank links
Has anyone solved this issue? I've tried writing a regex in the :prerender
function but its just displaying the output as plain text, not as a rendered HTML tag. Would love target="_self"
as an option!
I think it's a better idea to parse and edit the HTML with the DOM API.
E.g.
function removeTargetBlank(htmldata) {
var container = document.createElement('div');
container.innerHTML = htmldata;
Array.from(container.querySelectorAll('a[target="_blank"]')).forEach(link => link.removeAttribute('target'));
return container.innerHTML;
}