-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continuation of #669
- Loading branch information
Showing
4 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
flake-info/assets/data/docbook-reader/citerefentry-to-rst-role.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--[[ | ||
Converts Code AST nodes produced by pandoc’s DocBook reader | ||
from citerefentry elements into AST for corresponding role | ||
for reStructuredText. | ||
We use subset of MyST syntax (CommonMark with features from rST) | ||
so let’s use the rST AST for rST features. | ||
Reference: https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-manpage | ||
]] | ||
|
||
function Code(elem) | ||
elem.classes = elem.classes:map(function (x) | ||
if x == 'citerefentry' then | ||
elem.attributes['role'] = 'manpage' | ||
return 'interpreted-text' | ||
else | ||
return x | ||
end | ||
end) | ||
|
||
return elem | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--[[ | ||
Replaces Str AST nodes containing {role}, followed by a Code node | ||
by a Code node with attrs that would be produced by rST reader | ||
from the role syntax. | ||
This is to emulate MyST syntax in Pandoc. | ||
(MyST is a CommonMark flavour with rST features mixed in.) | ||
Reference: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#roles-an-in-line-extension-point | ||
]] | ||
|
||
function Inlines(inlines) | ||
for i = #inlines-1,1,-1 do | ||
local first = inlines[i] | ||
local second = inlines[i+1] | ||
local correct_tags = first.tag == 'Str' and second.tag == 'Code' | ||
if correct_tags then | ||
-- docutils supports alphanumeric strings separated by [-._:] | ||
-- We are slightly more liberal for simplicity. | ||
-- Allow preceding punctuation (eg '('), otherwise '({file}`...`)' | ||
-- does not match. Also allow anything followed by a non-breaking space | ||
-- since pandoc emits those after certain abbreviations (e.g. e.g.). | ||
local prefix, role = first.text:match('^(.*){([-._+:%w]+)}$') | ||
if role ~= nil and (prefix == '' or prefix:match("^.*[%p ]$") ~= nil) then | ||
if prefix == '' then | ||
inlines:remove(i) | ||
else | ||
first.text = prefix | ||
end | ||
second.attributes['role'] = role | ||
second.classes:insert('interpreted-text') | ||
end | ||
end | ||
end | ||
return inlines | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters