Bundle pandoc filters (#670)
Continuation of https://github.com/NixOS/nixos-search/pull/669
This commit is contained in:
parent
67bac7fe6d
commit
1128c8fb69
|
@ -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
|
36
flake-info/assets/data/myst-reader/roles.lua
Normal file
36
flake-info/assets/data/myst-reader/roles.lua
Normal file
|
@ -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
|
|
@ -23,7 +23,6 @@ pkgs.rustPlatform.buildRustPackage rec {
|
|||
checkInputs = with pkgs; [ pandoc ];
|
||||
|
||||
ROOTDIR = builtins.placeholder "out";
|
||||
NIXPKGS_PANDOC_FILTERS_PATH = pkgs.path + "/doc/build-aux/pandoc-filters";
|
||||
LINK_MANPAGES_PANDOC_FILTER = import src/data/link-manpages.nix { inherit pkgs; };
|
||||
|
||||
checkFlags = [
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
use lazy_static::lazy_static;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use pandoc::*;
|
||||
|
||||
const FILTERS_PATH: &str = env!("NIXPKGS_PANDOC_FILTERS_PATH");
|
||||
|
||||
lazy_static! {
|
||||
static ref DOCBOOK_ROLES_FILTER: PathBuf =
|
||||
Path::new(FILTERS_PATH).join("docbook-reader/citerefentry-to-rst-role.lua");
|
||||
static ref MARKDOWN_ROLES_FILTER: PathBuf =
|
||||
Path::new(FILTERS_PATH).join("myst-reader/roles.lua");
|
||||
crate::DATADIR.join("data/docbook-reader/citerefentry-to-rst-role.lua");
|
||||
static ref MARKDOWN_ROLES_FILTER: PathBuf = crate::DATADIR.join("data/myst-reader/roles.lua");
|
||||
static ref MANPAGE_LINK_FILTER: PathBuf = PathBuf::from(env!("LINK_MANPAGES_PANDOC_FILTER"));
|
||||
static ref XREF_FILTER: PathBuf = crate::DATADIR.join("data/fix-xrefs.lua");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue