@awesome-fe/translate
Version:
Translation utils
44 lines • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SentenceFormatter = void 0;
var dom_models_1 = require("../dom/parse5/dom-models");
var markdown_1 = require("../dom/unified/markdown");
var adoc_to_tiny_html_1 = require("../dom/asciidoctor/html-adoc/adoc-to-tiny-html");
var tiny_html_to_adoc_1 = require("../dom/asciidoctor/html-adoc/tiny-html-to-adoc");
var SentenceFormatter = /** @class */ (function () {
function SentenceFormatter() {
}
SentenceFormatter.toHtml = function (sentence, format) {
switch (format) {
case 'html':
return sentence;
case 'plain':
var doc = dom_models_1.DomDocumentFragment.parse('');
doc.textContent = sentence;
return doc.toHtml();
case 'markdown':
return markdown_1.markdown.mdToHtml(sentence);
case 'asciidoctor':
return (0, adoc_to_tiny_html_1.adocToTinyHtml)(sentence);
}
};
SentenceFormatter.fromHtml = function (sentence, format) {
switch (format) {
case 'html':
return sentence;
case 'plain':
var doc = dom_models_1.DomDocumentFragment.parse(sentence);
return doc.textContent;
case 'markdown':
return markdown_1.markdown.mdFromHtml(sentence);
case 'asciidoctor':
return (0, tiny_html_to_adoc_1.tinyHtmlToAdoc)(sentence);
}
};
SentenceFormatter.toPlain = function (sentence, format) {
return this.fromHtml(this.toHtml(sentence, format), 'plain').trim();
};
return SentenceFormatter;
}());
exports.SentenceFormatter = SentenceFormatter;
//# sourceMappingURL=sentence-formatter.js.map