A Pandoc Lua filter for embedding and extracting comments between Markdown and DOCX.
This repository contains two Pandoc Lua filters for handling comments during Markdown ↔ DOCX conversions:
md2docx_add_comment.lua
- Embeds HTML-style comments (
<!-- comment -->
) from Markdown into DOCX as document comments.
- Embeds HTML-style comments (
docx2md_add_comment.lua
- Extracts comments from DOCX headers and converts them back into Markdown comments.
These filters are useful for tracking metadata across conversions.
Use this script to embed comments into DOCX headers.
$ pandoc input.md -o output.docx --lua-filter=md2docx_add_comment.lua
Markdown Input:
<!-- COMMENT EXAMPLE -->
## Section 1
DOCX Output:
- The header "Section 1" will have a comment attached:
COMMENT EXAMPLE
.
Use this script to extract comments from DOCX and restore them as Markdown comments.\
Note
Use the --track-changes=all
option for extracting DOCX comments.
$ pandoc input.docx -t gfm -o output.md --track-changes=all --lua-filter=docx2md_add_comment.lua
DOCX Input:
- A document with a header "Section 1" containing a comment:
COMMENT EXAMPLE
.
Markdown Output:
<!-- COMMENT EXAMPLE -->
## Section 1
Clone this repository and use the Lua filters with Pandoc:
$ git clone https://github.com/qq3g7bad/pandoc-comment-extractor.git
$ cd pandoc-comment-extractor
$ pandoc input.md -o output.docx --lua-filter=md2docx_add_comment.lua
$ pandoc input.docx -t gfm -o output.md --track-changes=all --lua-filter=docx2md_add_comment.lua