Skip to content

Commit

Permalink
feat: Citations basic support
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Dec 11, 2024
1 parent 2b977f9 commit 128a8de
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
15 changes: 15 additions & 0 deletions inputters/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ local function SileAstWriter (writerOps, renderOps)
return createCommand("markdown:internal:math" , { mode = mode }, { text })
end

writer.citations = function (text_cites, cites)
local buffer = {}
local ct = text_cites and 'AuthorInText' or 'NormalCitation'
for _, cite in ipairs(cites) do
buffer[#buffer + 1] = createCommand("cite", {
key = cite.name,
mode = cite.suppress_author and 'SuppressAuthor' or ct,
prefix = cite.prenote,
suffix = cite.postnote
})
end
return createStructuredCommand("markdown:internal:citations", {}, buffer)
end

-- Final AST conversion logic.
-- The lunamark "AST" is made of "ropes":
-- "A rope is an array whose elements may be ropes, strings, numbers,
Expand Down Expand Up @@ -430,6 +444,7 @@ function inputter:parse (doc)
line_blocks = true,
escaped_line_breaks = true,
tex_math_dollars = true,
citations = true,
}
for k, v in pairs(self.options) do
-- Allow overriding known options
Expand Down
22 changes: 16 additions & 6 deletions inputters/pandocast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,22 @@ function Renderer:Quoted (quotetype, inlines)
end

-- Cite [Citation] [Inline]
-- Where a Citation is a dictionary
function Renderer:Cite (_, inlines)
-- TODO
-- We could possibly do better.
-- Just render the inlines and ignore the citations
return self:render(inlines)
-- Where a Citation is a dictionary:
-- { citationId: Text, citationPrefix: [Inline], citationSuffix: [Inline],
-- citationMode: CitationMode, citationNoteNum: Int, citationHash: Int }
-- and CitationMode is a tag AuthorInText, SuppressAuthor or NormalCitation.
-- We dont use the raw inlines.
function Renderer:Cite (citations, _)
local buffer = {}
for _, cite in ipairs(citations) do
buffer[#buffer + 1] = createCommand("cite", {
key = cite.citationId,
mode = cite.citationMode.t,
prefix = #cite.citationPrefix > 0 and self:render(cite.citationPrefix) or nil,
suffix = #cite.citationSuffix > 0 and self:render(cite.citationSuffix) or nil,
})
end
return createStructuredCommand("markdown:internal:citations", {}, buffer)
end

-- Code Attr Text
Expand Down
8 changes: 8 additions & 0 deletions packages/markdown/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,14 @@ Please consider using a resilient-compatible class!]])
end
end, "Symbol in Djot (internal)")

self:registerCommand("markdown:internal:citations", function (_, content)
pl.pretty.dump(content)
SU.warn("Citations are not yet supported")
-- We'd need to transform to text the citationSuffix at least, and parse for locators.
-- But then, what to call anyway for multiple citation keys?
-- See https://github.com/sile-typesetter/sile/issues/2196
end, "Citations (internal)")

-- B. Fallback commands

self:registerCommand("markdown:fallback:blockquote", function (_, content)
Expand Down

0 comments on commit 128a8de

Please sign in to comment.