diff options
-rwxr-xr-x | tools/yelp-check.in | 37 | ||||
-rw-r--r-- | xslt/Makefile.am | 1 | ||||
-rw-r--r-- | xslt/comments.xsl | 120 |
3 files changed, 157 insertions, 1 deletions
diff --git a/tools/yelp-check.in b/tools/yelp-check.in index e38d0bd..a30cf02 100755 --- a/tools/yelp-check.in +++ b/tools/yelp-check.in @@ -19,6 +19,7 @@ xsl_mal_link='@XSL_MAL_LINK@' xsl_mal_status='@DATADIR@/xslt/mal-status.xsl' xsl_mal_rng='@DATADIR@/xslt/mal-rng.xsl' +xsl_comments='@DATADIR@/xslt/comments.xsl' urlencode () { # We usually don't want to urlencode slashes, because we're @@ -51,8 +52,9 @@ yelp_usage () { echo "Usage: yelp-check <COMMAND> [OPTIONS] [FILES]" echo "" echo "Commands:" - echo " orphans Find orphaned pages in a Mallard document" + echo " comments Print the editorial comments in a document" echo " links Find broken xref links in a Mallard document" + echo " orphans Find orphaned pages in a Mallard document" echo " status Report the status of Mallard pages" echo " validate Validate files against a DTD or RNG" ) 1>&2 @@ -79,6 +81,14 @@ yelp_usage_orphans () { echo " -c CACHE Use the existing Mallard cache CACHE" ) 1>&2 } +yelp_usage_comments () { + ( + echo "Usage: yelp-check comments <FILES>" + echo "" + echo " Print the editorial comments in the files FILES, using the" + echo " comment element in Mallard and the remark element in DocBook." + ) 1>&2 +} yelp_usage_status () { ( echo "Usage: yelp-check status <FILES>" @@ -270,6 +280,28 @@ yelp_orphans () { exit $ret } +yelp_comments_page () { + ext=`echo "$1" | sed -e 's/.*\.//'` + bname=`basename "$1" ".$ext"` + xsltproc --stringparam basename "$bname" "$xsl_comments" "$1" +} + +yelp_comments () { + if [ "$#" = "0" -o "x$1" = "x--help" ]; then + yelp_usage_comments + exit 1 + fi + for xml in "$@"; do + if [ -d "$xml" ]; then + for page in "$xml"/*.page; do + yelp_comments_page "$page" + done + else + yelp_comments_page "$xml" + fi + done +} + yelp_status () { if [ "$#" = "0" -o "x$1" = "x--help" ]; then yelp_usage_status @@ -409,6 +441,9 @@ yelp_validate () { cmd="$1" shift case "x$cmd" in + "xcomments") + yelp_comments "$@" + ;; "xlinks") yelp_links "$@" ;; diff --git a/xslt/Makefile.am b/xslt/Makefile.am index 4d4aa7c..2c26e6d 100644 --- a/xslt/Makefile.am +++ b/xslt/Makefile.am @@ -1,6 +1,7 @@ xsldir=$(datadir)/yelp-tools/xslt xsl_DATA = \ + comments.xsl \ mal-epub.xsl \ mal-opf.xsl \ mal-ncx.xsl \ diff --git a/xslt/comments.xsl b/xslt/comments.xsl new file mode 100644 index 0000000..61e1cdb --- /dev/null +++ b/xslt/comments.xsl @@ -0,0 +1,120 @@ +<xsl:stylesheet + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:mal="http://projectmallard.org/1.0/" + xmlns:db="http://docbook.org/ns/docbook" + exclude-result-prefixes="mal db" + version="1.0"> + +<xsl:output method="text"/> + +<xsl:param name="basename"/> + +<xsl:template match="/*[namespace-uri(.) = ''] | /db:*"> + <xsl:for-each select="//remark | //db:remark"> + <xsl:text>Page: </xsl:text> + <xsl:value-of select="$basename"/> + <xsl:if test="ancestor::*/@id | ancestor::*/@xml:id"> + <xsl:text>#</xsl:text> + <xsl:value-of select="(ancestor::*/@id | ancestor::*/@xml:id)[last()]"/> + </xsl:if> + <xsl:text>
</xsl:text> + <xsl:if test="@revisionflag"> + <xsl:text>Flag: </xsl:text> + <xsl:value-of select="@revisionflag"/> + <xsl:text>
</xsl:text> + </xsl:if> + <xsl:text>
</xsl:text> + <xsl:call-template name="fill"> + <xsl:with-param name="text" select="normalize-space(.)"/> + <xsl:with-param name="pad" select="' '"/> + </xsl:call-template> + <xsl:text>
</xsl:text> + </xsl:for-each> +</xsl:template> + +<xsl:template match="/mal:page"> + <xsl:for-each select="//mal:comment"> + <xsl:variable name="id"> + <xsl:value-of select="/mal:page/@id"/> + <xsl:if test="ancestor::mal:section[1]/@id"> + <xsl:text>#</xsl:text> + <xsl:value-of select="ancestor::mal:section[1]/@id"/> + </xsl:if> + </xsl:variable> + <xsl:text>Page: </xsl:text> + <xsl:value-of select="$id"/> + <xsl:text>
</xsl:text> + <xsl:if test="mal:cite"> + <xsl:text>From: </xsl:text> + <xsl:value-of select="mal:cite[1]"/> + <xsl:if test="starts-with(mal:cite[1]/@href, 'mailto:')"> + <xsl:text> <</xsl:text> + <xsl:value-of select="substring-after(mal:cite[1]/@href, 'mailto:')"/> + <xsl:text>></xsl:text> + </xsl:if> + <xsl:text>
</xsl:text> + <xsl:if test="mal:cite[1]/@date"> + <xsl:text>Date: </xsl:text> + <xsl:value-of select="mal:cite[1]/@date"/> + <xsl:text>
</xsl:text> + </xsl:if> + </xsl:if> + <xsl:text>
</xsl:text> + <xsl:for-each select="*[not(self::mal:cite)]"> + <xsl:choose> + <xsl:when test="self::mal:p"> + <xsl:call-template name="fill"> + <xsl:with-param name="text" select="normalize-space(.)"/> + <xsl:with-param name="pad" select="' '"/> + </xsl:call-template> + <xsl:text>
</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text> FIXME: <</xsl:text> + <xsl:value-of select="local-name(.)"/> + <xsl:text>>>...</</xsl:text> + <xsl:value-of select="local-name(.)"/> + <xsl:text>></xsl:text> + <xsl:text>

</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> + <xsl:if test="not(*[not(self::mal:cite)])"> + <xsl:text>

</xsl:text> + </xsl:if> + </xsl:for-each> +</xsl:template> + +<xsl:template name="fill"> + <xsl:param name="text" select="''"/> + <xsl:param name="pad" select="''"/> + <xsl:param name="end" select="80 - string-length($pad)"/> + <xsl:param name="col" select="$end"/> + <xsl:choose> + <xsl:when test="$col > string-length($text)"> + <xsl:value-of select="$pad"/> + <xsl:value-of select="$text"/> + <xsl:text>
</xsl:text> + </xsl:when> + <xsl:when test="substring($text, $col, 1) = ' '"> + <xsl:value-of select="$pad"/> + <xsl:value-of select="substring($text, 0, $col)"/> + <xsl:text>
</xsl:text> + <xsl:call-template name="fill"> + <xsl:with-param name="text" select="substring($text, $col + 1)"/> + <xsl:with-param name="end" select="$end"/> + <xsl:with-param name="pad" select="$pad"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="fill"> + <xsl:with-param name="text" select="$text"/> + <xsl:with-param name="end" select="$end"/> + <xsl:with-param name="pad" select="$pad"/> + <xsl:with-param name="col" select="$col - 1"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +</xsl:stylesheet> |