Skip to content

Instantly share code, notes, and snippets.

@noamross
Last active May 28, 2024 19:25
Show Gist options
  • Save noamross/12e67a8d8d1fb71c4669cd1ceb9bbcf9 to your computer and use it in GitHub Desktop.
Save noamross/12e67a8d8d1fb71c4669cd1ceb9bbcf9 to your computer and use it in GitHub Desktop.
A pandoc filter for MS Word track changes to criticmarkup
-- a lua filter for panodoc
-- run pandoc your_word_doc.docx --track-change=all -t markdown --lua-filter=criticmarkup.lua
-- TODO: Detect substitutions in adjacent insertion/deletions
-- TODO: capture whole comment hightlight rather than just start point of comment
function Span(elem)
if elem.classes[1] and elem.classes[1] == "insertion" then
local opener = { pandoc.RawInline(FORMAT, "{++ ") }
local closer = { pandoc.RawInline(FORMAT, " ++}") }
return opener .. elem.content .. closer
elseif
elem.classes[1] and elem.classes[1] == "deletion" then
local opener = { pandoc.RawInline(FORMAT, "{-- ") }
local closer = { pandoc.RawInline(FORMAT, " --}") }
return opener .. elem.content .. closer
elseif
elem.classes[1] and elem.classes[1] == "comment-start" then
if elem.t == nil then
return pandoc.RawInline(FORMAT, "")
end
local opener = { pandoc.RawInline(FORMAT, "{>> ") }
local closer = { pandoc.RawInline(FORMAT, " ("), pandoc.RawInline(FORMAT, elem.attributes.author), pandoc.RawInline(FORMAT, ")<<}")}
return opener .. elem.content .. closer
elseif
elem.classes[1] and (elem.classes[1] == "comment-end" or elem.classes[1] == "paragraph-insertion") then
return pandoc.RawInline(FORMAT, "")
else
return nil
end
end
@jebyrnes
Copy link

jebyrnes commented Nov 8, 2018

Oh - does this just work with RMarkdown? Can you provide an example?

@jjallaire
Copy link

Fantastic!!!!

@kofm
Copy link

kofm commented Nov 10, 2020

This is awesome!

@ttxtea
Copy link

ttxtea commented Jun 16, 2021

This is indeed wonderful to convert docx comments into some more human readable form. I am wondering is it also possible to turn the filter around and have it produce docx with comments from criticmarkdown? In principle pancritic could maybe do this as a preprocessor, but its very convenient to just have it as a filter to pandoc.

@tillgrallert
Copy link

I second the last comment. CriticMarkup to comments in docx would be wonderful

@alerque
Copy link

alerque commented Mar 1, 2022

Related Pandoc issue has been re-opened: jgm/pandoc#2873

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment