emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A simple Lua filter for Pandoc


From: Thomas S. Dye
Subject: Re: A simple Lua filter for Pandoc
Date: Tue, 04 Jan 2022 06:28:36 -1000
User-agent: mu4e 1.2.0; emacs 27.1


Juan Manuel Macías <maciaschain@posteo.net> writes:

Hi,

Very often I need to convert docx documents to Org. There are a series of characters that I prefer to be passed to Org as Org entities and not literally, so I have written this little filter in Lua for Pandoc. I share it here in case it could be useful to someone. Of course, the
associative table can be expanded with more replacement cases:

#+begin_src lua :tangle entities.lua
local chars = {["/"] = "\\slash{}", ["*"] = "\\lowast{}", ["<"] = "\\lt{}", [">"] = "\\gt{}", ["†"] = "\\dagger{}", [utf8.char(0x00A0)] = "\\nbsp{}"}

  function Str (elem)
     x = elem.text:match 'http[^%s]'
     if not x then
        for i in pairs(chars) do
           elem = pandoc.Str(elem.text:gsub (i, chars[i]))
        end
        return elem
     end
  end
#+end_src

Neat!  Converting Word documents is no fun at all.

BTW, Babel support for Lua isn't very good AFAICT. I poked around ob-lua.el recently and concluded that one problem is that the Lua interpreter prints pointers for some data types instead of a human-readable form that might be parsed.

All the best,
Tom

--
Thomas S. Dye
https://tsdye.online/tsdye



reply via email to

[Prev in Thread] Current Thread [Next in Thread]