3-Round-Stones / callimachus

Callimachus is a highly scalable platform for creating and running data-driven websites
Other
95 stars 24 forks source link

Fails to save article with programlisting when language is set #254

Closed edwardsph closed 7 years ago

edwardsph commented 8 years ago

Issue with v1.5.0, tested in Chrome on Windows 10. Create a docbook article, insert a code snippet with no language set and save the page. That works, but set a language for the snippet and you get an error on saving; Document is invalid systemId: ....; lineNumber: 12; columnNumber: 38; attribute "class" not allowed here; expected attribute "annotations", "arch", "audience", "condition", "conformance", "dir", "language", "linkend", "os", "remap", "revision", "revisionflag", "role", "security", "userlevel", "vendor", "version", "wordsize", "xl:actuate", "xl:arcrole", "xl:href", "xl:role", "xl:show", "xl:title", "xl:type", "xml:base", "xml:id", "xml:lang" or "xreflabel"

You can also see the issue if you open an existing article that has a code snippet with a language set., Simply click save with no edits and the same thing occurs.

The code element and language attribute are translated to: <code class="language-bash"> and I think the problem is related to issue #229. One of its changes was to include the clause "[not(@class)]" in article-save.xsl:

<xsl:template match="xhtml:pre/xhtml:code[not(@class)]">
    <programlisting>
        <xsl:call-template name="id" />
        <xsl:if test="matches(@class,'language-\S')">
            <xsl:attribute name="language">
                <xsl:value-of select="replace(@class,'^.*language-(\S+).*$','$1')" />
            </xsl:attribute>
        </xsl:if>
        <xsl:value-of select="." />
    </programlisting>
</xsl:template>

This no longer makes sense as the class attribute is used within the template but the template is only applied if there is no class attribute. The snippet generated by the editor is not handled by this template and drops through to one intended for inline formatting.

The only solution for now is to remove the language settings of any snippets when you want to edit the file.