about summary refs log tree commit diff
path: root/nixpkgs/doc/build-aux/pandoc-filters/link-manpages.nix
blob: 2589a7c34251f06e02e7c2406a9cc14486a066a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{ pkgs ? import ../../.. {} }:
let
  inherit (pkgs) lib;
  manpageURLs = lib.importJSON (pkgs.path + "/doc/manpage-urls.json");
in pkgs.writeText "link-manpages.lua" ''
  --[[
  Adds links to known man pages that aren't already in a link.
  ]]

  local manpage_urls = {
  ${lib.concatStringsSep "\n" (lib.mapAttrsToList (man: url:
    "  [${builtins.toJSON man}] = ${builtins.toJSON url},") manpageURLs)}
  }

  traverse = 'topdown'

  -- Returning false as the second value aborts processing of child elements.
  function Link(elem)
    return elem, false
  end

  function Code(elem)
    local is_man_role = elem.classes:includes('interpreted-text') and elem.attributes['role'] == 'manpage'
    if is_man_role and manpage_urls[elem.text] ~= nil then
      return pandoc.Link(elem, manpage_urls[elem.text]), false
    end
  end
''