我使用QuillJs来允许用户在我的项目中编辑文本,在我的web应用程序中实现它非常容易(我使用Laravel作为后端,HTML/CSS/JS作为前端),我想添加功能来导出自定义文本到Docx和PDF,但问题是,QuillJs使用外部样式表来构建编辑后的文本,所以当它被导出时,文本的某些部分不显示我尝试用PHPWord和Vanilla JavaScript导出的任何样式,这两个似乎都只允许内联样式。我的JS函数:
const Foo = () => {
var header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' " +
"xmlns:w='urn:schemas-microsoft-com:office:word' " +
"xmlns='http://www.w3.org/TR/REC-html40'>" +
"<head><meta charset='utf-8'>" +
"<link type=\"text/css\" href=\"https://cdn.quilljs.com/1.3.6/quill.snow.css\" rel=\"stylesheet\">" +
"</head><body>";
var footer = "</body></html>";
var body = document.querySelector('.ql-editor').innerHTML;
var sourceHTML = header + body + footer;
var source = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(sourceHTML);
// console.log(source);
var fileDownload = document.createElement("a");
document.body.appendChild(fileDownload);
fileDownload.href = source;
fileDownload.download = 'document.doc';
fileDownload.click();
document.body.removeChild(fileDownload);
}
你可以看到我已经尝试添加<link type=\"text/css\" href=\"https://cdn.quilljs.com/1.3.6/quill.snow.css\" rel=\"stylesheet\">
了,那么,我的问题是,有没有一种方法可以用样式导出它,或者有另一个文本编辑器,但是用的是内联样式(开源plz)?
编辑1:我尝试添加了一个var style = (`<style> css ...</style>`)
;
发布于 2019-11-28 03:42:55
问题是,我已经用一种简单的方式解决了我的问题,改变了编辑器框架。我已经尝试了Froala Editor和QuillJs,当我导出到Docx时它们都没有附带样式,所以我搜索了另一个,他们我找到了Summernote,一个具有内联样式的开源所见即所得编辑器,现在我可以导出我的Docx文件了。
https://stackoverflow.com/questions/59061331
复制相似问题