Commit 4ae8c743 authored by Wendell Piez's avatar Wendell Piez

First cut at auto-manifest poll of XSLT and XProc for docs

parent 862a6d9a
### xpl
#### html-list-promote.xpl
XProc pipeline version 1.0 (4 steps)
Runtime dependency: `mark-lists.xsl`
Runtime dependency: `itemize-lists.xsl`
### xsl
#### itemize-lists.xsl
XSLT stylesheet version 2.0 (2 templates)
#### mark-lists.xsl
XSLT stylesheet version 2.0 (4 templates)
#### PROMOTE-lists.xsl
XSLT stylesheet version 3.0 (4 templates)
Declared dependency: `mark-lists.xsl`
Declared dependency: `itemize-lists.xsl`
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsw="http://coko.foundation/xsweet"
......
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsw="http://coko.foundation/xsweet"
......
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:xsw="http://coko.foundation/xsweet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0"
type="xsw:html-header-promote" name="html-header-promote">
<p:input port="parameters" kind="parameter"/>
<p:option name="dirpath" required="true"/>
<p:output port="HTML" primary="false">
<p:pipe port="result" step="produce-manifest-html"/>
</p:output>
<p:output port="MARKDOWN" primary="true">
<p:pipe port="result" step="render-markdown"/>
</p:output>
<p:serialization port="HTML" method="html" omit-xml-declaration="true" indent="true"/>
<p:serialization port="MARKDOWN" method="text" omit-xml-declaration="true"/>
<p:xslt name="produce-manifest-html">
<p:input port="source">
<p:document href="directory-manifest.xsl"/>
</p:input>
<p:input port="stylesheet">
<p:document href="directory-manifest.xsl"/>
</p:input>
<p:with-param name="dirpath" select="$dirpath"/>
</p:xslt>
<p:xslt name="render-markdown">
<p:input port="stylesheet">
<p:document href="html-to-markdown.xsl"/>
</p:input>
</p:xslt>
</p:declare-step>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:file="http://expath.org/ns/file"
xmlns:xsw="http://coko.foundation/xsweet"
xmlns:p="http://www.w3.org/ns/xproc"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="#all"
version="3.0"
expand-text="true">
<!-- Reads directory on file system and writes out a manifest of its contents.
For XSLTs and XProcs, lists file dependencies (echoes calls on xsl:import, xsl:include, document() function etc.)
Produces simple HTML suitable for auto-conversion into markdown
e.g., pipeline this with a markdown serializer to produce a file auto-manifest.md
-->
<!-- Next: connect up into pipeline for production of md
Run and refine (checking against Gitlab)
-->
<xsl:param name="dirpath" as="xs:string"/>
<xsl:template match="/*"/>
<xsl:template match="/" name="go">
<xsl:if test="$dirpath castable as xs:anyURI">
<html>
<body>
<xsl:for-each-group select="file:list($dirpath, true())" group-by="replace(.,'.*\.','')">
<div>
<h3>{ current-grouping-key() }</h3>
<xsl:apply-templates select="current-group()"/>
</div>
</xsl:for-each-group>
</body>
</html>
</xsl:if>
</xsl:template>
<xsl:template match=".">
<div>
<h4>
<xsl:sequence select="."/>
</h4>
</div>
</xsl:template>
<xsl:template match=".[ends-with(.,'xsl') or ends-with(.,'xslt') or ends-with(.,'xpl')]">
<xsl:variable name="filepath" select="$dirpath || '/' || ."/>
<div>
<h4>
<xsl:sequence select="."/>
</h4>
<xsl:apply-templates select="document($filepath)/*" mode="report"/>
</div>
</xsl:template>
<xsl:template match="xsl:stylesheet | xsl:transform" mode="report">
<xsl:variable name="templatecount" select="count(xsl:template)"/>
<p>XSLT stylesheet version { @version } ({ $templatecount } { if ($templatecount eq 1) then 'template' else 'templates' })</p>
<xsl:apply-templates mode="#current"/>
</xsl:template>
<xsl:template match="xsl:include | xsl:import" mode="report">
<p>Compile-time dependency ({ name() }) <code>{ @href }</code></p>
</xsl:template>
<xsl:template match="xsw:transform[empty(*)]" mode="report">
<p>Declared dependency: <code>{ normalize-space(.) }</code></p>
</xsl:template>
<xsl:template match="p:declare-step | p:pipeline" mode="report">
<xsl:variable name="stepcount" select="count(.//p:xslt | .//p:identity)"/>
<p>XProc pipeline version { @version } ({ $stepcount } { if ($stepcount eq 1) then 'step' else 'steps' })</p>
<xsl:apply-templates mode="#current"/>
</xsl:template>
<xsl:template match="p:document" mode="report">
<p>Runtime dependency: <code>{ @href }</code></p>
</xsl:template>
<xsl:template match="text()" mode="report"/>
</xsl:stylesheet>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
xpath-default-namespace="http://www.w3.org/1999/xhtml"
version="3.0">
<!-- Translates a simple HTML into Github Markdown -->
<xsl:template match="/">
<!-- Ensures XML output for XProc. Strip this element (or simply serialize using @method='text') to get your Markdown! -->
<md>
<xsl:apply-templates/>
</md>
</xsl:template>
<xsl:variable name="lf1"><xsl:text>&#xA;</xsl:text></xsl:variable>
<xsl:variable name="lf2"><xsl:text>&#xA;&#xA;</xsl:text></xsl:variable>
<xsl:template match="head"/>
<xsl:template match="h1 | h2 | h3 | h4 | h5 | h6">
<xsl:value-of select="$lf2"/>
<xsl:for-each select="1 to (replace(local-name(),'^h','') cast as xs:integer)">#</xsl:for-each>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="p[@class='toc-line']">
<xsl:value-of select="$lf1"/>
<xsl:text>> </xsl:text>
<xsl:for-each select="ancestor::div[@class='toc']" xml:space="preserve"> </xsl:for-each>
<xsl:text>* </xsl:text>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="p">
<xsl:value-of select="$lf2"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="span[contains(@class,'tag')]">
<!-- double escaped! -->
<xsl:text>&amp;lt;</xsl:text>
<xsl:apply-templates/>
<!-- Heh -->
<xsl:text>></xsl:text>
</xsl:template>
<xsl:template match="code | span[contains(@class,'code')]">
<xsl:text>`</xsl:text>
<xsl:apply-templates/>
<xsl:text>`</xsl:text>
</xsl:template>
<xsl:template match="em">
<xsl:text>*</xsl:text>
<xsl:apply-templates/>
<xsl:text>*</xsl:text>
</xsl:template>
<xsl:template match="q">
<xsl:text>"</xsl:text>
<xsl:apply-templates/>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:key name="element-by-id" match="*[exists(@id)]" use="@id"/>
<xsl:template match="a[starts-with(@href,'#')]">
<xsl:variable name="link-target" select="key('element-by-id',substring-after(@href,'#'))"/>
<xsl:text>[</xsl:text>
<xsl:value-of select="replace(.,'&lt;','&amp;lt;')"/>
<xsl:text>]</xsl:text>
<xsl:text>(#</xsl:text>
<xsl:value-of select="$link-target/*[1] ! normalize-space(.) ! lower-case(.) ! replace(.,'\s','-')"/>
<xsl:text>)</xsl:text>
</xsl:template>
<xsl:template match="pre">
<xsl:text>```&#xA;</xsl:text>
<xsl:value-of select="."/>
<xsl:text>&#xA;```&#xA;</xsl:text>
</xsl:template>
<xsl:template match="pre//text()">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="replace(.,'\s+',' ')"/>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment