import React from "react"; import { assert } from "chai"; import { DOCXQuoteStructRun, HTMLQuoteStructRun } from "./quoteStructRun"; import loadEL from "../../node/el/loadEL"; import type * as std from "../../law/std"; import { renderToStaticMarkup } from "../common"; import formatXML from "../../util/formatXml"; import htmlCSS from "./htmlCSS"; import path from "path"; import { promisify } from "util"; import fs from "fs"; import ensureTempTestDir from "../../../test/ensureTempTestDir"; import { renderDocxAsync } from "../common/docx/file"; import { w } from "../common/docx/tags"; describe("Test HTML quoteStructRun", () => { /* eslint-disable no-irregular-whitespace */ it("Success case", async () => { const input = loadEL({ tag: "QuoteStruct", attr: {}, children: [ { tag: "TableStruct", attr: {}, children: [ { tag: "TableStructTitle", 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: ["シジュウカラガン"], }, ], }, ], }, ], }, ], }, ], }) as std.QuoteStruct; const expectedHTML = /*html*/`\
表一
種名
(1)   かも科
シジュウカラガン
`; const element = ; const rendered = renderToStaticMarkup(element); console; const formatted = formatXML(rendered, { collapseContent: true }); assert.strictEqual( formatted, expectedHTML, ); const html = /*html*/`\ ${rendered} `; const tempParsedHtml = path.join(ensureTempTestDir(), "renderer.quoteStructRun.html"); await promisify(fs.writeFile)(tempParsedHtml, html); console.log(` Saved html: ${tempParsedHtml}`); }); }); describe("Test DOCX quoteStructRun", () => { /* eslint-disable no-irregular-whitespace */ it("Success case", async () => { const input = loadEL({ tag: "QuoteStruct", attr: {}, children: [ { tag: "TableStruct", attr: {}, children: [ { tag: "TableStructTitle", 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: ["シジュウカラガン"], }, ], }, ], }, ], }, ], }, ], }) as std.QuoteStruct; const expectedDOCX = /*xml*/`\ 表一 種名 (1)   かも科 シジュウカラガン `; 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.quoteStructRun.docx"); fs.writeFileSync(tempParsedDocx, u8); console.log(` Saved docx: ${tempParsedDocx}`); }); });