Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xrefs #402

Merged
merged 1 commit into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25
26
21 changes: 21 additions & 0 deletions flake-info/src/data/fix-xrefs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--[[
Resolve cross-references to NixOS options in a hacky way and link them to the
unstable channel's option search page on search.nixos.org
]]

function Link(elem)
prefix = '#opt-'
if elem.target:sub(1, #prefix) == prefix then
option_name = elem.target:sub(#prefix + 1)
option_name = option_name:gsub('%._name_%.', '.<name>.')
option_name = option_name:gsub('%._%.', '.*.')

elem.target = 'https://search.nixos.org/options?channel=unstable&show=' .. option_name .. '&query=' .. option_name

if #elem.content == 1 and elem.content[1].tag == 'Str' and elem.content[1].text == '???' then
elem.content[1].text = option_name
end

return elem
end
end
9 changes: 9 additions & 0 deletions flake-info/src/data/pandoc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

use lazy_static::lazy_static;
Expand All @@ -6,6 +8,8 @@ use pandoc::{
InputFormat, InputKind, OutputFormat, OutputKind, PandocError, PandocOption, PandocOutput,
};

const XREF_FILTER: &str = include_str!("fix-xrefs.lua");

lazy_static! {
static ref FILTERS_PATH: PathBuf = std::env::var("NIXPKGS_PANDOC_FILTERS_PATH")
.unwrap_or("".into())
Expand Down Expand Up @@ -35,6 +39,10 @@ impl<T: AsRef<str>> PandocExt for T {
p.push("link-unix-man-references.lua");
p
};
let tmpdir = tempfile::tempdir()?;
let xref_filter = tmpdir.path().join("fix-xrefs.lua");
writeln!(File::create(&xref_filter)?, "{}", XREF_FILTER)?;

let mut pandoc = pandoc::new();
let wrapper_xml = format!(
"
Expand All @@ -52,6 +60,7 @@ impl<T: AsRef<str>> PandocExt for T {
pandoc.add_options(&[
PandocOption::LuaFilter(citeref_filter),
PandocOption::LuaFilter(man_filter),
PandocOption::LuaFilter(xref_filter),
]);

pandoc.execute().map(|result| match result {
Expand Down