我想以编程方式从摩纳哥编辑器实例中获取格式化文本。
当我说格式化文本时,我的意思是语法高亮 - 当我从摩纳哥复制文本并将其粘贴到outlook(或支持粘贴HTML内容的任何其他应用程序)时,我得到了什么。
我的目标是将它与其他一些文本(摩纳哥编辑无法访问)一起放在剪贴板上。
我如何实现这一目标?
答案 0 :(得分:0)
根据此https://github.com/Microsoft/monaco-editor/issues/866
答案应该是
var editor = monaco.editor.create(document.getElementById("container"), {
value: "function hello() {\n\talert('Hello world!');\n}",
language: "javascript"
});
setTimeout(function() {
const html = editor.viewModel.getHTMLToCopy([editor.getModel().getFullModelRange()], false);
console.log(html);
}, 2000);