创高项目初始化

This commit is contained in:
王文昊
2026-05-12 16:53:18 +08:00
commit abc3b4f875
13573 changed files with 2231964 additions and 0 deletions

View File

@@ -0,0 +1 @@
export default function normalize(doc: Document): void;

View File

@@ -0,0 +1,24 @@
const normalWeightRegexp = /font-weight:\s*normal/;
const blockTagNames = ['P', 'OL', 'UL'];
const isBlockElement = element => {
return element && blockTagNames.includes(element.tagName);
};
const normalizeEmptyLines = doc => {
Array.from(doc.querySelectorAll('br')).filter(br => isBlockElement(br.previousElementSibling) && isBlockElement(br.nextElementSibling)).forEach(br => {
br.parentNode?.removeChild(br);
});
};
const normalizeFontWeight = doc => {
Array.from(doc.querySelectorAll('b[style*="font-weight"]')).filter(node => node.getAttribute('style')?.match(normalWeightRegexp)).forEach(node => {
const fragment = doc.createDocumentFragment();
fragment.append(...node.childNodes);
node.parentNode?.replaceChild(fragment, node);
});
};
export default function normalize(doc) {
if (doc.querySelector('[id^="docs-internal-guid-"]')) {
normalizeFontWeight(doc);
normalizeEmptyLines(doc);
}
}
//# sourceMappingURL=googleDocs.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"googleDocs.js","names":["normalWeightRegexp","blockTagNames","isBlockElement","element","includes","tagName","normalizeEmptyLines","doc","Array","from","querySelectorAll","filter","br","previousElementSibling","nextElementSibling","forEach","parentNode","removeChild","normalizeFontWeight","node","getAttribute","match","fragment","createDocumentFragment","append","childNodes","replaceChild","normalize","querySelector"],"sources":["../../../../src/modules/normalizeExternalHTML/normalizers/googleDocs.ts"],"sourcesContent":["const normalWeightRegexp = /font-weight:\\s*normal/;\nconst blockTagNames = ['P', 'OL', 'UL'];\n\nconst isBlockElement = (element: Element | null) => {\n return element && blockTagNames.includes(element.tagName);\n};\n\nconst normalizeEmptyLines = (doc: Document) => {\n Array.from(doc.querySelectorAll('br'))\n .filter(\n (br) =>\n isBlockElement(br.previousElementSibling) &&\n isBlockElement(br.nextElementSibling),\n )\n .forEach((br) => {\n br.parentNode?.removeChild(br);\n });\n};\n\nconst normalizeFontWeight = (doc: Document) => {\n Array.from(doc.querySelectorAll('b[style*=\"font-weight\"]'))\n .filter((node) => node.getAttribute('style')?.match(normalWeightRegexp))\n .forEach((node) => {\n const fragment = doc.createDocumentFragment();\n fragment.append(...node.childNodes);\n node.parentNode?.replaceChild(fragment, node);\n });\n};\n\nexport default function normalize(doc: Document) {\n if (doc.querySelector('[id^=\"docs-internal-guid-\"]')) {\n normalizeFontWeight(doc);\n normalizeEmptyLines(doc);\n }\n}\n"],"mappings":"AAAA,MAAMA,kBAAkB,GAAG,uBAAuB;AAClD,MAAMC,aAAa,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC;AAEvC,MAAMC,cAAc,GAAIC,OAAuB,IAAK;EAClD,OAAOA,OAAO,IAAIF,aAAa,CAACG,QAAQ,CAACD,OAAO,CAACE,OAAO,CAAC;AAC3D,CAAC;AAED,MAAMC,mBAAmB,GAAIC,GAAa,IAAK;EAC7CC,KAAK,CAACC,IAAI,CAACF,GAAG,CAACG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CACnCC,MAAM,CACJC,EAAE,IACDV,cAAc,CAACU,EAAE,CAACC,sBAAsB,CAAC,IACzCX,cAAc,CAACU,EAAE,CAACE,kBAAkB,CACxC,CAAC,CACAC,OAAO,CAAEH,EAAE,IAAK;IACfA,EAAE,CAACI,UAAU,EAAEC,WAAW,CAACL,EAAE,CAAC;EAChC,CAAC,CAAC;AACN,CAAC;AAED,MAAMM,mBAAmB,GAAIX,GAAa,IAAK;EAC7CC,KAAK,CAACC,IAAI,CAACF,GAAG,CAACG,gBAAgB,CAAC,yBAAyB,CAAC,CAAC,CACxDC,MAAM,CAAEQ,IAAI,IAAKA,IAAI,CAACC,YAAY,CAAC,OAAO,CAAC,EAAEC,KAAK,CAACrB,kBAAkB,CAAC,CAAC,CACvEe,OAAO,CAAEI,IAAI,IAAK;IACjB,MAAMG,QAAQ,GAAGf,GAAG,CAACgB,sBAAsB,CAAC,CAAC;IAC7CD,QAAQ,CAACE,MAAM,CAAC,GAAGL,IAAI,CAACM,UAAU,CAAC;IACnCN,IAAI,CAACH,UAAU,EAAEU,YAAY,CAACJ,QAAQ,EAAEH,IAAI,CAAC;EAC/C,CAAC,CAAC;AACN,CAAC;AAED,eAAe,SAASQ,SAASA,CAACpB,GAAa,EAAE;EAC/C,IAAIA,GAAG,CAACqB,aAAa,CAAC,6BAA6B,CAAC,EAAE;IACpDV,mBAAmB,CAACX,GAAG,CAAC;IACxBD,mBAAmB,CAACC,GAAG,CAAC;EAC1B;AACF","ignoreList":[]}

View File

@@ -0,0 +1 @@
export default function normalize(doc: Document): void;

View File

@@ -0,0 +1,87 @@
const ignoreRegexp = /\bmso-list:[^;]*ignore/i;
const idRegexp = /\bmso-list:[^;]*\bl(\d+)/i;
const indentRegexp = /\bmso-list:[^;]*\blevel(\d+)/i;
const parseListItem = (element, html) => {
const style = element.getAttribute('style');
const idMatch = style?.match(idRegexp);
if (!idMatch) {
return null;
}
const id = Number(idMatch[1]);
const indentMatch = style?.match(indentRegexp);
const indent = indentMatch ? Number(indentMatch[1]) : 1;
const typeRegexp = new RegExp(`@list l${id}:level${indent}\\s*\\{[^\\}]*mso-level-number-format:\\s*([\\w-]+)`, 'i');
const typeMatch = html.match(typeRegexp);
const type = typeMatch && typeMatch[1] === 'bullet' ? 'bullet' : 'ordered';
return {
id,
indent,
type,
element
};
};
// list items are represented as `p` tags with styles like `mso-list: l0 level1` where:
// 1. "0" in "l0" means the list item id;
// 2. "1" in "level1" means the indent level, starting from 1.
const normalizeListItem = doc => {
const msoList = Array.from(doc.querySelectorAll('[style*=mso-list]'));
const ignored = [];
const others = [];
msoList.forEach(node => {
const shouldIgnore = (node.getAttribute('style') || '').match(ignoreRegexp);
if (shouldIgnore) {
ignored.push(node);
} else {
others.push(node);
}
});
// Each list item contains a marker wrapped with "mso-list: Ignore".
ignored.forEach(node => node.parentNode?.removeChild(node));
// The list stype is not defined inline with the tag, instead, it's in the
// style tag so we need to pass the html as a string.
const html = doc.documentElement.innerHTML;
const listItems = others.map(element => parseListItem(element, html)).filter(parsed => parsed);
while (listItems.length) {
const childListItems = [];
let current = listItems.shift();
// Group continuous items into the same group (aka "ul")
while (current) {
childListItems.push(current);
current = listItems.length && listItems[0]?.element === current.element.nextElementSibling &&
// Different id means the next item doesn't belong to this group.
listItems[0].id === current.id ? listItems.shift() : null;
}
const ul = document.createElement('ul');
childListItems.forEach(listItem => {
const li = document.createElement('li');
li.setAttribute('data-list', listItem.type);
if (listItem.indent > 1) {
li.setAttribute('class', `ql-indent-${listItem.indent - 1}`);
}
li.innerHTML = listItem.element.innerHTML;
ul.appendChild(li);
});
const element = childListItems[0]?.element;
const {
parentNode
} = element ?? {};
if (element) {
parentNode?.replaceChild(ul, element);
}
childListItems.slice(1).forEach(_ref => {
let {
element: e
} = _ref;
parentNode?.removeChild(e);
});
}
};
export default function normalize(doc) {
if (doc.documentElement.getAttribute('xmlns:w') === 'urn:schemas-microsoft-com:office:word') {
normalizeListItem(doc);
}
}
//# sourceMappingURL=msWord.js.map

File diff suppressed because one or more lines are too long