Skip to content
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

Links default to target="_blank" ? #13

Open
reinoldus opened this issue Oct 4, 2019 · 4 comments
Open

Links default to target="_blank" ? #13

reinoldus opened this issue Oct 4, 2019 · 4 comments

Comments

@reinoldus
Copy link

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

@Spanri
Copy link

Spanri commented May 10, 2020

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

@SampsonCrowley
Copy link

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

@madebycaliper
Copy link

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!

@304NotModified
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants