import React from "react"; import { assert } from "chai"; import loadEL from "../../node/el/loadEL"; import type * as std from "../../law/std"; import { DOCXNoteLike, HTMLNoteLike } from "./noteLike"; import { renderToStaticMarkup } from "../common"; import { renderDocxAsync } from "../common/docx/file"; import ensureTempTestDir from "../../../test/ensureTempTestDir"; import path from "path"; import fs from "fs"; import formatXML from "../../util/formatXml"; import htmlCSS from "./htmlCSS"; import { promisify } from "util"; describe("Test HTML noteLike", () => { /* eslint-disable no-irregular-whitespace */ it("Success case", async () => { const input = loadEL({ tag: "NoteStruct", attr: {}, children: [ { tag: "Remarks", attr: {}, children: [ { tag: "RemarksLabel", attr: {}, children: ["備考"], }, { tag: "Sentence", attr: {}, children: ["備考文1"], }, ], }, { tag: "Note", attr: {}, children: [ { tag: "Table", attr: {}, children: [ { tag: "TableHeaderRow", attr: {}, children: [ { tag: "TableHeaderColumn", attr: {}, children: ["項"], }, { tag: "TableHeaderColumn", attr: {}, children: ["種名"], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: { colspan: "2", }, children: [ { tag: "Column", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["(1)"], }, ], }, { tag: "Column", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["かも科"], }, ], }, ], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["1"], }, ], }, { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["シジュウカラガン"], }, ], }, ], }, ], }, ], }, { tag: "Remarks", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["備考文2"], }, ], }, ], }) as std.NoteLike; const expectedHTML = /*html*/`\
備考
備考文1
種名
(1)   かも科
シジュウカラガン
備考文2
`; const element = ; const rendered = renderToStaticMarkup(element); const formatted = formatXML(rendered, { collapseContent: true }); assert.strictEqual( formatted, expectedHTML, ); const html = /*html*/`\ ${rendered} `; const tempParsedHtml = path.join(ensureTempTestDir(), "renderer.noteLike.html"); await promisify(fs.writeFile)(tempParsedHtml, html); console.log(` Saved html: ${tempParsedHtml}`); }); }); describe("Test DOCX noteLike", () => { /* eslint-disable no-irregular-whitespace */ it("Success case", async () => { const input = loadEL({ tag: "NoteStruct", attr: {}, children: [ { tag: "Remarks", attr: {}, children: [ { tag: "RemarksLabel", attr: {}, children: ["備考"], }, { tag: "Sentence", attr: {}, children: ["備考文1"], }, ], }, { tag: "Note", attr: {}, children: [ { tag: "Table", attr: {}, children: [ { tag: "TableHeaderRow", attr: {}, children: [ { tag: "TableHeaderColumn", attr: {}, children: ["項"], }, { tag: "TableHeaderColumn", attr: {}, children: ["種名"], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: { colspan: "2", }, children: [ { tag: "Column", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["(1)"], }, ], }, { tag: "Column", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["かも科"], }, ], }, ], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["1"], }, ], }, { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["シジュウカラガン"], }, ], }, ], }, ], }, ], }, { tag: "Remarks", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["備考文2"], }, ], }, ], }) as std.NoteLike; const expectedDOCX = /*xml*/`\ 備考 備考文1 種名 (1)   かも科 シジュウカラガン 備考文2 `; const element = ; const rendered = renderToStaticMarkup(element); const formatted = formatXML(rendered, { collapseContent: true }); assert.strictEqual( formatted, expectedDOCX, ); const u8 = await renderDocxAsync(element); const tempParsedDocx = path.join(ensureTempTestDir(), "renderer.noteLike.docx"); fs.writeFileSync(tempParsedDocx, u8); console.log(` Saved docx: ${tempParsedDocx}`); }); });