如何使用 markdown 集获取 markitup 编辑器以发送 markdown 而不是 html

发布于 2024-11-11 16:03:35 字数 1089 浏览 4 评论 0原文

我正在使用 Rails 并有一个 markItUp 编辑器,使用 Markdown 自定义集。我唯一不明白的是如何让它提交原始 Markdown 而不是转换后的 html。我计划存储这两种格式,但我还没有找到任何能够将 html 解析回 markdown 的东西。我自定义了 markdown 集 set.js,因为我们不需要整套格式选项。这里:

myMarkdownSettings = {
previewParserPath:  '',
onShiftEnter:       {keepDefault: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...' }
    ]
}

这是标记元素出现的页面的 onready 代码:

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

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

这可行,但它以 html 形式提交。我试图使用 wmd,因为有一个输出选项可以按原样维护 markdown 文本,但无法让它运行。谢谢。

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:       {keepDefault: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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏佲洛 2024-11-18 16:03:35

假设文本区域包含 markdown 格式的文本,您应该能够在使用 $('.editable').text() 提交表单之前获取内容,并将其存储在另一个隐藏字段中,但您必须确保得到在标记转换内容之前将其转换为内容。

如果你真的只是想存储 markdown,你最好不要使用 markitup,而只是将其作为简单的 markdown 保留在文本视图中,然后自己将其转换为 html 以使用可用的库之一(如 rdiscount 等)进行显示。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文