开发者

How to get markitup editor, using markdown set, to send markdown instead of html

开发者 https://www.devze.com 2023-03-10 11:40 出处:网络
I\'m using rails and have a markItUp editor in place, using the Markdown custom set. The only thing I can\'t figure out is how to get it to submit raw Markdown instead of converted html. I plan on sto

I'm using rails and have a markItUp editor in place, using the Markdown custom set. The only thing I can't figure out is how to get it to submit raw Markdown instead of converted html. I plan on storing both formats, but I haven't found anything capable of parsing html back to markdown. I've customized the markdown set set.js as we didn't want the entire set of formatting options. Here:

myMarkdownSettings = {
previewParserPath:  '',
onShiftEnter:       {keepD开发者_开发百科efault:false, openWith:'\n\n'},
markupSet: [    
    {name:'Bold', key:'B', openWith:'**', closeWith:'**'},
    {name:'Italic', key:'I', openWith:'_', closeWith:'_'},
    {name:'Bulleted List', openWith:'- ' },
    {name:'Link', key:'L', openWith:'[', closeWith:']([![Url:!:http://]!] "[![Title]!]")', placeHolder:'Your text to link here...' }
    ]
}

And here's the onready code for the page where the markitup elements appear:

$.editable.addInputType('markitup', {
    element : $.editable.types.textarea.element,
    plugin  : function(myMarkdownSettings, original) {
        $('textarea', this).markItUp(myMarkdownSettings);
    }
});

$('.editable').editable({type : 'markitup'});

This works, but it submits as html. I was trying to use wmd as there's an option for output which maintains the markdown text as is, but haven't been able to get that to fly. Thanks.


Assuming the textarea contains markdown formatted text, you should be able to grab the contents before form submit with $('.editable').text(), and store it in another hidden field, but you'd have to ensure that you get to the contents before markitup transforms them.

If you really just want to store markdown, you'd be better not to use markitup, and just leave it as simple markdown in a text view, then translate it yourself to html for display with one of the libraries available like rdiscount etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消