Java markdown to word

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).

License

inokawa/remark-docx

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).

This project is aiming to support all nodes in mdast syntax tree, but currently transformation and stylings may not be well.

If you have some feature requests or improvements, please create a issue or PR.

  • paragraph
  • heading
  • thematicBreak
  • blockquote
  • list
  • listItem
  • table
  • tableRow
  • tableCell
  • html
  • code
  • yaml
  • toml
  • definition
  • footnoteDefinition
  • text
  • emphasis
  • strong
  • delete
  • inlineCode
  • break
  • link
  • image
  • linkReference
  • imageReference
  • footnote
  • footnoteReference
  • LaTeX support with math and inlineMath (remark-math is required)
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" >); const text = "# hello world"; (async () =>  const doc = await processor.process(text); const blob = await doc.result; saveAs(blob, "example.docx"); >)();
import  unified > from "unified"; import markdown from "remark-parse"; import docx from "remark-docx"; import * as fs from "fs"; const processor = unified().use(markdown).use(docx,  output: "buffer" >); const text = "# hello world"; (async () =>  const doc = await processor.process(text); const buffer = await doc.result; fs.writeFileSync("example.docx", buffer); >)();

All contributions are welcome. If you find a problem, feel free to create an issue or a PR.

  1. Clone this repo.
  2. Run npm install .
  3. Commit your fix.
  4. Make a PR and confirm all the CI checks passed.

About

remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Generate awesome word(docx) with template

License

Sayi/poi-tl

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A better way to generate word(docx) with template,based on Apache POI。

FreeMarker or Velocity generates new html pages or configuration files based on text template and data. poi-tl is a Word template engine that generates new documents based on Word template and data.

The Word template has rich styles. Poi-tl will perfectly retain the styles in the template in the generated documents. You can also set styles for the tags. The styles of the tags will be applied to the replaced text, so you can focus on the template design.

poi-tl is a «logic-less» template engine. There is no complicated control structure and variable assignment, only tags, some tags can be replaced with text, pictures, tables, etc., some tags will hide certain some document content, while other tags will loop a series of document content.

«Powerful» constructs like variable assignment or conditional statements make it easy to modify the look of an application within the template system exclusively. however, at the cost of separation, turning the templates themselves into part of the application logic.

《Google CTemplate》

poi-tl supports custom functions (plug-ins), functions can be executed anywhere in the Word template, do anything anywhere in the document is the goal of poi-tl.

Feature Description
✅ Text Render the tag as text
✅ Picture Render the tag as a picture
✅ Table Render the tag as a table
✅ Numbering Render the tag as a numbering
✅ Chart Bar chart (3D bar chart), column chart (3D column chart), area chart (3D area chart), line chart (3D line chart), radar chart, pie chart (3D pie Figure) and other chart rendering
✅ If Condition Hide or display certain document content (including text, paragraphs, pictures, tables, lists, charts, etc.) according to conditions
✅ Foreach Loop Loop through certain document content (including text, paragraphs, pictures, tables, lists, charts, etc.) according to the collection
✅ Loop table row Loop to copy a row of the rendered table
✅ Loop table column Loop copy and render a column of the table
✅ Loop ordered list Support the loop of ordered list, and support multi-level list at the same time
✅ Highlight code Word highlighting of code blocks, supporting 26 languages ​​and hundreds of coloring styles
✅ Markdown Convert Markdown to a word document
✅ Word attachment Insert attachment in Word
✅ Word Comments Complete support comment, create comment, modify comment, etc.
✅ Word SDT Complete support structured document tag
✅ Textbox Tag support in text box
✅ Picture replacement Replace the original picture with another picture
✅ bookmarks, anchors, hyperlinks Support setting bookmarks, anchors and hyperlinks in documents
✅ Expression Language Fully supports SpringEL expressions and can extend more expressions: OGNL, MVEL.
✅ Style The template is the style, and the code can also set the style
✅ Template nesting The template contains sub-templates, and the sub-templates then contain sub-templates
✅ Merge Word merge Merge, you can also merge in the specified position
✅ custom functions (plug-ins) Plug-in design, execute function anywhere in the document
dependency> groupId>com.deepoovegroupId> artifactId>poi-tlartifactId> version>1.12.1version> dependency>

NOTE: poi-tl 1.12.x requires POI version 5.2.2+ .

Start with a deadly simple example: replace > with «poi-tl template engine».

  1. Create a new document template.docx , including the content >
  2. TDO mode: Template + data-model = output
//The core API uses a minimalist design, only one line of code is required XWPFTemplate.compile("template.docx").render(new HashMapString, Object>()put("title", "poi-tl template engine"); >>).writeToFile("out_template.docx");

Open the out_template.docx document, everything is as you wish.

The tag consists of two curly braces, > is a tag, > is also a tag, title is the name of the tag, and ? identifies the type of tag. Next, we Let’s see what tag types are there.

The text tag is the most basic tag type in the Word template. > will be replaced by the value of key name in the data model. If the key is not exist, the tag will be cleared(The program can configure whether to keep the tag or throw an exception).

The style of the text tag will be applied to the replaced text, as shown in the following example.

put("name", "Mama"); put("thing", "chocolates");

> always said life was like a box of >.

Mama always said life was like a box of chocolates.

The image tag starts with @ , for example, > will look for the value with the key of logo in the data model, and then replace the tag with the image. The data corresponding to the image tag can be a simple URL or Path string, or a structure containing the width and height of the image.

put("watermelon", "assets/watermelon.png"); put("watermelon", "http://x/lemon.png"); put("lemon", Pictures.ofLocal("sob.jpeg", PictureType.JPEG).size(24, 24).create());
Fruit Logo: watermelon > lemon > banana > 
Fruit Logo: watermelon 🍉 lemon 🍋 banana 🍌 

The table tag starts with # , such as > , it will be rendered as a Word table with N rows and N columns. The value of N depends on the data of the table tag.

put("table", Tables.of(new String[][] < new String[] < "Song name", "Artist" > >).border(BorderStyle.DEFAULT).create());

The list tag corresponds to Word’s symbol list or numbered list, starting with * , such as > .

put("list", Numberings.create("Plug-in grammar", "Supports word text, pictures, table. ", "Template, not just template, but also style template"));
● Plug-in grammar ● Supports word text, pictures, table. ● Templates, not just templates, but also style templates 

A section is composed of two tags before and after, the start tag is identified by ? , and the end tag is identified by / , such as <> as the start tag of the sections block, > is the end tag, and section is the name of this section.

Sections are very useful when processing a series of document elements. Document elements (text, pictures, tables, etc.) located in a section can be rendered zero, one or N times, depending on the value of the section.

False Values or Empty collection

If the value of the section is null , false or an empty collection, all document elements located in the section will not be displayed, similar to the condition of the if statement is false .

Made it,Ma!>Top of the world!> Made it,Ma! > Top of the world!🎋 > 

Non-False Values and Not a collection

If the value of the section is not null , false , and is not a collection, all document elements in the section will be rendered once, similar to the condition of the if statement is true .

If the value of the section is a non-empty collection, the document elements in the section will be looped once or N times, depending on the size of the collection, similar to the foreach syntax.

< "songs": [ < "name": "Memories" >, < "name": "Sugar" >, < "name": "Last Dance" > ] >
Memories Sugar Last Dance 

In the loop, a special tag > can be used to directly refer to the object of the current iteration.

< "produces": [ "application/json", "application/xml" ] >
application/json application/xml 

Nesting is the merging of another Word template in a Word template, which can be understood as import, include or word document merging, marked with + , such as > .

class AddrModel < String addr; public AddrModel(String addr) < this.addr = addr; > > ListAddrModel> subData = new ArrayList<>(); subData.add(new AddrModel("Hangzhou,China")); subData.add(new AddrModel("Shanghai,China")); put("nested", Includes.ofLocal("sub.docx").setRenderModel(subData).create());
Hello, World Address: Hangzhou,China Address: Shanghai,China 

Documentation and examples

For more examples and the source code of all examples, see JUnit testcases.

You can join this project in many ways, not limited to the following ways:

  • Feedback problems encountered in use
  • Share the joy of success
  • Update and improve documentation
  • Solve and discuss issues

Источник

Читайте также:  Css if contains child
Оцените статью