From 91b5abcaed850639cde8808076cf76719b9cc669 Mon Sep 17 00:00:00 2001 From: Vivien Kraus Date: Thu, 6 Oct 2022 23:16:54 +0200 Subject: Add a new chapter to beautify listing inclusion in book. --- mped.xml | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/mped.xml b/mped.xml index 8739fcf..fb8c4d0 100644 --- a/mped.xml +++ b/mped.xml @@ -251,9 +251,7 @@ makes cross-referencing easier.
- - Insert literally a listing in another when tangling - + Insert literally a listing in another when tangling @@ -315,4 +313,107 @@
+ + Displaying the source code: back to docbook! + + Now that the program is written, the mped tags are not required + anymore. We need to remove them, and embed their semantics into + docbook. For instance, the <mped:copy> tag that links to + other listings must be replaced with a comment instructing the + reader to insert the correct listing at this location. + + + To achieve this, we create a new stylesheet, that runs across + the document, and produces a list of templates to remove mped + elements. + +
+ Clean program listings + + We need to replace the <mped:copy> tags within the + program listing, with the title of the listing as a + comment. See to put + the comment in the XML language, and for a default language + (do not put a comment). + +
+ Insert a call-out comment in XML + + + <!-- + + + + + + + --> + + ]]> + +
+
+ Do not insert a call-out if the language comment syntax is unknown + + + ]]> + +
+ + Finally, all other elements must be copied as-is. This is why + the catch-all template + is used. + +
+ Copy everything else without modification + + + + + + + ]]> + +
+
+
+ Putting it all together + + The collection of all these templates gives a full stylesheet, + in . + +
+ The full stylesheet to apply mped markup + + + + ]]> + + + + + ]]> + +
+ + Starting from this file, mped.xml, and + the bootstrap tangling stylesheet, + tangle-bootstrap.xsl, you would obtain a + mped-less docbook file with: + + xsltproc tangle-bootstrap.xsl mped.xml | bash +xsltproc apply-mped.xsl mped.xml | xmllint --format - +
+
-- cgit v1.2.3