public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* more fun with pandoc lua
@ 2023-01-21 19:05 John MacFarlane
       [not found] ` <CC299ED9-B166-4B45-AC42-9DA430CAA122-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: John MacFarlane @ 2023-01-21 19:05 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

-- 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")


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

* Re: more fun with pandoc lua
       [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-25 11:50   ` BPJ
  1 sibling, 1 reply; 5+ messages in thread
From: 'rufus42' via pandoc-discuss @ 2023-01-24 21:17 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2977 bytes --]

Hello fiddlosopher,

Thank you very much for sharing your script.
I would like to use it, but unfortunately I don't know how.
Do I use the script like a Lua filter?

Please be so kind and give me a hint how I can use your script.

Thank you for your time and best regards

fiddlosopher schrieb am Samstag, 21. Januar 2023 um 20:05:46 UTC+1:
-- 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") 

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d9e014a6-2dfd-44e3-a856-2bf18959103dn%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 4178 bytes --]

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

* Re: more fun with pandoc lua
       [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>
  0 siblings, 1 reply; 5+ messages in thread
From: John MacFarlane @ 2023-01-24 21:28 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 4260 bytes --]

This is using the new pandoc 3.0 feature which allows pandoc to be used as a Lua interpreter.  So just save the file as rosetta.lua and then;

pandoc lua rosetta.lua


> On Jan 24, 2023, at 1:17 PM, 'rufus42' via pandoc-discuss <pandoc-discuss@googlegroups.com> wrote:
> 
> Hello fiddlosopher,
> 
> Thank you very much for sharing your script.
> I would like to use it, but unfortunately I don't know how.
> Do I use the script like a Lua filter?
> 
> Please be so kind and give me a hint how I can use your script.
> 
> Thank you for your time and best regards
> 
> fiddlosopher schrieb am Samstag, 21. Januar 2023 um 20:05:46 UTC+1:
> -- 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 <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") 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d9e014a6-2dfd-44e3-a856-2bf18959103dn%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/d9e014a6-2dfd-44e3-a856-2bf18959103dn%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/EF95D206-4259-43CD-823D-C9AFA637E2FC%40gmail.com.

[-- Attachment #2: Type: text/html, Size: 6647 bytes --]

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

* Re: more fun with pandoc lua
       [not found]         ` <EF95D206-4259-43CD-823D-C9AFA637E2FC-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2023-01-24 21:48           ` 'rufus42' via pandoc-discuss
  0 siblings, 0 replies; 5+ messages in thread
From: 'rufus42' via pandoc-discuss @ 2023-01-24 21:48 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 4309 bytes --]

Hello fiddlosopher,

thank you very much for your answer.
Great, it works!
(Must definitely look into the potential of Lua filters...).

Thanks for your time and best regards

fiddlosopher schrieb am Dienstag, 24. Januar 2023 um 22:28:10 UTC+1:

> This is using the new pandoc 3.0 feature which allows pandoc to be used as 
> a Lua interpreter.  So just save the file as rosetta.lua and then;
>
> pandoc lua rosetta.lua
>
>
> On Jan 24, 2023, at 1:17 PM, 'rufus42' via pandoc-discuss <
> pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote:
>
> Hello fiddlosopher,
>
> Thank you very much for sharing your script.
> I would like to use it, but unfortunately I don't know how.
> Do I use the script like a Lua filter?
>
> Please be so kind and give me a hint how I can use your script.
>
> Thank you for your time and best regards
>
> fiddlosopher schrieb am Samstag, 21. Januar 2023 um 20:05:46 UTC+1:
> -- 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") 
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/d9e014a6-2dfd-44e3-a856-2bf18959103dn%40googlegroups.com 
> <https://groups.google.com/d/msgid/pandoc-discuss/d9e014a6-2dfd-44e3-a856-2bf18959103dn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/dbe5d1cc-a2c7-4fb0-b266-6ae99805e6e9n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 6863 bytes --]

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

* Re: more fun with pandoc lua
       [not found] ` <CC299ED9-B166-4B45-AC42-9DA430CAA122-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2023-01-24 21:17   ` 'rufus42' via pandoc-discuss
@ 2023-01-25 11:50   ` BPJ
  1 sibling, 0 replies; 5+ messages in thread
From: BPJ @ 2023-01-25 11:50 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 4268 bytes --]

I wonder if my filters/custom writers for converting plain output into
"email" — something in between fully plain and fully markdown, configurable
in various ways (through metadata) — and to Perl POD could profit from
being rewritten as standalone scripts to be used with pandoc-lua. Both
basically replace some elements in the AST with "plain" raw inline or block
elements containing markup for the actual target format around the content
of the original element. As Lua scripts they could take configuaration on
the command line, using a pure Lua command line argument processor like
Penlight's lapp rather than having to programmatically convert Pandoc
metadata into a plain data structure with string/number leaves.

Den lör 21 jan. 2023 20:06John MacFarlane <fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

> -- 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")
>
> --
> You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/CC299ED9-B166-4B45-AC42-9DA430CAA122%40gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhCWYdonBf1%2BJrrv1wAWj9ktm50WA54CbFnuQm1R0K%2BzRA%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 5802 bytes --]

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

end of thread, other threads:[~2023-01-25 11:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21 19:05 more fun with pandoc lua John MacFarlane
     [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

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).