about summary refs log tree commit diff
path: root/nixpkgs/doc
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-09-13 11:53:06 +0000
committerAlyssa Ross <hi@alyssa.is>2021-09-13 17:18:49 +0000
commitc3e005913d59b8ad64004e60888a71816688af1f (patch)
treef65b32f0d16acaa40f2ee82ac736d150de4b6cf5 /nixpkgs/doc
parent1c8034da05499ca3d999f57ba1f6b235e7711ee1 (diff)
parentdb88608d8c811a93b74c99cfa1224952afc78200 (diff)
downloadnixlib-c3e005913d59b8ad64004e60888a71816688af1f.tar
nixlib-c3e005913d59b8ad64004e60888a71816688af1f.tar.gz
nixlib-c3e005913d59b8ad64004e60888a71816688af1f.tar.bz2
nixlib-c3e005913d59b8ad64004e60888a71816688af1f.tar.lz
nixlib-c3e005913d59b8ad64004e60888a71816688af1f.tar.xz
nixlib-c3e005913d59b8ad64004e60888a71816688af1f.tar.zst
nixlib-c3e005913d59b8ad64004e60888a71816688af1f.zip
Merge commit 'db88608d8c811a93b74c99cfa1224952afc78200'
Conflicts:
	nixpkgs/nixos/modules/config/update-users-groups.pl
Diffstat (limited to 'nixpkgs/doc')
-rw-r--r--nixpkgs/doc/Makefile9
-rw-r--r--nixpkgs/doc/build-aux/pandoc-filters/docbook-reader/citerefentry-to-rst-role.lua23
-rw-r--r--nixpkgs/doc/build-aux/pandoc-filters/docbook-writer/labelless-link-is-xref.lua (renamed from nixpkgs/doc/labelless-link-is-xref.lua)10
-rw-r--r--nixpkgs/doc/build-aux/pandoc-filters/docbook-writer/rst-roles.lua36
-rw-r--r--nixpkgs/doc/build-aux/pandoc-filters/link-unix-man-references.lua18
-rw-r--r--nixpkgs/doc/build-aux/pandoc-filters/myst-reader/roles.lua29
-rw-r--r--nixpkgs/doc/build-aux/pandoc-filters/myst-writer/roles.lua25
-rw-r--r--nixpkgs/doc/contributing/contributing-to-documentation.chapter.md7
8 files changed, 155 insertions, 2 deletions
diff --git a/nixpkgs/doc/Makefile b/nixpkgs/doc/Makefile
index 1d3a0e7ccbdf..f8d2d7248fab 100644
--- a/nixpkgs/doc/Makefile
+++ b/nixpkgs/doc/Makefile
@@ -3,12 +3,17 @@ MD_TARGETS=$(addsuffix .xml, $(basename $(shell find . -type f -regex '.*\.md$$'
 PANDOC ?= pandoc
 
 pandoc_media_dir = media
-# NOTE: Keep in sync with NixOS manual (/nixos/doc/manual/md-to-db.sh).
+# NOTE: Keep in sync with NixOS manual (/nixos/doc/manual/md-to-db.sh) and conversion script (/maintainers/scripts/db-to-md.sh).
 # TODO: Remove raw-attribute when we can get rid of DocBook altogether.
 pandoc_commonmark_enabled_extensions = +attributes+fenced_divs+footnotes+bracketed_spans+definition_lists+pipe_tables+raw_attribute
+# Not needed:
+# - docbook-reader/citerefentry-to-rst-role.lua (only relevant for DocBook → MarkDown/rST/MyST)
 pandoc_flags = --extract-media=$(pandoc_media_dir) \
 	--lua-filter=$(PANDOC_LUA_FILTERS_DIR)/diagram-generator.lua \
-	--lua-filter=labelless-link-is-xref.lua \
+	--lua-filter=build-aux/pandoc-filters/myst-reader/roles.lua \
+	--lua-filter=build-aux/pandoc-filters/link-unix-man-references.lua \
+	--lua-filter=build-aux/pandoc-filters/docbook-writer/rst-roles.lua \
+	--lua-filter=build-aux/pandoc-filters/docbook-writer/labelless-link-is-xref.lua \
 	-f commonmark$(pandoc_commonmark_enabled_extensions)+smart
 
 .PHONY: all
diff --git a/nixpkgs/doc/build-aux/pandoc-filters/docbook-reader/citerefentry-to-rst-role.lua b/nixpkgs/doc/build-aux/pandoc-filters/docbook-reader/citerefentry-to-rst-role.lua
new file mode 100644
index 000000000000..281e85af2717
--- /dev/null
+++ b/nixpkgs/doc/build-aux/pandoc-filters/docbook-reader/citerefentry-to-rst-role.lua
@@ -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
diff --git a/nixpkgs/doc/labelless-link-is-xref.lua b/nixpkgs/doc/build-aux/pandoc-filters/docbook-writer/labelless-link-is-xref.lua
index 67569b020916..fa97729a28bc 100644
--- a/nixpkgs/doc/labelless-link-is-xref.lua
+++ b/nixpkgs/doc/build-aux/pandoc-filters/docbook-writer/labelless-link-is-xref.lua
@@ -1,3 +1,13 @@
+--[[
+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
diff --git a/nixpkgs/doc/build-aux/pandoc-filters/docbook-writer/rst-roles.lua b/nixpkgs/doc/build-aux/pandoc-filters/docbook-writer/rst-roles.lua
new file mode 100644
index 000000000000..92dc6895750f
--- /dev/null
+++ b/nixpkgs/doc/build-aux/pandoc-filters/docbook-writer/rst-roles.lua
@@ -0,0 +1,36 @@
+--[[
+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'
+    end
+
+    if tag ~= nil then
+      return pandoc.RawInline('docbook', '<' .. tag .. '>' .. content .. '</' .. tag .. '>')
+    end
+  end
+end
diff --git a/nixpkgs/doc/build-aux/pandoc-filters/link-unix-man-references.lua b/nixpkgs/doc/build-aux/pandoc-filters/link-unix-man-references.lua
new file mode 100644
index 000000000000..12431f140fed
--- /dev/null
+++ b/nixpkgs/doc/build-aux/pandoc-filters/link-unix-man-references.lua
@@ -0,0 +1,18 @@
+--[[
+Turns a manpage reference into a link, when a mapping is defined
+in the unix-man-urls.lua file.
+]]
+
+local man_urls = {
+  ["tmpfiles.d(5)"] = "https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html",
+  ["nix.conf(5)"] = "https://nixos.org/manual/nix/stable/#sec-conf-file",
+  ["systemd.time(7)"] = "https://www.freedesktop.org/software/systemd/man/systemd.time.html",
+  ["systemd.timer(5)"] = "https://www.freedesktop.org/software/systemd/man/systemd.timer.html",
+}
+
+function Code(elem)
+  local is_man_role = elem.classes:includes('interpreted-text') and elem.attributes['role'] == 'manpage'
+  if is_man_role and man_urls[elem.text] ~= nil then
+    return pandoc.Link(elem, man_urls[elem.text])
+  end
+end
diff --git a/nixpkgs/doc/build-aux/pandoc-filters/myst-reader/roles.lua b/nixpkgs/doc/build-aux/pandoc-filters/myst-reader/roles.lua
new file mode 100644
index 000000000000..c33a688eeba7
--- /dev/null
+++ b/nixpkgs/doc/build-aux/pandoc-filters/myst-reader/roles.lua
@@ -0,0 +1,29 @@
+--[[
+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.
+      local role = first.text:match('^{([-._+:%w]+)}$')
+      if role ~= nil then
+        inlines:remove(i)
+        second.attributes['role'] = role
+        second.classes:insert('interpreted-text')
+      end
+    end
+  end
+  return inlines
+end
diff --git a/nixpkgs/doc/build-aux/pandoc-filters/myst-writer/roles.lua b/nixpkgs/doc/build-aux/pandoc-filters/myst-writer/roles.lua
new file mode 100644
index 000000000000..0136bc550652
--- /dev/null
+++ b/nixpkgs/doc/build-aux/pandoc-filters/myst-writer/roles.lua
@@ -0,0 +1,25 @@
+--[[
+Replaces Code nodes with attrs that would be produced by rST reader
+from the role syntax by a Str AST node containing {role}, followed by a Code node.
+
+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 Code(elem)
+  local role = elem.attributes['role']
+
+  if elem.classes:includes('interpreted-text') and role ~= nil then
+    elem.classes = elem.classes:filter(function (c)
+      return c ~= 'interpreted-text'
+    end)
+    elem.attributes['role'] = nil
+
+    return {
+      pandoc.Str('{' .. role .. '}'),
+      elem,
+    }
+  end
+end
diff --git a/nixpkgs/doc/contributing/contributing-to-documentation.chapter.md b/nixpkgs/doc/contributing/contributing-to-documentation.chapter.md
index 2f7ae32259c4..178fdb36262b 100644
--- a/nixpkgs/doc/contributing/contributing-to-documentation.chapter.md
+++ b/nixpkgs/doc/contributing/contributing-to-documentation.chapter.md
@@ -52,6 +52,13 @@ Additionally, the following syntax extensions are currently used:
 
   This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing).
 
+- []{#ssec-contributing-markup-inline-roles}
+  If you want to link to a man page, you can use `` {manpage}`nix.conf(5)` ``, which will turn into {manpage}`nix.conf(5)`.
+
+  The references will turn into links when a mapping exists in {file}`doc/build-aux/pandoc-filters/unix-man-urls.lua`.
+
+  This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#roles-an-in-line-extension-point). Though, the feature originates from [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-manpage) with slightly different syntax.
+
 - []{#ssec-contributing-markup-admonitions}
   **Admonitions**, set off from the text to bring attention to something.