|
|
|
@ -393,15 +393,26 @@ async function aiformat() {
|
|
|
|
|
// TODO 处理html文件
|
|
|
|
|
// step 1 - split images and insert text tag
|
|
|
|
|
// match <figure ... </figure>
|
|
|
|
|
const img_tag = /<figure.*?>(.*?)<\/figure>/g
|
|
|
|
|
const img_list = doc_content.match(img_tag)
|
|
|
|
|
console.log(img_list)
|
|
|
|
|
const figure_tag = /<figure.*?>(.*?)<\/figure>/g
|
|
|
|
|
const figure_list = doc_content.match(figure_tag)
|
|
|
|
|
console.log(figure_list)
|
|
|
|
|
// replace img tag with text tag
|
|
|
|
|
var figure_listLen = 0
|
|
|
|
|
if (figure_list) {
|
|
|
|
|
console.log("replace figure tag")
|
|
|
|
|
figure_listLen = figure_list.length
|
|
|
|
|
for (let i = 0; i < figure_listLen; i++) {
|
|
|
|
|
const figure = figure_list[i]
|
|
|
|
|
const text = `<text>tag图片${i + 1}</text>`
|
|
|
|
|
doc_content = doc_content.replace(figure, text)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const img_tag = /<img.*?>/g
|
|
|
|
|
const img_list = doc_content.match(img_tag)
|
|
|
|
|
if(img_list){
|
|
|
|
|
console.log("replace img tag")
|
|
|
|
|
for(let i = 0; i < img_list.length; i++){
|
|
|
|
|
const img = img_list[i]
|
|
|
|
|
const text = `<text>图片${i + 1}</text>`
|
|
|
|
|
const text = `<text>tag图片${i + 1+figure_listLen}</text>`
|
|
|
|
|
doc_content = doc_content.replace(img, text)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -453,11 +464,18 @@ async function aiformat() {
|
|
|
|
|
|
|
|
|
|
console.log("html_content:\n\n", html_content)
|
|
|
|
|
// insert original img tag
|
|
|
|
|
if (figure_list) {
|
|
|
|
|
console.log("insert figure tag")
|
|
|
|
|
for (let i = 0; i < figure_listLen; i++) {
|
|
|
|
|
const figure = figure_list[i]
|
|
|
|
|
const text = `tag图片${i + 1}`
|
|
|
|
|
html_content = html_content.replace(text, figure)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(img_list){
|
|
|
|
|
console.log("insert img tag")
|
|
|
|
|
for (let i = 0; i < img_list.length; i++) {
|
|
|
|
|
const img = img_list[i]
|
|
|
|
|
const text = `图片${i + 1}`
|
|
|
|
|
const text = `tag图片${i + 1 + figure_listLen}`
|
|
|
|
|
html_content = html_content.replace(text, img)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -484,18 +502,28 @@ async function aiformat() {
|
|
|
|
|
console.log("headingClass:\n\n", headingClass)
|
|
|
|
|
// for each element
|
|
|
|
|
heading.forEach((element) => {
|
|
|
|
|
// reset counter for heading
|
|
|
|
|
// // reset counter for heading
|
|
|
|
|
// const parentNode = element.parentNode;
|
|
|
|
|
// let currentCounterReset = parentNode.style.counterReset;
|
|
|
|
|
// console.log(element,"\t",parentNode,"\t",currentCounterReset)
|
|
|
|
|
// // TODO 有bug
|
|
|
|
|
// if (currentCounterReset) {
|
|
|
|
|
// // currentCounterReset 不存在该counterreset
|
|
|
|
|
// if (currentCounterReset.indexOf(headingClass + "counter") == -1) {
|
|
|
|
|
// currentCounterReset += " " + headingClass + "counter";
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// currentCounterReset = headingClass + "counter";
|
|
|
|
|
// }
|
|
|
|
|
// parentNode.style.setProperty('counter-reset', currentCounterReset);
|
|
|
|
|
const parentNode = element.parentNode;
|
|
|
|
|
let currentCounterReset = parentNode.style.counterReset;
|
|
|
|
|
if (currentCounterReset) {
|
|
|
|
|
// currentCounterReset 不存在该counterreset
|
|
|
|
|
if (currentCounterReset.indexOf(headingClass + "counter") == -1) {
|
|
|
|
|
currentCounterReset += " " + headingClass + "counter";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
currentCounterReset = headingClass + "counter";
|
|
|
|
|
}
|
|
|
|
|
parentNode.style.setProperty('counter-reset', currentCounterReset);
|
|
|
|
|
let currentCounterReset = new Set(parentNode.style.counterReset.split(/\s+/).filter(Boolean));
|
|
|
|
|
|
|
|
|
|
// 添加新的 counter 名称
|
|
|
|
|
currentCounterReset.add(`${headingClass}counter`);
|
|
|
|
|
|
|
|
|
|
// 将 Set 转换回字符串
|
|
|
|
|
parentNode.style.setProperty('counter-reset', Array.from(currentCounterReset).join(' '));
|
|
|
|
|
element.classList.add(headingTag, headingClass);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -541,6 +569,8 @@ async function aiformat() {
|
|
|
|
|
ul[i].classList.add(user_config.listStyle.option);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AiFormat extends Plugin {
|
|
|
|
@ -771,7 +801,7 @@ function setConfig() {
|
|
|
|
|
Undo,
|
|
|
|
|
Export2Word, RefineDoc, Export2PDF, ToggleSideBar, SaveButton, AiFormat, PicRecog
|
|
|
|
|
],
|
|
|
|
|
balloonToolbar: ['bold', 'italic', '|', 'link', 'insertImage', '|', 'bulletedList', 'numberedList', '|', 'AiFormat'],
|
|
|
|
|
balloonToolbar: ['bold', 'italic', '|', 'link', 'insertImage', '|', 'bulletedList', 'numberedList'],
|
|
|
|
|
//自定义设置字体
|
|
|
|
|
fontFamily: {
|
|
|
|
|
// 自定义字体
|
|
|
|
|