inokawa / remark-docx

remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).
https://inokawa.github.io/remark-docx/
MIT License
42 stars 15 forks source link

Tables not working #41

Closed strazan closed 1 year ago

strazan commented 1 year ago

Describe the bug My markdown containing table does not convert to table in docx.

To Reproduce

import { unified } from "unified";
import markdown from "remark-parse";
import docx from "remark-docx";
import { saveAs } from "file-saver";

const processor = unified().use(markdown).use(docx, { output: "blob" });

export const saveMessage = async () => {

  const html = `
| Column 1 |Column 2| Column 3 |
| -------- |--------| -------- |
| Row 1    | Data     | Data   |
| Row 2    | Data     | Data   |
| Row 3    | Data     | Data   |
`
  const doc = await processor.process(html);
  const blob = await doc.result as Blob;
  saveAs(blob, "example.docx");
}

saveMessage()

The example.docx file

image

Same string in the playground

image

Expected behavior To be a table in the docx.

Additional context "remark-docx": "^0.1.6" "file-saver": "^2.0.5"

inokawa commented 1 year ago

Table is not included in CommonMark spec so you can't parse table with remark-parse only. You have to setup remark-gfm like:

import { unified } from "unified";
import markdown from "remark-parse";
import gfm from "remark-gfm";
import docx from "remark-docx";

const processor = unified().use(markdown).use(gfm).use(docx, { output: "blob" });