public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: John MacFarlane <fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: more fun with pandoc lua
Date: Sat, 21 Jan 2023 11:05:41 -0800	[thread overview]
Message-ID: <CC299ED9-B166-4B45-AC42-9DA430CAA122@gmail.com> (raw)

-- This Lua script, when run using `pandoc lua`, will create an HTML
-- file rosetta.html that compares how the same content is represented
-- in all the text markup languages pandoc supports:

local inp = [[
# Heading

## level 2

### level 3

#### level 4 with attributes {.blue #foobar}

- Unordered
- list

1. ordered
2. list

a) Lettered list

   with continuation paragraph

> Block quote

``` {.lua}
local formats = pandoc.writers
for format,_ in formats do
  print(format)
end
```

*emphasized text **with strong emphasis***

`verbatim text` and a [link with `verbatim`](http://example.com)
]]
local doc = pandoc.read(inp, "markdown")

local formats = pandoc.writers
-- remove binary formats:
formats.docx = nil
formats.pptx = nil
formats.odt = nil
formats.epub2 = nil
formats.epub3 = nil
formats.epub = nil
formats.chunkedhtml = nil
formats.biblatex = nil
formats.bibtex = nil
formats.csljson = nil

local blocks = {}

-- Table of code languages to use for highlighting, when it differs
-- from the format name:
local langs = {
  icml = "xml",
  jira = "xml",
  fb2 = "xml",
  docbook = "xml",
  docbook4 = "xml",
  docbook5 = "xml",
  commonmark = "markdown",
  commonmark_x = "markdown",
  context = "latex",
  dzslides = "html5",
  slideous = "html",
  slidy = "html",
  man = "troff",
  ms = "troff",
  gfm = "markdown",
  markdown_mmd = "multimarkdown",
  markdown_github = "markdown",
  revealjs = "html",
  beamer = "latex",
  ipynb = "json",
  opendocument = "xml",
  native = "haskell",
  html5 = "html",
  html4 = "html",
}

local sorted_formats = {}
for format,_ in pairs(formats) do
  table.insert(sorted_formats, format)
end
table.sort(sorted_formats)

-- construct document part for each format
for _,format in ipairs(sorted_formats) do
  table.insert(blocks, pandoc.Header(2, format))
  local lang = langs[format] or format
  table.insert(blocks,
      pandoc.CodeBlock(pandoc.write(doc, format), {class = lang}))
end

local template = pandoc.template.compile(pandoc.template.default("html5"))
local html = pandoc.write(pandoc.Pandoc(blocks,
                            {title = "Markup Rosetta Stone"}),
                "html5",
                { template = template })

io.open("rosetta.html", "w"):write(html)
print("Created rosetta.html")


             reply	other threads:[~2023-01-21 19:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-21 19:05 John MacFarlane [this message]
     [not found] ` <CC299ED9-B166-4B45-AC42-9DA430CAA122-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-01-24 21:17   ` 'rufus42' via pandoc-discuss
     [not found]     ` <d9e014a6-2dfd-44e3-a856-2bf18959103dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-24 21:28       ` John MacFarlane
     [not found]         ` <EF95D206-4259-43CD-823D-C9AFA637E2FC-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-01-24 21:48           ` 'rufus42' via pandoc-discuss
2023-01-25 11:50   ` BPJ

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CC299ED9-B166-4B45-AC42-9DA430CAA122@gmail.com \
    --to=fiddlosopher-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.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.
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 NNTP newsgroup(s).