emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* A simple Lua filter for Pandoc
@ 2022-01-04 10:14 Juan Manuel Macías
  2022-01-04 11:26 ` Timothy
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Juan Manuel Macías @ 2022-01-04 10:14 UTC (permalink / raw)
  To: orgmode

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 


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-01-07 15:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-04 10:14 A simple Lua filter for Pandoc Juan Manuel Macías
2022-01-04 11:26 ` Timothy
2022-01-04 15:11   ` Juan Manuel Macías
2022-01-04 14:05 ` Max Nikulin
2022-01-04 15:06   ` Juan Manuel Macías
2022-01-05 16:29     ` Max Nikulin
2022-01-05 17:08       ` Juan Manuel Macías
2022-01-07 14:29         ` Max Nikulin
2022-01-07 15:14           ` Juan Manuel Macías
2022-01-04 16:28 ` Thomas S. Dye

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).