Skip to content

Commit

Permalink
refactor: AST utilities are in SU.ast in SILE 0.15-develop
Browse files Browse the repository at this point in the history
And silex.ast provides our compatibility layer for these with
SILE 0.14.x
  • Loading branch information
Omikhleia authored and Didier Willis committed Jan 28, 2024
1 parent 07cf1b4 commit d63aec9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ luac.out
tests/*.pdf
tests/*.debug

# I often have crappy test files here
temp/*

7 changes: 4 additions & 3 deletions inputters/djot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
-- Using the djot Lua library for parsing.
-- Reusing the common commands initially made for the "markdown" inputter/package.
--
-- @copyright License: MIT (c) 2023 Omikhleia
-- @copyright License: MIT (c) 2023-2024 Omikhleia, Didier Willis
-- @module inputters.djot
--
require("silex.ast") -- Compatibility layer

local utils = require("packages.markdown.utils")
local ast = require("silex.ast")
local createCommand, createStructuredCommand
= ast.createCommand, ast.createStructuredCommand
= SU.ast.createCommand, SU.ast.createStructuredCommand

-- DJOT AST CONVERTER TO SILE AST

Expand Down
9 changes: 5 additions & 4 deletions inputters/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
--
-- Using the lunamark Lua library for parsing.
--
-- @copyright License: MIT (c) 2022-2023 Omikhleia
-- @copyright License: MIT (c) 2022-2024 Omikhleia, Didier Willis
-- @module inputters.markdown
--
require("silex.ast")

local utils = require("packages.markdown.utils")
local ast = require("silex.ast")
local createCommand, createStructuredCommand
= ast.createCommand, ast.createStructuredCommand
= SU.ast.createCommand, SU.ast.createStructuredCommand

local function simpleCommandWrapper (name)
-- Simple wrapper argound a SILE command
return function (content)
return createCommand (name, {}, content)
return createCommand(name, {}, content)
end
end

Expand Down
13 changes: 7 additions & 6 deletions inputters/pandocast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
-- Using the LuaJSON library for parsing.
-- Reusing the common commands initially made for the "markdown" inputter/package.
--
-- @copyright License: MIT (c) 2022-2023 Omikhleia
-- @copyright License: MIT (c) 2022-2024 Omikhleia, Didier Willis
-- @module inputters.pandocast
--
require("silex.ast") -- Compatibility layer

local utils = require("packages.markdown.utils")
local createCommand, createStructuredCommand
= SU.ast.createCommand, SU.ast.createStructuredCommand

local Pandoc = {
API_VERSION = { 1, 22, 0 } -- Supported API version (semver)
}
Expand Down Expand Up @@ -39,11 +45,6 @@ local function checkAstSemver(version)
end
end

local utils = require("packages.markdown.utils")
local ast = require("silex.ast")
local createCommand, createStructuredCommand
= ast.createCommand, ast.createStructuredCommand

local Renderer = pl.class()

function Renderer:_init(options)
Expand Down
24 changes: 13 additions & 11 deletions packages/markdown/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
-- Split in a standalone package so that it can be reused and
-- generalized somewhat independently from the undelying parsing code.
--
-- @copyright License: MIT (c) 2022-2023 Omikhleia
-- @copyright License: MIT (c) 2022-2024 Omikhleia, Didier Willis
-- @module packages.markdown.commands
--
require("silex.lang")
require("silex.lang") -- Compatibility layer
require("silex.ast") -- Compatibility layer

local utils = require("packages.markdown.utils")
local hasClass = utils.hasClass
local ast = require("silex.ast")

local createCommand, createStructuredCommand,
extractFromTree, subContent
= ast.createCommand, ast.createStructuredCommand,
ast.extractFromTree, ast.subContent
removeFromTree, subContent
= SU.ast.createCommand, SU.ast.createStructuredCommand,
SU.ast.removeFromTree, SU.ast.subContent

local base = require("packages.base")

Expand Down Expand Up @@ -717,7 +719,7 @@ Please consider using a resilient-compatible class!]])
if type(content) ~= "table" then
SU.error("Expected a table AST content in captioned blockquote environment")
end
local title = extractFromTree(content, "caption")
local title = removeFromTree(content, "caption")

if SILE.Commands["epigraph"] then -- asssuming the implementation from resilient.epigraph.
if title then
Expand Down Expand Up @@ -796,7 +798,7 @@ Please consider using a resilient-compatible class!]])
if type(content) ~= "table" then
SU.error("Expected a table AST content in captioned table environment")
end
local caption = extractFromTree(content, "caption")
local caption = removeFromTree(content, "caption")

SILE.process(content)
if caption then
Expand All @@ -814,8 +816,8 @@ Please consider using a resilient-compatible class!]])
if type(content) ~= "table" then
SU.error("Expected a table AST content in captioned table environment")
end
local term = extractFromTree(content, "term")
local desc = extractFromTree(content, "desc")
local term = removeFromTree(content, "term")
local desc = removeFromTree(content, "desc")

SILE.typesetter:leaveHmode()
SILE.call("strong", {}, term)
Expand All @@ -834,7 +836,7 @@ Please consider using a resilient-compatible class!]])
if type(content) ~= "table" then
SU.error("Expected a table AST content in captioned figure environment")
end
local caption = extractFromTree(content, "caption")
local caption = removeFromTree(content, "caption")

SILE.call("smallskip")
SILE.call("center", {}, function ()
Expand Down
4 changes: 2 additions & 2 deletions packages/markdown/utils.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
--- A few utilities for the markdown / pandocast inputters
--
--
local ast = require("silex.ast")
local createCommand = ast.createCommand
require("silex.ast") -- Compatibility layer
local createCommand = SU.ast.createCommand

--- Some utility functions.
-- @section utils
Expand Down

0 comments on commit d63aec9

Please sign in to comment.