From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: A simple Lua filter for Pandoc
Date: Tue, 04 Jan 2022 10:14:58 +0000 [thread overview]
Message-ID: <875yqzu7rx.fsf@posteo.net> (raw)
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
next reply other threads:[~2022-01-04 10:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-04 10:14 Juan Manuel Macías [this message]
2022-01-04 11:26 ` A simple Lua filter for Pandoc 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875yqzu7rx.fsf@posteo.net \
--to=maciaschain@posteo.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).