"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "data/sample.lua" between
pandoc-2.17.1.tar.gz and pandoc-2.17.1.1.tar.gz

About: Pandoc converts files from one markup format into another.

sample.lua  (pandoc-2.17.1):sample.lua  (pandoc-2.17.1.1)
skipping to change at line 17 skipping to change at line 17
-- --
-- Invoke with: pandoc -t sample.lua -- Invoke with: pandoc -t sample.lua
-- --
-- Note: you need not have lua installed on your system to use this -- Note: you need not have lua installed on your system to use this
-- custom writer. However, if you do have lua installed, you can -- custom writer. However, if you do have lua installed, you can
-- use it to test changes to the script. 'lua sample.lua' will -- use it to test changes to the script. 'lua sample.lua' will
-- produce informative error messages if your code contains -- produce informative error messages if your code contains
-- syntax errors. -- syntax errors.
local pipe = pandoc.pipe local pipe = pandoc.pipe
local stringify = (require "pandoc.utils").stringify local stringify = (require 'pandoc.utils').stringify
-- The global variable PANDOC_DOCUMENT contains the full AST of -- The global variable PANDOC_DOCUMENT contains the full AST of
-- the document which is going to be written. It can be used to -- the document which is going to be written. It can be used to
-- configure the writer. -- configure the writer.
local meta = PANDOC_DOCUMENT.meta local meta = PANDOC_DOCUMENT.meta
-- Choose the image format based on the value of the -- Choose the image format based on the value of the
-- `image_format` meta value. -- `image_format` meta value.
local image_format = meta.image_format local image_format = meta.image_format
and stringify(meta.image_format) and stringify(meta.image_format)
or "png" or 'png'
local image_mime_type = ({ local image_mime_type = ({
jpeg = "image/jpeg", jpeg = 'image/jpeg',
jpg = "image/jpeg", jpg = 'image/jpeg',
gif = "image/gif", gif = 'image/gif',
png = "image/png", png = 'image/png',
svg = "image/svg+xml", svg = 'image/svg+xml',
})[image_format] })[image_format]
or error("unsupported image format `" .. image_format .. "`") or error('unsupported image format `' .. image_format .. '`')
-- Character escaping -- Character escaping
local function escape(s, in_attribute) local function escape(s, in_attribute)
return s:gsub("[<>&\"']", return s:gsub('[<>&"\']',
function(x) function(x)
if x == '<' then if x == '<' then
return '&lt;' return '&lt;'
elseif x == '>' then elseif x == '>' then
return '&gt;' return '&gt;'
elseif x == '&' then elseif x == '&' then
return '&amp;' return '&amp;'
elseif in_attribute and x == '"' then elseif in_attribute and x == '"' then
return '&quot;' return '&quot;'
elseif in_attribute and x == "'" then elseif in_attribute and x == "'" then
skipping to change at line 63 skipping to change at line 63
return x return x
end end
end) end)
end end
-- Helper function to convert an attributes table into -- Helper function to convert an attributes table into
-- a string that can be put into HTML tags. -- a string that can be put into HTML tags.
local function attributes(attr) local function attributes(attr)
local attr_table = {} local attr_table = {}
for x,y in pairs(attr) do for x,y in pairs(attr) do
if y and y ~= "" then if y and y ~= '' then
table.insert(attr_table, ' ' .. x .. '="' .. escape(y,true) .. '"') table.insert(attr_table, ' ' .. x .. '="' .. escape(y,true) .. '"')
end end
end end
return table.concat(attr_table) return table.concat(attr_table)
end end
-- Table to store footnotes, so they can be included at the end. -- Table to store footnotes, so they can be included at the end.
local notes = {} local notes = {}
-- Blocksep is used to separate block elements. -- Blocksep is used to separate block elements.
function Blocksep() function Blocksep()
return "\n\n" return '\n\n'
end end
-- This function is called once for the whole document. Parameters: -- This function is called once for the whole document. Parameters:
-- body is a string, metadata is a table, variables is a table. -- body is a string, metadata is a table, variables is a table.
-- This gives you a fragment. You could use the metadata table to -- This gives you a fragment. You could use the metadata table to
-- fill variables in a custom lua template. Or, pass `--template=...` -- fill variables in a custom lua template. Or, pass `--template=...`
-- to pandoc, and pandoc will do the template processing as usual. -- to pandoc, and pandoc will do the template processing as usual.
function Doc(body, metadata, variables) function Doc(body, metadata, variables)
local buffer = {} local buffer = {}
local function add(s) local function add(s)
skipping to change at line 109 skipping to change at line 109
-- The functions that follow render corresponding pandoc elements. -- The functions that follow render corresponding pandoc elements.
-- s is always a string, attr is always a table of attributes, and -- s is always a string, attr is always a table of attributes, and
-- items is always an array of strings (the items in a list). -- items is always an array of strings (the items in a list).
-- Comments indicate the types of other variables. -- Comments indicate the types of other variables.
function Str(s) function Str(s)
return escape(s) return escape(s)
end end
function Space() function Space()
return " " return ' '
end end
function SoftBreak() function SoftBreak()
return "\n" return '\n'
end end
function LineBreak() function LineBreak()
return "<br/>" return '<br/>'
end end
function Emph(s) function Emph(s)
return "<em>" .. s .. "</em>" return '<em>' .. s .. '</em>'
end end
function Strong(s) function Strong(s)
return "<strong>" .. s .. "</strong>" return '<strong>' .. s .. '</strong>'
end end
function Subscript(s) function Subscript(s)
return "<sub>" .. s .. "</sub>" return '<sub>' .. s .. '</sub>'
end end
function Superscript(s) function Superscript(s)
return "<sup>" .. s .. "</sup>" return '<sup>' .. s .. '</sup>'
end end
function SmallCaps(s) function SmallCaps(s)
return '<span style="font-variant: small-caps;">' .. s .. '</span>' return '<span style="font-variant: small-caps;">' .. s .. '</span>'
end end
function Strikeout(s) function Strikeout(s)
return '<del>' .. s .. '</del>' return '<del>' .. s .. '</del>'
end end
function Link(s, tgt, tit, attr) function Link(s, tgt, tit, attr)
return "<a href='" .. escape(tgt,true) .. "' title='" .. return '<a href="' .. escape(tgt,true) .. '" title="' ..
escape(tit,true) .. "'" .. attributes(attr) .. ">" .. s .. "</a>" escape(tit,true) .. '"' .. attributes(attr) .. '>' .. s .. '</a>'
end end
function Image(s, src, tit, attr) function Image(s, src, tit, attr)
return "<img src='" .. escape(src,true) .. "' title='" .. return '<img src="' .. escape(src,true) .. '" title="' ..
escape(tit,true) .. "'/>" escape(tit,true) .. '"/>'
end end
function Code(s, attr) function Code(s, attr)
return "<code" .. attributes(attr) .. ">" .. escape(s) .. "</code>" return '<code' .. attributes(attr) .. '>' .. escape(s) .. '</code>'
end end
function InlineMath(s) function InlineMath(s)
return "\\(" .. escape(s) .. "\\)" return '\\(' .. escape(s) .. '\\)'
end end
function DisplayMath(s) function DisplayMath(s)
return "\\[" .. escape(s) .. "\\]" return '\\[' .. escape(s) .. '\\]'
end end
function SingleQuoted(s) function SingleQuoted(s)
return "&lsquo;" .. s .. "&rsquo;" return '&lsquo;' .. s .. '&rsquo;'
end end
function DoubleQuoted(s) function DoubleQuoted(s)
return "&ldquo;" .. s .. "&rdquo;" return '&ldquo;' .. s .. '&rdquo;'
end end
function Note(s) function Note(s)
local num = #notes + 1 local num = #notes + 1
-- insert the back reference right before the final closing tag. -- insert the back reference right before the final closing tag.
s = string.gsub(s, s = string.gsub(s,
'(.*)</', '%1 <a href="#fnref' .. num .. '">&#8617;</a></') '(.*)</', '%1 <a href="#fnref' .. num .. '">&#8617;</a></')
-- add a list item with the note to the note table. -- add a list item with the note to the note table.
table.insert(notes, '<li id="fn' .. num .. '">' .. s .. '</li>') table.insert(notes, '<li id="fn' .. num .. '">' .. s .. '</li>')
-- return the footnote reference, linked to the note. -- return the footnote reference, linked to the note.
return '<a id="fnref' .. num .. '" href="#fn' .. num .. return '<a id="fnref' .. num .. '" href="#fn' .. num ..
'"><sup>' .. num .. '</sup></a>' '"><sup>' .. num .. '</sup></a>'
end end
function Span(s, attr) function Span(s, attr)
return "<span" .. attributes(attr) .. ">" .. s .. "</span>" return '<span' .. attributes(attr) .. '>' .. s .. '</span>'
end end
function RawInline(format, str) function RawInline(format, str)
if format == "html" then if format == 'html' then
return str return str
else else
return '' return ''
end end
end end
function Cite(s, cs) function Cite(s, cs)
local ids = {} local ids = {}
for _,cit in ipairs(cs) do for _,cit in ipairs(cs) do
table.insert(ids, cit.citationId) table.insert(ids, cit.citationId)
end end
return "<span class=\"cite\" data-citation-ids=\"" .. table.concat(ids, ",") . return '<span class="cite" data-citation-ids="' .. table.concat(ids, ',') ..
. '">' .. s .. '</span>'
"\">" .. s .. "</span>"
end end
function Plain(s) function Plain(s)
return s return s
end end
function Para(s) function Para(s)
return "<p>" .. s .. "</p>" return '<p>' .. s .. '</p>'
end end
-- lev is an integer, the header level. -- lev is an integer, the header level.
function Header(lev, s, attr) function Header(lev, s, attr)
return "<h" .. lev .. attributes(attr) .. ">" .. s .. "</h" .. lev .. ">" return '<h' .. lev .. attributes(attr) .. '>' .. s .. '</h' .. lev .. '>'
end end
function BlockQuote(s) function BlockQuote(s)
return "<blockquote>\n" .. s .. "\n</blockquote>" return '<blockquote>\n' .. s .. '\n</blockquote>'
end end
function HorizontalRule() function HorizontalRule()
return "<hr/>" return "<hr/>"
end end
function LineBlock(ls) function LineBlock(ls)
return '<div style="white-space: pre-line;">' .. table.concat(ls, '\n') .. return '<div style="white-space: pre-line;">' .. table.concat(ls, '\n') ..
'</div>' '</div>'
end end
function CodeBlock(s, attr) function CodeBlock(s, attr)
-- If code block has class 'dot', pipe the contents through dot -- If code block has class 'dot', pipe the contents through dot
-- and base64, and include the base64-encoded png as a data: URL. -- and base64, and include the base64-encoded png as a data: URL.
if attr.class and string.match(' ' .. attr.class .. ' ',' dot ') then if attr.class and string.match(' ' .. attr.class .. ' ',' dot ') then
local img = pipe("base64", {}, pipe("dot", {"-T" .. image_format}, s)) local img = pipe('base64', {}, pipe('dot', {'-T' .. image_format}, s))
return '<img src="data:' .. image_mime_type .. ';base64,' .. img .. '"/>' return '<img src="data:' .. image_mime_type .. ';base64,' .. img .. '"/>'
-- otherwise treat as code (one could pipe through a highlighter) -- otherwise treat as code (one could pipe through a highlighter)
else else
return "<pre><code" .. attributes(attr) .. ">" .. escape(s) .. return '<pre><code' .. attributes(attr) .. '>' .. escape(s) ..
"</code></pre>" '</code></pre>'
end end
end end
function BulletList(items) function BulletList(items)
local buffer = {} local buffer = {}
for _, item in pairs(items) do for _, item in pairs(items) do
table.insert(buffer, "<li>" .. item .. "</li>") table.insert(buffer, '<li>' .. item .. '</li>')
end end
return "<ul>\n" .. table.concat(buffer, "\n") .. "\n</ul>" return '<ul>\n' .. table.concat(buffer, '\n') .. '\n</ul>'
end end
function OrderedList(items) function OrderedList(items)
local buffer = {} local buffer = {}
for _, item in pairs(items) do for _, item in pairs(items) do
table.insert(buffer, "<li>" .. item .. "</li>") table.insert(buffer, '<li>' .. item .. '</li>')
end end
return "<ol>\n" .. table.concat(buffer, "\n") .. "\n</ol>" return '<ol>\n' .. table.concat(buffer, '\n') .. '\n</ol>'
end end
function DefinitionList(items) function DefinitionList(items)
local buffer = {} local buffer = {}
for _,item in pairs(items) do for _,item in pairs(items) do
local k, v = next(item) local k, v = next(item)
table.insert(buffer, "<dt>" .. k .. "</dt>\n<dd>" .. table.insert(buffer, '<dt>' .. k .. '</dt>\n<dd>' ..
table.concat(v, "</dd>\n<dd>") .. "</dd>") table.concat(v, '</dd>\n<dd>') .. '</dd>')
end end
return "<dl>\n" .. table.concat(buffer, "\n") .. "\n</dl>" return '<dl>\n' .. table.concat(buffer, '\n') .. '\n</dl>'
end end
-- Convert pandoc alignment to something HTML can use. -- Convert pandoc alignment to something HTML can use.
-- align is AlignLeft, AlignRight, AlignCenter, or AlignDefault. -- align is AlignLeft, AlignRight, AlignCenter, or AlignDefault.
local function html_align(align) local function html_align(align)
if align == 'AlignLeft' then if align == 'AlignLeft' then
return 'left' return 'left'
elseif align == 'AlignRight' then elseif align == 'AlignRight' then
return 'right' return 'right'
elseif align == 'AlignCenter' then elseif align == 'AlignCenter' then
skipping to change at line 306 skipping to change at line 306
end end
-- Caption is a string, aligns is an array of strings, -- Caption is a string, aligns is an array of strings,
-- widths is an array of floats, headers is an array of -- widths is an array of floats, headers is an array of
-- strings, rows is an array of arrays of strings. -- strings, rows is an array of arrays of strings.
function Table(caption, aligns, widths, headers, rows) function Table(caption, aligns, widths, headers, rows)
local buffer = {} local buffer = {}
local function add(s) local function add(s)
table.insert(buffer, s) table.insert(buffer, s)
end end
add("<table>") add('<table>')
if caption ~= "" then if caption ~= '' then
add("<caption>" .. escape(caption) .. "</caption>") add('<caption>' .. escape(caption) .. '</caption>')
end end
if widths and widths[1] ~= 0 then if widths and widths[1] ~= 0 then
for _, w in pairs(widths) do for _, w in pairs(widths) do
add('<col width="' .. string.format("%.0f%%", w * 100) .. '" />') add('<col width="' .. string.format('%.0f%%', w * 100) .. '" />')
end end
end end
local header_row = {} local header_row = {}
local empty_header = true local empty_header = true
for i, h in pairs(headers) do for i, h in pairs(headers) do
local align = html_align(aligns[i]) local align = html_align(aligns[i])
table.insert(header_row,'<th align="' .. align .. '">' .. h .. '</th>') table.insert(header_row,'<th align="' .. align .. '">' .. h .. '</th>')
empty_header = empty_header and h == "" empty_header = empty_header and h == ''
end end
if not empty_header then if not empty_header then
add('<tr class="header">') add('<tr class="header">')
for _,h in pairs(header_row) do for _,h in pairs(header_row) do
add(h) add(h)
end end
add('</tr>') add('</tr>')
end end
local class = "even" local class = 'even'
for _, row in pairs(rows) do for _, row in pairs(rows) do
class = (class == "even" and "odd") or "even" class = (class == 'even' and 'odd') or 'even'
add('<tr class="' .. class .. '">') add('<tr class="' .. class .. '">')
for i,c in pairs(row) do for i,c in pairs(row) do
add('<td align="' .. html_align(aligns[i]) .. '">' .. c .. '</td>') add('<td align="' .. html_align(aligns[i]) .. '">' .. c .. '</td>')
end end
add('</tr>') add('</tr>')
end end
add('</table>') add('</table>')
return table.concat(buffer,'\n') return table.concat(buffer,'\n')
end end
function RawBlock(format, str) function RawBlock(format, str)
if format == "html" then if format == 'html' then
return str return str
else else
return '' return ''
end end
end end
function Div(s, attr) function Div(s, attr)
return "<div" .. attributes(attr) .. ">\n" .. s .. "</div>" return '<div' .. attributes(attr) .. '>\n' .. s .. '</div>'
end end
-- The following code will produce runtime warnings when you haven't defined -- The following code will produce runtime warnings when you haven't defined
-- all of the functions you need for the custom writer, so it's useful -- all of the functions you need for the custom writer, so it's useful
-- to include when you're working on a writer. -- to include when you're working on a writer.
local meta = {} local meta = {}
meta.__index = meta.__index =
function(_, key) function(_, key)
io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key)) io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key))
return function() return "" end return function() return '' end
end end
setmetatable(_G, meta) setmetatable(_G, meta)
 End of changes. 43 change blocks. 
55 lines changed or deleted 54 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)