{"id":478,"date":"2018-07-01T10:33:51","date_gmt":"2018-07-01T00:33:51","guid":{"rendered":"https:\/\/www.docx4java.org\/blog\/?p=478"},"modified":"2018-07-01T10:34:31","modified_gmt":"2018-07-01T00:34:31","slug":"markdown-to-docx","status":"publish","type":"post","link":"https:\/\/www.docx4java.org\/blog\/2018\/07\/markdown-to-docx\/","title":{"rendered":"markdown to docx"},"content":{"rendered":"<p>I was looking for a way to convert <a href=\"https:\/\/github.com\/Swagger2Markup\/swagger2markup\">swagger2markup<\/a> markdown output to docx using Java (as opposed to Pandoc).<\/p>\n<p>I found <a href=\"https:\/\/github.com\/vsch\/flexmark-java\">flexmark-java<\/a>\u00a0which describes itself as:<\/p>\n<blockquote><p>Java Markdown parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.<\/p><\/blockquote>\n<p>Its\u00a0MD to DOCX\u00a0is in\u00a0<a href=\"https:\/\/github.com\/vsch\/flexmark-java\/tree\/master\/flexmark-docx-converter\">flexmark-docx-converter<\/a> module, which happily, uses docx4j under the covers.<\/p>\n<p>I tried it, and found it works nicely, the exception being table rendering if you open the resulting docx in LibreOffice (Word automatically\u00a0sets the column widths, but in LibreOffice 5.3 Writer, the\u00a0column widths are bad and painful to fix).\u00a0 \u00a0The underlying issue is that markdown doesn&#8217;t specify column widths, and in docx4j, we don&#8217;t\u00a0provide an algorithm to help the user set\u00a0sensible values.<\/p>\n<p>Development of flexmark-docx-converter was\u00a0\u00a0<a href=\"https:\/\/github.com\/vsch\/flexmark-java\/issues\/153\">sponsored by<\/a>\u00a0Johner Institut GmbH (medical device <a href=\"https:\/\/johner-institute.com\/consulting\/technical-documentation\/\">documentation<\/a>)<\/p>\n<p>The documentation for\u00a0flexmark-docx-converter is at\u00a0<a href=\"https:\/\/github.com\/vsch\/flexmark-java\/wiki\/Docx-Renderer-Extension\">https:\/\/github.com\/vsch\/flexmark-java\/wiki\/Docx-Renderer-Extension<\/a><\/p>\n<p>That page says:<\/p>\n<blockquote><p>Word does not handle inserted HTML very well.<\/p><\/blockquote>\n<p>It would be quite straightforward\u00a0to\u00a0use docx4j-ImportHTML to work around that \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was looking for a way to convert swagger2markup markdown output to docx using Java (as opposed to Pandoc). I found flexmark-java\u00a0which describes itself as: Java Markdown parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules. Its\u00a0MD to DOCX\u00a0is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-478","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":2,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/478\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}