UNPKG

@awesome-fe/translate

Version:
49 lines 2.31 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.AngularJsonMarker = void 0; var marker_1 = require("./marker"); var html_marker_1 = require("./html-marker"); var dom_models_1 = require("../dom/parse5/dom-models"); var AngularJsonMarker = /** @class */ (function (_super) { __extends(AngularJsonMarker, _super); function AngularJsonMarker(selectors) { if (selectors === void 0) { selectors = dom_models_1.defaultSelectors; } var _this = _super.call(this) || this; _this.htmlMarker = new html_marker_1.HtmlMarker(selectors); return _this; } AngularJsonMarker.prototype.markContent = function (content, mono) { var json = JSON.parse(content); if (!json.contents) { return content; } json.contents = this.htmlMarker.markContent(this.preprocessAngularJson(json.contents), mono); return JSON.stringify(json); }; AngularJsonMarker.prototype.preprocessAngularJson = function (contents) { // 对 cheatsheet页做特殊处理 if (contents.includes('<h1 class="no-toc">Cheat Sheet</h1>')) { return contents.replace(/<(td|th)>\s*<p>([\s\S]*?)<\/p>\s*<\/\1>/g, '<$1>$2</$1>'); } // 为其它页面中的 section、header 添加翻译标记 return contents.replace(/<(section|header)\b/g, '<$1 ng-should-translate'); }; return AngularJsonMarker; }(marker_1.Marker)); exports.AngularJsonMarker = AngularJsonMarker; //# sourceMappingURL=angular-json-marker.js.map