Skip to content

Instantly share code, notes, and snippets.

@greystate
Created August 25, 2011 20:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save greystate/1171897 to your computer and use it in GitHub Desktop.
Save greystate/1171897 to your computer and use it in GitHub Desktop.
Include file for handling WYSIWYG content for real (as in: XML instead of effin' CDATA...)
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY NiceUrl "umb:NiceUrl">
<!ENTITY Parse "ucom:Parse">
<!ENTITY wrapper "WYSIWYG">
<!ENTITY nbsp "&#160;">
<!ENTITY badStuff "FONT | font | MARQUEE | marquee | BLINK | blink">
<!ENTITY TinyMCEStuff "span[@class = 'Apple-style-span'] | div[@class = 'xmlblock']">
<!ENTITY blackListedElements "&badStuff; | &TinyMCEStuff;">
<!ENTITY embedded-doctype "&lt;!DOCTYPE WYSIWYG [ &lt;!ENTITY nbsp &quot;&amp;#160;&quot;&gt; ]&gt;">
<!ENTITY EditorContent "concat('&embedded-doctype;&lt;&wrapper;&gt;', ., '&lt;/&wrapper;&gt;')">
]>
<!--
_WYSIWYG.xslt
Helper include
Handles rendering of WYSIWYG content
-->
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
xmlns:ucom="urn:ucomponents.xml"
exclude-result-prefixes="ucom umb"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="*" mode="WYSIWYG">
<xsl:variable name="parsedContent" select="&Parse;(&EditorContent;)" />
<xsl:apply-templates select="$parsedContent/&wrapper;" />
</xsl:template>
<!-- Excerpt mode takes only the first paragraph -->
<xsl:template match="*" mode="WYSIWYG.excerpt">
<xsl:variable name="parsedContent" select="&Parse;(&EditorContent;)" />
<xsl:variable name="wrapper" select="$parsedContent/&wrapper;" />
<xsl:apply-templates select="$wrapper/*[1]" />
</xsl:template>
<!-- Identity transform -->
<xsl:template match="* | text()">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="* | text()" />
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:copy-of select="." />
</xsl:template>
<!-- Rule for the wrapper element -->
<xsl:template match="&wrapper;">
<xsl:apply-templates />
</xsl:template>
<!-- :: Handle custom elements here :: -->
<!-- Wrapped image -->
<xsl:template match="p[img]">
<img src="{img/@src}" />
</xsl:template>
<!-- Floated images -->
<xsl:template match="p[img[contains(@style, 'float: left')]]">
<img src="{img/@src}" class="left" />
</xsl:template>
<xsl:template match="p[img[contains(@style, 'float: right')]]">
<img src="{img/@src}" class="right" />
</xsl:template>
<xsl:template match="&blackListedElements;">
<xsl:apply-templates /><!-- Silently ignore -->
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment