jonschlinkert / remarkable

Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one. Gulp and metalsmith plugins available. Used by Facebook, Docusaurus and many others! Use https://github.com/breakdance/breakdance for HTML-to-markdown conversion. Use https://github.com/jonschlinkert/markdown-toc to generate a table of contents.
https://jonschlinkert.github.io/remarkable/demo/
MIT License
5.75k stars 373 forks source link

linkify: allows for URL text shortening #431

Open dresende opened 1 year ago

dresende commented 1 year ago

This allows to change replaceFn in Autolinker to something like this:

replaceFn : function (match) {
    switch (match.getType()) {
        case 'url':
            // here's the change..
            let text = match.matchedText;

            if (text.length > 25) {
                text = text.substr(0, 23) + "..";
            }

            links.push({
                text: text,
                url: match.getUrl()
            });
            break;
        case 'email':
            links.push({
                text: match.matchedText,
                // normalize email protocol
                url: 'mailto:' + match.getEmail().replace(/^mailto:/i, '')
            });
            break;
    }
    return false;
}