kueblc / LDT

Lightweight in browser syntax highlighting
https://kueblc.github.io/LDT/
159 stars 17 forks source link

Match exactly the beginning of a line (Writing a Markdown highlighter) #13

Closed IngwiePhoenix closed 8 years ago

IngwiePhoenix commented 9 years ago

As indicated in the title, I am trying to create a Parser ruleset to highlight Markdown.

So far, I can perfectly match the inline stuff for bold and italic text as well as other stuff. However, I am unable to match headers, lists and proper code fences.

It would be nice if you could help me out there! This is my Parser so far:

        var rules = {
            list: /[-\*]\s[^\n\r]*\n?/,
            header: /#\s[^\n\r]*\n?/,
            "bold fix": /[\*\_]{2}[^\_\*\r\n]*[\*\_]{2}?/,
            "italic fix": /[\_\*][^\_\*\r\n]*[\_\*]?/,
            strike: /-[^-]*-?/,
            code: /```[\r\n].*[\r\n]```/,
            quote: />[^\r\n]*\n?/,
            mention: /@[^@\r\n]([a-z0-9\-\._]*)?/,
            url: require("url-regex")(), // Dink! :)
            ip: require("ip-regex")(),
            email: require("email-regex")(),
            hashtag: /(#[a-z0-9][a-z0-9\-_]*)/,
            whitespace: /\s+/,
            other: /\S+/
        };

Kind regards, Ingwie.

IngwiePhoenix commented 8 years ago

I managed to use miniMarkdown

All is going well now :)