Skip to content

Commit

Permalink
Merge pull request #60 from atusy/pandoc3
Browse files Browse the repository at this point in the history
Support pandoc 3.0
  • Loading branch information
kmuto authored Jul 3, 2023
2 parents 2004c82 + c0d7f1a commit 1fec901
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 17 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/pandoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ jobs:
Pandoc:
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.1']
pandoc: ['2.11.3', '3.1.4']
steps:
- uses: actions/checkout@master
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
ruby-version: ${{ matrix.ruby }}
- uses: r-lib/actions/setup-pandoc@v1
with:
pandoc-version: '2.11.3'
pandoc-version: ${{ matrix.pandoc }}
- run: |
gem install bundler --no-document
bundle install --retry 3
Expand Down
37 changes: 35 additions & 2 deletions lua/filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ local beginchild = {pandoc.Plain(review_inline("//beginchild"))}
local endchild = {pandoc.Plain(review_inline("//endchild"))}

local function markdown(text)
return(pandoc.read(text, "markdown").blocks[1].content)
return pandoc.read(
text,
"markdown-auto_identifiers-smart+east_asian_line_breaks",
PANDOC_READER_OPTIONS
).blocks[1].content
end

local function support_blankline(constructor)
Expand Down Expand Up @@ -150,6 +154,34 @@ local function noindent(para)
return para
end

local function figure(fig)
-- Pandoc 3.x adds pandoc.Figure
if #fig.content > 1 or #fig.content[1].content > 1 then
error("NotImplemented")
end

local base = fig.content[1].content[1]

local attr = {}
for k, v in pairs(base.attributes) do
attr[k] = v
end
local classes = {}
for _, v in pairs(base.classes) do
table.insert(classes, "." .. v)
end
attr.classes = table.concat(classes, " ")
attr.identifier = base.attr.identifier
attr.is_figure = "true"

return pandoc.Image(
base.title,
base.src,
pandoc.utils.stringify(fig.caption),
attr
)
end

return {
{Emph = support_strong("Strong")},
{Strong = support_strong("Emph")},
Expand All @@ -160,5 +192,6 @@ return {
{BulletList = nestablelist},
{OrderedList = nestablelist},
{DefinitionList = nestablelist},
{Div = caption_div}
{Div = caption_div},
{Figure = figure},
}
50 changes: 37 additions & 13 deletions lua/review.lua
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ function CaptionedImage(s, src, tit, attr)
)
end

function Image(s, src, tit, attr)
-- Re:VIEW @<icon> ignores caption and title
if attr.is_figure then
return CaptionedImage(src, s, tit, attr)
end
local id = string.gsub(src, "%.%w+$", "")
id = string.gsub(id, "^images/", "")
return format_inline("icon", id)
end

function Note(s)
note_num = note_num + 1
table.insert(footnotes, "//footnote[fn" .. note_num .. "][" .. s .. "]")
Expand Down Expand Up @@ -596,24 +606,38 @@ function RawBlock(format, text)
end
end

try_catch {
try = function()
metadata = PANDOC_DOCUMENT.meta
end,
catch = function(error)
log("Due to your pandoc version is too old, config.yml loader is disabled.\n")
end
}
local function configure()
try_catch {
try = function()
metadata = PANDOC_DOCUMENT.meta
end,
catch = function(error)
log("Due to your pandoc version is too old, config.yml loader is disabled.\n")
end
}

if (metadata) then
-- Load config from YAML
for k,v in pairs(config) do
if metadata[k] ~= nil then
config[k] = stringify(metadata[k])
if (metadata) then
-- Load config from YAML
for k,v in pairs(config) do
if metadata[k] ~= nil then
config[k] = stringify(metadata[k])
end
end
end
end

if PANDOC_VERSION >= "3.0.0" then
-- NOTE: A wrapper to support Pandoc >= 3.0 https://pandoc.org/custom-writers.html#changes-in-pandoc-3.0
function Writer (doc, opts)
PANDOC_DOCUMENT = doc
PANDOC_WRITER_OPTIONS = opts
configure()
return pandoc.write_classic(doc, opts)
end
else
configure()
end

local meta = {}
meta.__index =
function(_, key)
Expand Down

0 comments on commit 1fec901

Please sign in to comment.