Created
August 25, 2011 20:54
-
-
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...)
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
<?xml version="1.0" encoding="utf-8" ?> | |
<!DOCTYPE xsl:stylesheet [ | |
<!ENTITY NiceUrl "umb:NiceUrl"> | |
<!ENTITY Parse "ucom:Parse"> | |
<!ENTITY wrapper "WYSIWYG"> | |
<!ENTITY nbsp " "> | |
<!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 "<!DOCTYPE WYSIWYG [ <!ENTITY nbsp "&#160;"> ]>"> | |
<!ENTITY EditorContent "concat('&embedded-doctype;<&wrapper;>', ., '</&wrapper;>')"> | |
]> | |
<!-- | |
_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