Skip to content

Commit

Permalink
added processing of tei:egXML elements
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstadler committed Oct 11, 2016
1 parent c9a2928 commit d7bcdff
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
9 changes: 9 additions & 0 deletions resources/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ $.fn.initDatepicker = function () {
})
};

/* Run Google Code Prettifyer for code examples */
$.fn.googlecodeprettify = function ()
{
prettyPrint();
}

$('.prettyprint').googlecodeprettify();

// remove popovers when clicking somewhere
$('body').on('click', function (e) {
$('[data-original-title]').each(function () {
Expand Down Expand Up @@ -595,3 +603,4 @@ $('#create-newID').on('click', function() {
$('#newID-result span').show();
});
});

104 changes: 104 additions & 0 deletions xsl/var.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@
</xsl:element>
</xsl:template>

<xsl:template match="teix:egXML">
<xsl:element name="div">
<xsl:attribute name="class" select="'panel'"/>
<xsl:element name="pre">
<xsl:attribute name="class">prettyprint</xsl:attribute>
<xsl:element name="code">
<xsl:attribute name="class">language-xml</xsl:attribute>
<xsl:apply-templates select="*|comment()|processing-instruction()" mode="verbatim"/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="tei:code">
<xsl:element name="code">
<xsl:apply-templates select="@xml:id"/>
Expand Down Expand Up @@ -294,5 +307,96 @@
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="*" mode="verbatim">
<xsl:param name="indent-increment" select="' '"/>
<xsl:param name="indent" select="'&#xA;'"/>

<!-- indent the opening tag; unless it's the root element -->
<xsl:if test="not(parent::teix:egXML)">
<xsl:value-of select="$indent"/>
</xsl:if>

<!-- Begin opening tag -->
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>

<!-- Namespaces -->
<xsl:for-each select="namespace::*[not(starts-with(., 'http://www.tei-c.org') or . eq 'http://www.w3.org/XML/1998/namespace')]">
<xsl:text> xmlns</xsl:text>
<xsl:if test="name() != ''">
<xsl:text>:</xsl:text>
<xsl:value-of select="name()"/>
</xsl:if>
<xsl:text>='</xsl:text>
<xsl:call-template name="verbatim-xml">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
<xsl:text>'</xsl:text>
</xsl:for-each>

<!-- Attributes -->
<xsl:for-each select="@*">
<xsl:text> </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>='</xsl:text>
<xsl:call-template name="verbatim-xml">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
<xsl:text>'</xsl:text>
</xsl:for-each>

<!-- End opening tag -->
<xsl:text>&gt;</xsl:text>

<!-- Content (child elements, text nodes, and PIs) -->
<xsl:apply-templates select="node()" mode="verbatim">
<xsl:with-param name="indent" select="concat($indent, $indent-increment)"/>
</xsl:apply-templates>

<xsl:if test="*">
<xsl:value-of select="$indent"/>
</xsl:if>

<!-- Closing tag -->
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:template>

<xsl:template match="text()" mode="verbatim">
<xsl:call-template name="verbatim-xml">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>

<xsl:template match="processing-instruction()" mode="verbatim">
<xsl:text>&lt;?</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>
<xsl:call-template name="verbatim-xml">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
<xsl:text>?&gt;</xsl:text>
</xsl:template>

<xsl:template name="verbatim-xml">
<xsl:param name="text"/>
<xsl:if test="$text != ''">
<xsl:variable name="head" select="substring($text, 1, 1)"/>
<xsl:variable name="tail" select="substring($text, 2)"/>
<xsl:choose>
<xsl:when test="$head = '&amp;'">&amp;amp;</xsl:when>
<xsl:when test="$head = '&lt;'">&amp;lt;</xsl:when>
<xsl:when test="$head = '&gt;'">&amp;gt;</xsl:when>
<xsl:when test="$head = '&#34;'">&amp;quot;</xsl:when>
<xsl:when test="$head = &#34;'&#34;">&amp;apos;</xsl:when>
<xsl:otherwise><xsl:value-of select="$head"/></xsl:otherwise>
</xsl:choose>
<xsl:call-template name="verbatim-xml">
<xsl:with-param name="text" select="$tail"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

0 comments on commit d7bcdff

Please sign in to comment.