REFACTOR: Small improvement in code for Tag.slice method

This commit is contained in:
Vinoth Kannan 2017-12-18 13:38:47 +05:30
parent 0588edbc96
commit b9f553d45d

View File

@ -155,10 +155,10 @@ class Tag {
}; };
} }
static slice(name, prefix, suffix) { static slice(name, suffix) {
return class extends Tag { return class extends Tag {
constructor() { constructor() {
super(name, prefix, suffix); super(name, "", suffix);
} }
decorate(text) { decorate(text) {
@ -171,11 +171,11 @@ class Tag {
} }
static cell(name) { static cell(name) {
return Tag.slice(name, "", " "); return Tag.slice(name, " ");
} }
static li() { static li() {
return class extends Tag.slice("li", "", "\n") { return class extends Tag.slice("li", "\n") {
decorate(text) { decorate(text) {
const indent = this.element.filterParentNames("ul").slice(1).map(() => " ").join(""); const indent = this.element.filterParentNames("ul").slice(1).map(() => " ").join("");
return super.decorate(`${indent}* ${trimLeft(text)}`); return super.decorate(`${indent}* ${trimLeft(text)}`);
@ -188,7 +188,7 @@ class Tag {
const tags = [ const tags = [
...Tag.blocks().map((b) => Tag.block(b)), ...Tag.blocks().map((b) => Tag.block(b)),
...Tag.headings().map((h, i) => Tag.heading(h, i + 1)), ...Tag.headings().map((h, i) => Tag.heading(h, i + 1)),
...Tag.slices().map((s) => Tag.slice(s, "", "\n")), ...Tag.slices().map((s) => Tag.slice(s, "\n")),
...Tag.emphases().map((e) => Tag.emphasis(e[0], e[1])), ...Tag.emphases().map((e) => Tag.emphasis(e[0], e[1])),
Tag.cell("td"), Tag.cell("th"), Tag.cell("td"), Tag.cell("th"),
Tag.replace("br", "\n"), Tag.replace("hr", "\n---\n"), Tag.replace("head", ""), Tag.replace("br", "\n"), Tag.replace("hr", "\n---\n"), Tag.replace("head", ""),