From 818a9baba42c57f0816b8130a30c02fa2e4f34a4 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:51:04 +0900 Subject: [PATCH 1/4] feat: partially support Pandoc 3.0 (runs, but fails test) --- lua/review.lua | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/lua/review.lua b/lua/review.lua index d29e44f..c4d8f0e 100755 --- a/lua/review.lua +++ b/lua/review.lua @@ -596,24 +596,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) From 9b6fa03aa83df3fbd015284dde73f2a1a6622216 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:54:43 +0900 Subject: [PATCH 2/4] fix: pandoc.read should follow options of the parent conversion --- lua/filters.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/filters.lua b/lua/filters.lua index 2af172f..8d69b28 100644 --- a/lua/filters.lua +++ b/lua/filters.lua @@ -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) From 9babfe54dde3e887fd4eac953c7995a008ec1508 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 3 Jul 2023 22:00:40 +0900 Subject: [PATCH 3/4] feat: support pandoc.Figure from Pandoc 3.x --- lua/filters.lua | 31 ++++++++++++++++++++++++++++++- lua/review.lua | 10 ++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lua/filters.lua b/lua/filters.lua index 8d69b28..4dd8880 100644 --- a/lua/filters.lua +++ b/lua/filters.lua @@ -154,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")}, @@ -164,5 +192,6 @@ return { {BulletList = nestablelist}, {OrderedList = nestablelist}, {DefinitionList = nestablelist}, - {Div = caption_div} + {Div = caption_div}, + {Figure = figure}, } diff --git a/lua/review.lua b/lua/review.lua index c4d8f0e..5b9b825 100755 --- a/lua/review.lua +++ b/lua/review.lua @@ -477,6 +477,16 @@ function CaptionedImage(s, src, tit, attr) ) end +function Image(s, src, tit, attr) + -- Re:VIEW @ 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 .. "]") From c0d7f1abe151c97814826472090d36275c4a184e Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sat, 1 Jul 2023 12:30:29 +0900 Subject: [PATCH 4/4] try matrix test --- .github/workflows/pandoc.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pandoc.yml b/.github/workflows/pandoc.yml index d31033f..9fa2aee 100644 --- a/.github/workflows/pandoc.yml +++ b/.github/workflows/pandoc.yml @@ -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