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

And a quick test:

#+begin_src sh :results org
str="/ † * < > http://foo.es  "
pandoc -f markdown -t org --lua-filter=entities.lua <<< $str
#+end_src

#+RESULTS:
#+begin_src org
\slash{} \dagger{} \lowast{} \lt{} \gt{} http://foo.es \nbsp{}
#+end_src

Best regards,

Juan Manuel 

Reply via email to