miaolz123 / vue-markdown

A Powerful and Highspeed Markdown Parser for Vue
https://miaolz123.github.io/vue-markdown/
MIT License
1.89k stars 257 forks source link

Parse Rule Modifications? #41

Open mastastealth opened 6 years ago

mastastealth commented 6 years ago

I was wondering if there was a simple way to modify the rules. E.g.:

MeirionHughes commented 6 years ago

Is this possible with vue-markdown? I'd like to have customization (embedding) too.

Batophobia commented 4 years ago

You can do some simple stuff using postrender like so:

<vue-markdown :postrender="postRender">test @user</vue-markdown>

and in your script make a function that does whatever you want

function postRender(input: any){
      // format (space)@(word) in a span with "tag" class
      let output = input.replace(/(\s)#([a-z0-9-]+)/g,"$1<span class='user'>$2</span>");
      return output;
}

One thing to note is that this is after all the markdown is added, so where you think there is a \n newline, there might be a < from a br that was added