admin管理员组文章数量:1414621
I try use JS markdown editor tui-editor. For this i add on page div element with id "rawtext". Standart initializaion:
var editor = $('#rawtext').tuiEditor({
initialEditType: 'markdown',
previewStyle: 'vertical',
exts: ['colorSyntax']
});
Editor is successfully loaded and all work. But how can i retrieve text from editor? According documentation class ToastUIEditor has method getMarkdown,but i can't acess to object with this method
I try use JS markdown editor tui-editor. For this i add on page div element with id "rawtext". Standart initializaion:
var editor = $('#rawtext').tuiEditor({
initialEditType: 'markdown',
previewStyle: 'vertical',
exts: ['colorSyntax']
});
Editor is successfully loaded and all work. But how can i retrieve text from editor? According documentation class ToastUIEditor has method getMarkdown,but i can't acess to object with this method
Share Improve this question asked Jun 12, 2018 at 10:47 GDAGDA 1591 gold badge2 silver badges12 bronze badges6 Answers
Reset to default 3It's from the editor maintainer.
The jQuery plugin doesn't expose any APIs from the documentation. It's just a shortcut for the initializer.
You'll want to initialize the editor with ToastUIEditor constructor if you want to access the APIs.
var editor = new tui.Editor({
el: document.querySelector('#rawtext'),
initialEditType: 'markdown',
previewStyle: 'vertical',
height: '300px'
});
editor.getMarkdown()
The change
event is where you most likely want to call that method.
var editor = $('#rawtext').tuiEditor({
initialEditType: 'markdown',
previewStyle: 'vertical',
exts: ['colorSyntax'],
events: {
change: function() {
console.log(editor.getMarkdown())
},
}
});
I'm also not sure if the jQuery plugin returns the object, but some form of this pattern will get you where you're trying to go.
This is an old thread but I think I faced the same problem and want to share my solution.
I embedded the editor within the HTML element and then was able to get the markdown directly.
create the editor
let editor = $('#rawtext').tuiEditor({ initialEditType: 'markdown', previewStyle: 'vertical', exts: ['colorSyntax'] }); $('#rawtext').editor = editor;
get the markdown directly from the embedded editor
let editor = $('#rawtext').editor; let markdown = editor.getMarkdown()
I've faced the same problem and below is what I did. Hope it helps
var editor = new tui.Editor({
el: document.querySelector('#editSection'),
initialEditType: 'markdown',
previewStyle: 'vertical',
height: '300px'
});
$('#editSection').data('editor', editor);
$("#editSection").data('editor').setValue("* [x] Some markdown **here**");
alert($("#editSection").data('editor').getValue());
For the jquery editor (v2) the following is suggested in the documentation and I can confirm that this is working for me. The answer that suggests to attach the editor to the div after creation however doesn't work for me.
Creation of the editor after loading the page
let logeditor = $('#editor').toastuiEditor(
{
height: '500px',
initialEditType: 'markdown',
previewStyle: 'horizontal'
});
Fething the markdown or html
const markdown = $('#editor').toastuiEditor('getMarkdown');
console.log (markdown);
const html = $('#editor').toastuiEditor('getHtml');
console.log (html);
editor.data('tuiEditor').getMarkdown()
本文标签: javascripttuieditor how can i retrieve text (markdownhtml)Stack Overflow
版权声明:本文标题:javascript - tui-editor: how can i retrieve text (markdownhtml) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745151305a2644934.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论