Skip to content

Commit

Permalink
experimental support for embedded SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
reschke committed Feb 13, 2016
1 parent 9937dd1 commit 9c1f795
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 52 deletions.
13 changes: 11 additions & 2 deletions clean-for-DTD.xslt
@@ -1,7 +1,7 @@
<!--
Strip rfc2629.xslt extensions, generating XML input for MTR's xml2rfc
Copyright (c) 2006-2015, Julian Reschke (julian.reschke@greenbytes.de)
Copyright (c) 2006-2016, Julian Reschke (julian.reschke@greenbytes.de)
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -34,9 +34,10 @@
xmlns:ed="http://greenbytes.de/2002/rfcedit"
xmlns:grddl="http://www.w3.org/2003/g/data-view#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:x="http://purl.org/net/xml2rfc/ext"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="ed grddl rdf x xhtml"
exclude-result-prefixes="ed grddl rdf svg x xhtml"
>

<!-- re-use some of the default RFC2629.xslt rules -->
Expand Down Expand Up @@ -662,6 +663,14 @@
<xsl:template name="insert-end-code"/>
<xsl:template match="@x:is-code-component" mode="cleanup"/>

<xsl:template match="artwork[svg:svg]" mode="cleanup">
<xsl:call-template name="warning">
<xsl:with-param name="inline" select="'no'"/>
<xsl:with-param name="msg">SVG image removed.</xsl:with-param>
</xsl:call-template>
<artwork>(see SVG image in HTML version)</artwork>
</xsl:template>

<xsl:template match="artwork" mode="cleanup">
<xsl:variable name="content2"><xsl:apply-templates select="."/></xsl:variable>
<xsl:variable name="content" select="translate($content2,'&#160;&#x2500;&#x2502;&#x2508;&#x250c;&#x2510;&#x2514;&#x2518;&#x251c;&#x2524;',' -|+++++++')"/>
Expand Down
60 changes: 40 additions & 20 deletions rfc2629-ext.rnc
Expand Up @@ -11,6 +11,9 @@ namespace grddl = "http://www.w3.org/2003/g/data-view#"
# Define RDF namespace
namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

# Define SVG namespace
namespace svg = "http://www.w3.org/2000/svg"

# Include rfc2629bis RNC grammar
include "rfc2629.rnc" {

Expand All @@ -32,24 +35,26 @@ include "rfc2629.rnc" {
artwork =
element artwork {
attlist.artwork,
(TEXT
| eref
| iref
| spanx
| xref
| v3_em
| v3_strong
| x_abnf-char-sequence
| x_bb
| x_bc
| x_bcp14
| x_bt
| x_highlight
| x_length-of
| x_parse-xml
| x_ref
| x_span
| x_x)*
( v3_svg |
(TEXT
| eref
| iref
| spanx
| xref
| v3_em
| v3_strong
| x_abnf-char-sequence
| x_bb
| x_bc
| x_bcp14
| x_bt
| x_highlight
| x_length-of
| x_parse-xml
| x_ref
| x_span
| x_x)*
)
}

# Redefine <back> to allow boilerplate
Expand Down Expand Up @@ -485,7 +490,7 @@ v3_sup =
(TEXT)*
}

# Monospaced Text (see Section 12.20)
# Monospaced Text (see Section 12.21)
v3_tt =
element tt {
(TEXT
Expand All @@ -494,14 +499,29 @@ v3_tt =
| x_ref)*
}

# Unordered List (see Section 12.21)
# Unordered List (see Section 12.22)
v3_ul =
element ul {
attribute anchor { xsd:ID }?,
attribute empty { TEXT }?,
v3_li+
}

# SVG (see Section 12.20)
v3_svg =
element svg:svg {
(attribute * { text }
| text
| anySVGElement)*
}

anySVGElement =
element svg:* {
(attribute * { text }
| text
| anySVGElement)*
}

# Conversion to ABNF char sequence (see Section 11.1)
x_abnf-char-sequence =
element x:abnf-char-sequence {
Expand Down
22 changes: 17 additions & 5 deletions rfc2629.xslt
Expand Up @@ -40,10 +40,11 @@
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:saxon="http://saxon.sf.net/"
xmlns:saxon-old="http://icl.com/saxon"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:x="http://purl.org/net/xml2rfc/ext"
xmlns:xhtml="http://www.w3.org/1999/xhtml"

exclude-result-prefixes="date ed exslt msxsl myns rdf saxon saxon-old x xhtml"
exclude-result-prefixes="date ed exslt msxsl myns rdf saxon saxon-old svg x xhtml"
>

<xsl:strip-space elements="abstract author back figure front list middle note postal reference references rfc section texttable"/>
Expand Down Expand Up @@ -817,6 +818,10 @@
</xsl:if>
</xsl:template>

<xsl:template match="artwork[svg:svg]">
<xsl:copy-of select="svg:svg"/>
</xsl:template>

<xsl:template match="artwork|sourcecode">
<xsl:if test="not(ancestor::ed:del) and $xml2rfc-ext-parse-xml-in-artwork='yes' and function-available('myns:parseXml')" use-when="function-available('myns:parseXml')">
<xsl:if test="contains(.,'&lt;?xml')">
Expand Down Expand Up @@ -5047,7 +5052,14 @@ ul.ind li li {
font-weight: normal;
line-height: 150%;
margin-left: 0em;
}<xsl:if test="//svg:svg">
@namespace svg url(http://www.w3.org/2000/svg);
svg|svg {
margin-left: 3em;
}
svg {
margin-left: 3em;
}</xsl:if>
.avoidbreakinside {
page-break-inside: avoid;
}
Expand Down Expand Up @@ -8112,11 +8124,11 @@ dd, li, p {
<xsl:variable name="gen">
<xsl:text>http://greenbytes.de/tech/webdav/rfc2629.xslt, </xsl:text>
<!-- when RCS keyword substitution in place, add version info -->
<xsl:if test="contains('$Revision: 1.763 $',':')">
<xsl:value-of select="concat('Revision ',normalize-space(translate(substring-after('$Revision: 1.763 $', 'Revision: '),'$','')),', ')" />
<xsl:if test="contains('$Revision: 1.764 $',':')">
<xsl:value-of select="concat('Revision ',normalize-space(translate(substring-after('$Revision: 1.764 $', 'Revision: '),'$','')),', ')" />
</xsl:if>
<xsl:if test="contains('$Date: 2016/02/12 13:46:41 $',':')">
<xsl:value-of select="concat(normalize-space(translate(substring-after('$Date: 2016/02/12 13:46:41 $', 'Date: '),'$','')),', ')" />
<xsl:if test="contains('$Date: 2016/02/13 15:06:48 $',':')">
<xsl:value-of select="concat(normalize-space(translate(substring-after('$Date: 2016/02/13 15:06:48 $', 'Date: '),'$','')),', ')" />
</xsl:if>
<xsl:value-of select="concat('XSLT vendor: ',system-property('xsl:vendor'),' ',system-property('xsl:vendor-url'))" />
</xsl:variable>
Expand Down
9 changes: 8 additions & 1 deletion rfc2629toFO.xslt
Expand Up @@ -37,9 +37,10 @@
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:myns="mailto:julian.reschke@greenbytes.de?subject=rcf2629.xslt"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:x="http://purl.org/net/xml2rfc/ext"

exclude-result-prefixes="ed exslt msxsl myns rdf x"
exclude-result-prefixes="ed exslt msxsl myns rdf svg x"
>

<xsl:import href="rfc2629.xslt" />
Expand Down Expand Up @@ -177,6 +178,12 @@
</xsl:choose>
</xsl:template>

<xsl:template match="artwork[svg:svg]">
<fo:instream-foreign-object>
<xsl:copy-of select="svg:svg"/>
</fo:instream-foreign-object>
</xsl:template>

<xsl:template match="artwork|sourcecode">
<fo:block>
<xsl:if test="not(ancestor::figure)">
Expand Down
72 changes: 51 additions & 21 deletions rfc2629xslt.xml
Expand Up @@ -1433,6 +1433,14 @@ Content-Length: &lt;x:length-of target="req"/>
</t>
</section>

<section title="svg Element" anchor="v3.svg">
<iref item="V3 Extension Elements" subitem="svg" primary="true"/>
<iref item="svg V3 Extension Element" primary="true"/>
<t>
See <xref target="XML2RFCV3" x:fmt="of" x:rel="#element.svg"/>.
</t>
</section>

<section title="tt Element" anchor="v3.tt">
<iref item="V3 Extension Elements" subitem="tt" primary="true"/>
<iref item="tt V3 Extension Element" primary="true"/>
Expand All @@ -1448,6 +1456,7 @@ Content-Length: &lt;x:length-of target="req"/>
See <xref target="XML2RFCV3" x:fmt="of" x:rel="#element.ul"/>.
</t>
</section>

</section>

<section title="Utilities" anchor="utilities">
Expand Down Expand Up @@ -2090,10 +2099,10 @@ ocasionally save.
<front>
<title>The "xml2rfc" version 3 Vocabulary</title>
<author initials="P." surname="Hoffman" fullname="Paul Hoffman"/>
<date month="February" year="2016"/>
<date month="January" year="2016"/>
</front>
<seriesInfo name="Internet-Draft" value="draft-iab-xml2rfc-03"/>
<x:source href="/projects/ietf/xml2rfc/vocabulary/v3/iab03/draft-iab-xml2rfc-latest.xml"/>
<seriesInfo name="Internet-Draft" value="draft-iab-xml2rfc-02"/>
<x:source href="/projects/ietf/xml2rfc/vocabulary/v3/iab02/draft-iab-xml2rfc-latest.xml"/>
</reference>

</references>
Expand Down Expand Up @@ -2123,6 +2132,9 @@ namespace grddl = "http://www.w3.org/2003/g/data-view#"
<em># Define RDF namespace</em>
namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

<em># Define SVG namespace</em>
namespace svg = "http://www.w3.org/2000/svg"

<em># Include rfc2629bis RNC grammar</em>
include "rfc2629.rnc" {

Expand All @@ -2144,24 +2156,26 @@ include "rfc2629.rnc" {
artwork =
element artwork {
attlist.artwork,
(TEXT
<strong>| eref</strong>
<strong>| iref</strong>
<strong>| spanx</strong>
<strong>| xref</strong>
<strong>| <x:ref>v3_em</x:ref></strong>
<strong>| <x:ref>v3_strong</x:ref></strong>
<strong>| <x:ref>x_abnf-char-sequence</x:ref></strong>
<strong>| <x:ref>x_bb</x:ref></strong>
<strong>| <x:ref>x_bc</x:ref></strong>
<strong>| <x:ref>x_bcp14</x:ref></strong>
<strong>| <x:ref>x_bt</x:ref></strong>
<strong>| <x:ref>x_highlight</x:ref></strong>
<strong>| <x:ref>x_length-of</x:ref></strong>
<strong>| <x:ref>x_parse-xml</x:ref></strong>
<strong>| <x:ref>x_ref</x:ref></strong>
<strong>| <x:ref>x_span</x:ref></strong>
<strong>| <x:ref>x_x</x:ref></strong>)*
( <strong><x:ref>v3_svg</x:ref> |
</strong>(TEXT
<strong>| eref</strong>
<strong>| iref</strong>
<strong>| spanx</strong>
<strong>| xref</strong>
<strong>| <x:ref>v3_em</x:ref></strong>
<strong>| <x:ref>v3_strong</x:ref></strong>
<strong>| <x:ref>x_abnf-char-sequence</x:ref></strong>
<strong>| <x:ref>x_bb</x:ref></strong>
<strong>| <x:ref>x_bc</x:ref></strong>
<strong>| <x:ref>x_bcp14</x:ref></strong>
<strong>| <x:ref>x_bt</x:ref></strong>
<strong>| <x:ref>x_highlight</x:ref></strong>
<strong>| <x:ref>x_length-of</x:ref></strong>
<strong>| <x:ref>x_parse-xml</x:ref></strong>
<strong>| <x:ref>x_ref</x:ref></strong>
<strong>| <x:ref>x_span</x:ref></strong>
<strong>| <x:ref>x_x</x:ref></strong>)*
)
}

<em># Redefine &lt;back> to allow boilerplate</em>
Expand Down Expand Up @@ -2633,6 +2647,22 @@ attlist.xref &amp;=
<x:ref>v3_li</x:ref>+
}

<em anchor="v3_svg"><iref item="svg V3 Extension Element"/><iref item="V3 Extension Elements" subitem="svg"
/># SVG (see <xref target="v3.svg"/>)</em>
<x:ref>v3_svg</x:ref> =
element svg:svg {
(attribute * { text }
| text
| anySVGElement)*
}

anySVGElement =
element svg:* {
(attribute * { text }
| text
| anySVGElement)*
}

<em anchor="x_abnf-char-sequence"><iref item="abnf-char-sequence Extension Element"/><iref item="Extension Elements" subitem="abnf-char-sequence"
/># Conversion to ABNF char sequence (see <xref target="ext.element.abnf-char-sequence"/>)</em>
<x:ref>x_abnf-char-sequence</x:ref> =
Expand Down
6 changes: 3 additions & 3 deletions xsl11toFop.xslt
@@ -1,7 +1,7 @@
<!--
Transform XSL 1.1 extensions to Apache FOP
Copyright (c) 2007-2010, Julian Reschke (julian.reschke@greenbytes.de)
Copyright (c) 2007-2016, Julian Reschke (julian.reschke@greenbytes.de)
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -57,8 +57,8 @@

<!-- remove third-party extensions -->

<xsl:template match="*[not(ancestor::fo:declarations) and namespace-uri()!='http://www.w3.org/1999/XSL/Format' and namespace-uri()!='http://xml.apache.org/fop/extensions']" />
<xsl:template match="@*[not(ancestor::fo:declarations) and namespace-uri()!='' and namespace-uri()!='http://www.w3.org/1999/XSL/Format' and namespace-uri()!='http://xml.apache.org/fop/extensions']" />
<xsl:template match="*[not(ancestor::fo:declarations) and namespace-uri()!='http://www.w3.org/1999/XSL/Format' and namespace-uri()!='http://www.w3.org/2000/svg' and namespace-uri()!='http://xml.apache.org/fop/extensions']" />
<xsl:template match="@*[not(ancestor::fo:declarations) and namespace-uri()!='' and namespace-uri()!='http://www.w3.org/2000/svg' and namespace-uri()!='http://www.w3.org/1999/XSL/Format' and namespace-uri()!='http://xml.apache.org/fop/extensions']" />

<!-- index-page-citation-list -->

Expand Down

0 comments on commit 9c1f795

Please sign in to comment.