简体   繁体   中英

Markdown to html javascript

I actually use TinyMCE (4.8.2) on my application for multiple fields. i automatize fields by json content from JIRA API. BUT... One of the field is already in Markdown from JIRA.

Then i have implemented plugin text_pattern from tinymce to configure the markdown symbol in javascipt. The problem still persist and the text will not changed to html without rewrite the text. I can't find issue, do you?

function initMCEexact(e) {
    tinymce.init({
        mode: "exact",
        theme: "modern",
        plugins: 'textpattern, advlist',
        selector: 'textarea',
        elements: e,
        textpattern_patterns: [
            {start: '_', end: '_', format: 'italic'},
            {start: '*', end: '*', format: 'bold'},
            {start: 'h1. ', format: 'h1'},
            {start: 'h2. ', format: 'h2'},
            {start: 'h3. ', format: 'h3'},
            {start: 'h4. ', format: 'h4'},
            {start: 'h5. ', format: 'h5'},
            {start: 'h6. ', format: 'h6'},
            {start: '# ', cmd: 'InsertOrderedList'},
            {start: '* ', cmd: 'InsertUnorderedList'},
            {start: '*', cmd: 'InsertUnorderedList'},
            {start: '//brb', replacement: 'Be Right Back'}
        ]
    });
}

Expecting translation of markdown to HTML automatically.

Really simple and possibly the smallest JavaScript MarkDown to HTML converter

Detailed list of JavaScript MarkDown converters

It might be better if you use a Markdown to HTML converter. I recommend ShowdownJS . Just add it to your project with <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.0/showdown.min.js"></script> , and then use this code:

var converter = new showdown.Converter();
var text = '# hello, markdown!';
var html = converter.makeHtml(text);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM