about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2018-03-26 08:24:27 -0400
committerGraham Christensen <graham@grahamc.com>2018-03-26 21:44:24 -0400
commit8dac5ce146c0c3afe963ea8bc955d5b147853345 (patch)
treefde04ea30558c36bd80d810d3024e1696bd6d306
parent378e05c6ddcc213652e51c9bdaa5d54c66959156 (diff)
downloadnixlib-8dac5ce146c0c3afe963ea8bc955d5b147853345.tar
nixlib-8dac5ce146c0c3afe963ea8bc955d5b147853345.tar.gz
nixlib-8dac5ce146c0c3afe963ea8bc955d5b147853345.tar.bz2
nixlib-8dac5ce146c0c3afe963ea8bc955d5b147853345.tar.lz
nixlib-8dac5ce146c0c3afe963ea8bc955d5b147853345.tar.xz
nixlib-8dac5ce146c0c3afe963ea8bc955d5b147853345.tar.zst
nixlib-8dac5ce146c0c3afe963ea8bc955d5b147853345.zip
nixpkgs docs: syntax highlight
-rw-r--r--doc/.gitignore1
-rw-r--r--doc/Makefile24
-rw-r--r--doc/default.nix8
-rw-r--r--doc/style.css2
4 files changed, 30 insertions, 5 deletions
diff --git a/doc/.gitignore b/doc/.gitignore
index d8e765e38c2d..d0ba103fa9f1 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -3,3 +3,4 @@
 .version
 out
 manual-full.xml
+highlightjs
diff --git a/doc/Makefile b/doc/Makefile
index b76ea9ed59e4..c16e70e9c6a2 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -6,16 +6,17 @@ all: validate out/html/index.html out/epub/manual.epub
 .PHONY: debug
 debug:
 	nix-shell --run "xmloscopy --docbook5 ./manual.xml ./manual-full.xml"
+
 .PHONY: clean
 clean:
 	rm -f ${MD_TARGETS} .version manual-full.xml
-	rm -rf ./out/
+	rm -rf ./out/ ./highlightjs
 
 .PHONY: validate
 validate: manual-full.xml
 	jing "$$RNG" manual-full.xml
 
-out/html/index.html: manual-full.xml style.css
+out/html/index.html: manual-full.xml style.css highlightjs
 	mkdir -p out/html
 	xsltproc ${xsltFlags} \
 		--nonet --xinclude \
@@ -23,12 +24,22 @@ out/html/index.html: manual-full.xml style.css
 		"$$XSL/docbook/xhtml/docbook.xsl" \
 		./manual-full.xml
 
+	mkdir -p out/html/highlightjs/
+	echo "document.onreadystatechange = function () { \
+	  var listings = document.querySelectorAll('.programlisting, .screen'); \
+	  for (i = 0; i < listings.length; ++i) { \
+	     hljs.highlightBlock(listings[i]); \
+	  } \
+	} " > out/html/highlightjs/loader.js
+
+	cp -r highlightjs out/html/
+
 	cp ./overrides.css out/html/
 	cp ./style.css out/html/style.css
 
 	mkdir -p out/html/images/callouts
 	cp "$$XSL/docbook/images/callouts/"*.svg out/html/images/callouts/
-	chmod u+w -R out/html/images/
+	chmod u+w -R out/html/
 
 out/epub/manual.epub: manual-full.xml
 	mkdir -p out/epub/scratch
@@ -47,6 +58,13 @@ out/epub/manual.epub: manual-full.xml
 	cd "out/epub/scratch/" && zip -Xr9D "../manual.epub" *
 	rm -rf "out/epub/scratch/"
 
+highlightjs:
+	mkdir -p highlightjs
+	cp -r "$$HIGHLIGHTJS/highlight.pack.js" highlightjs/
+	cp -r "$$HIGHLIGHTJS/LICENSE" highlightjs/
+	cp -r "$$HIGHLIGHTJS/mono-blue.css" highlightjs/
+
+
 manual-full.xml: ${MD_TARGETS} .version *.xml
 	xmllint --nonet --xinclude --noxincludenode manual.xml --output manual-full.xml
 
diff --git a/doc/default.nix b/doc/default.nix
index 6f9804417ade..8abde58bb114 100644
--- a/doc/default.nix
+++ b/doc/default.nix
@@ -11,12 +11,18 @@ pkgs.stdenv.mkDerivation {
 
   src = ./.;
 
+  # Hacking on these variables? Make sure to close and open
+  # nix-shell between each test, maybe even:
+  # $ nix-shell --run "make clean all"
+  # otherwise they won't reapply :)
+  HIGHLIGHTJS = pkgs.documentation-highlighter;
   XSL = "${pkgs.docbook5_xsl}/xml/xsl";
   RNG = "${pkgs.docbook5}/xml/rng/docbook/docbook.rng";
   xsltFlags = lib.concatStringsSep " " [
     "--param section.autolabel 1"
     "--param section.label.includes.component.label 1"
-    "--stringparam html.stylesheet 'style.css overrides.css'"
+    "--stringparam html.stylesheet 'style.css overrides.css highlightjs/mono-blue.css'"
+    "--stringparam html.script './highlightjs/highlight.pack.js ./highlightjs/loader.js'"
     "--param xref.with.number.and.title 1"
     "--param toc.section.depth 3"
     "--stringparam admon.style ''"
diff --git a/doc/style.css b/doc/style.css
index 23cbdff38915..83dae0dd2cd2 100644
--- a/doc/style.css
+++ b/doc/style.css
@@ -104,7 +104,7 @@ pre.screen, pre.programlisting
     padding: 3px 3px;
     margin-left: 1.5em;
     margin-right: 1.5em;
-    color: #600000;
+
     background: #f4f4f8;
     font-family: monospace;
     border-radius: 0.4em;