forked from commonmark/cmark
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for tables and strike-through text in the XSLT (#117)
* Add support for tables and strike-through text in the XSLT * Update xml2md.xsl * Add specific stylesheet for tables and strike-through * Add comment
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
xml2md_gfm.xsl | ||
============== | ||
This XSLT stylesheet is a complement to xml2md.xsl with templates supporting GitHub-flavored Markdown extensions (tables, strike-through). | ||
--> | ||
|
||
<xsl:stylesheet | ||
version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:md="http://commonmark.org/xml/1.0"> | ||
|
||
|
||
<!-- Import commonmark XSL --> | ||
|
||
<xsl:import href="xml2md.xsl"/> | ||
<xsl:template match="/"> | ||
<xsl:apply-imports/> | ||
</xsl:template> | ||
|
||
<!-- params --> | ||
|
||
<xsl:output method="text" encoding="utf-8"/> | ||
|
||
|
||
<!-- Table --> | ||
|
||
<xsl:template match="md:table"> | ||
<xsl:apply-templates select="." mode="indent-block"/> | ||
<xsl:apply-templates select="md:*"/> | ||
</xsl:template> | ||
|
||
<xsl:template match="md:table_header"> | ||
<xsl:text>| </xsl:text> | ||
<xsl:apply-templates select="md:*"/> | ||
<xsl:text>
 | </xsl:text> | ||
<xsl:for-each select="md:table_cell"> | ||
<xsl:choose> | ||
<xsl:when test="@align = 'right'"> | ||
<xsl:text> ---: |</xsl:text> | ||
</xsl:when> | ||
<xsl:when test="@align = 'left'"> | ||
<xsl:text> :--- |</xsl:text> | ||
</xsl:when> | ||
<xsl:when test="@align = 'center'"> | ||
<xsl:text> :---: |</xsl:text> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:text> --- |</xsl:text> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:for-each> | ||
<xsl:text>
</xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="md:table_cell"> | ||
<xsl:apply-templates select="md:*"/> | ||
<xsl:text>| </xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="md:table_row"> | ||
<xsl:text>| </xsl:text> | ||
<xsl:apply-templates select="md:*"/> | ||
<xsl:text>
</xsl:text> | ||
</xsl:template> | ||
|
||
|
||
<!-- Striked-through --> | ||
|
||
<xsl:template match="md:strikethrough"> | ||
<xsl:text>~~</xsl:text> | ||
<xsl:apply-templates select="md:*"/> | ||
<xsl:text>~~</xsl:text> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |