fix: 使用新的 @awesome-fe/translate 版本

This commit is contained in:
Zhicheng WANG 2021-02-06 09:44:55 +08:00
parent 9b60ef0392
commit 45890e6df8
3 changed files with 814 additions and 75 deletions

View File

@ -101,7 +101,7 @@
"@angular/platform-browser-dynamic": "11.0.0",
"@angular/router": "11.0.0",
"@angular/service-worker": "11.0.0",
"@awesome-fe/translate": "0.2.6",
"@awesome-fe/translate": "1.0.0",
"@webcomponents/custom-elements": "1.2.1",
"rxjs": "^6.5.3",
"tslib": "^2.0.0",
@ -113,9 +113,9 @@
"@angular/compiler-cli": "11.0.0",
"@types/html-minifier": "^3.5.3",
"@types/jasmine": "~3.6.0",
"@types/lunr": "^2.3.2",
"@types/klaw-sync": "^6.0.0",
"@types/lodash": "^4.14.133",
"@types/lunr": "^2.3.2",
"@types/mkdirp": "^0.5.2",
"@types/node": "^12.7.9",
"@types/puppeteer": "^1.12.4",
@ -142,8 +142,8 @@
"hast-util-to-string": "^1.0.0",
"html": "^1.0.0",
"html-minifier": "^3.5.21",
"http-server-spa": "^1.3.0",
"http-server": "^0.11.1",
"http-server-spa": "^1.3.0",
"ignore": "^3.3.3",
"image-size": "^0.5.1",
"jasmine": "~3.6.0",
@ -157,8 +157,8 @@
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"light-server": "^2.6.2",
"klaw-sync": "^6.0.0",
"light-server": "^2.6.2",
"lighthouse": "6.1.0",
"lighthouse-logger": "^1.2.0",
"lodash": "^4.17.4",
@ -167,7 +167,6 @@
"mocha": "^5.2.0",
"npm-run-all": "^4.1.5",
"protractor": "~7.0.0",
"puppeteer": "5.1.0",
"puppeteer": "^1.12.2",
"rehype": "^6.0.0",
"rehype-slug": "^2.0.0",

View File

@ -1,15 +1,11 @@
const {addIdForHeaders, markAndSwapAll} = require('@awesome-fe/translate');
const {JSDOM} = require('jsdom');
const selectorGroups = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'section', 'p', 't'];
const {Marker, defaultSelectors, DomDocumentFragment} = require('@awesome-fe/translate');
function mark(text) {
const dom = new JSDOM(text);
const body = dom.window.document.body;
addIdForHeaders(body);
markAndSwapAll(body, selectorGroups);
return body.innerHTML;
const marker = new Marker([...defaultSelectors, (node) => node.isTagOf('header') || node.isTagOf('section')]);
const doc = DomDocumentFragment.parse(text);
marker.addIdForHeaders(doc);
marker.markAndSwapAll(doc);
return doc.toHtml();
}
module.exports = {

File diff suppressed because it is too large Load Diff