Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pandoc 3.0 #60

Merged
merged 4 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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