Commit f397309f authored by pennae's avatar pennae
Browse files

doc: remove remnants of docbook times

all xml-related tooling can go away. shell.nix is no longer useful since
the makefile is gone and the build runs entirely via a derivation, and
gitignore is thus also no longer that useful. it may filter out some
swap files, but its main reason to exist (keeping generated files out of
a concurrent build of the derivation) has gone away.
parent be4d19ff
Loading
Loading
Loading
Loading

doc/.gitignore

deleted100644 → 0
+0 −11
Original line number Diff line number Diff line
*.chapter.xml
*.section.xml
.version
functions/library/generated
functions/library/locations.xml
highlightjs
manual-full.xml
out
result
result-*
media
+0 −23
Original line number Diff line number Diff line
--[[
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
+0 −34
Original line number Diff line number Diff line
--[[
Converts Link AST nodes with empty label to DocBook xref elements.

This is a temporary script to be able use cross-references conveniently
using syntax taken from MyST, while we still use docbook-xsl
for generating the documentation.

Reference: https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing
]]

local function starts_with(start, str)
  return str:sub(1, #start) == start
end

local function escape_xml_arg(arg)
  amps = arg:gsub('&', '&')
  amps_quotes = amps:gsub('"', '"')
  amps_quotes_lt = amps_quotes:gsub('<', '&lt;')

  return amps_quotes_lt
end

function Link(elem)
  has_no_content = #elem.content == 0
  targets_anchor = starts_with('#', elem.target)
  has_no_attributes = elem.title == '' and elem.identifier == '' and #elem.classes == 0 and #elem.attributes == 0

  if has_no_content and targets_anchor and has_no_attributes then
    -- xref expects idref without the pound-sign
    target_without_hash = elem.target:sub(2, #elem.target)

    return pandoc.RawInline('docbook', '<xref linkend="' .. escape_xml_arg(target_without_hash) .. '" />')
  end
end
+0 −44
Original line number Diff line number Diff line
--[[
Converts AST for reStructuredText roles into corresponding
DocBook elements.

Currently, only a subset of roles is supported.

Reference:
  List of roles:
    https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html
  manpage:
    https://tdg.docbook.org/tdg/5.1/citerefentry.html
  file:
    https://tdg.docbook.org/tdg/5.1/filename.html
]]

function Code(elem)
  if elem.classes:includes('interpreted-text') then
    local tag = nil
    local content = elem.text
    if elem.attributes['role'] == 'manpage' then
      tag = 'citerefentry'
      local title, volnum = content:match('^(.+)%((%w+)%)$')
      if title == nil then
        -- No volnum in parentheses.
        title = content
      end
      content = '<refentrytitle>' .. title .. '</refentrytitle>' .. (volnum ~= nil and ('<manvolnum>' .. volnum .. '</manvolnum>') or '')
    elseif elem.attributes['role'] == 'file' then
      tag = 'filename'
    elseif elem.attributes['role'] == 'command' then
      tag = 'command'
    elseif elem.attributes['role'] == 'option' then
      tag = 'option'
    elseif elem.attributes['role'] == 'var' then
      tag = 'varname'
    elseif elem.attributes['role'] == 'env' then
      tag = 'envar'
    end

    if tag ~= nil then
      return pandoc.RawInline('docbook', '<' .. tag .. '>' .. content .. '</' .. tag .. '>')
    end
  end
end
+0 −28
Original line number Diff line number Diff line
{ 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
''
Loading