vue-simple-markdown icon indicating copy to clipboard operation
vue-simple-markdown copied to clipboard

Links default to target="_blank" ?

Open reinoldus opened this issue 5 years ago • 4 comments

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

reinoldus avatar Oct 04 '19 10:10 reinoldus

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 avatar May 10 '20 14:05 Spanri

@Spanri postrender happens after the links have already been converted to the target blank links

SampsonCrowley avatar Nov 29 '21 05:11 SampsonCrowley

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!

madebycaliper avatar Mar 15 '22 00:03 madebycaliper

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;
}

fiddle

304NotModified avatar Aug 16 '22 09:08 304NotModified