padding-left: 55px;
}
-.htmlview *[x-node='rdf:RDF'] {
+.htmlview *[x-node='RDF'] {
display: none;
}
}
setTimeout(function() {
html2xml({
- xml: serializer.serializeToString($('#html-view div').get(0)),
+ htmlElement: $('#html-view div').get(0),
+ /* xml: serializer.serializeToString($('#html-view div').get(0)), */
success: function(text) {
editor.setCode(text);
if (!dontBlock) {
result.push('<');
result.push(element.tagName);
- // Mozilla nie uważa deklaracji namespace za atrybuty
+ // Mozilla nie uważa deklaracji namespace za atrybuty | --lqc: bo nie są one atrybutami!
var ns = element.tagName.indexOf(':');
if (ns != -1 && $.browser.mozilla) {
result.push(' xmlns:');
function xml2html(options) {
withStylesheets(function() {
- var xml = options.xml.replace(/\/\s+/g, '<br />');
+ var xml = options.xml.replace(/\/\s+/g, '<br />');
var parser = new DOMParser();
var serializer = new XMLSerializer();
- var doc = parser.parseFromString(xml, 'text/xml');
+ var doc = parser.parseFromString(xml, 'text/xml');
var error = $('parsererror', doc);
if (error.length == 0) {
- doc = xml2htmlStylesheet.transformToFragment(doc, document);
+ doc = xml2htmlStylesheet.transformToDocument(doc);
+ console.log(doc);
error = $('parsererror', doc);
}
if (error.length > 0 && options.error) {
options.error(error.text());
- } else {
- options.success(doc.firstChild);
+ } else {
+ options.success(document.importNode(doc.documentElement, true));
}
}, function() { options.error && options.error('Nie udało się załadować XSLT'); });
}
+/* USEFULL CONSTANTS */
+const ELEMENT_NODE = 1;
+const ATTRIBUTE_NODE = 2;
+const TEXT_NODE = 3;
+const CDATA_SECTION_NODE = 4;
+const ENTITY_REFERENCE_NODE = 5;
+const ENTITY_NODE = 6;
+const PROCESSING_INSTRUCTION_NODE = 7;
+const COMMENT_NODE = 8;
+const DOCUMENT_NODE = 9;
+const DOCUMENT_TYPE_NODE = 10;
+const DOCUMENT_FRAGMENT_NODE = 11;
+const NOTATION_NODE = 12;
+const XATTR_RE = /^x-attr-name-(.*)$/;
-function html2xml(options) {
- withStylesheets(function() {
- var xml = options.xml;
- var parser = new DOMParser();
- var serializer = new XMLSerializer();
- var doc = parser.parseFromString(xml, 'text/xml');
- var error = $('parsererror', doc.documentElement);
+const ELEM_START = 1;
+const ELEM_END = 2;
- if (error.length == 0) {
- doc = html2xmlStylesheet.transformToDocument(doc);
- error = $('parsererror', doc.documentElement);
- }
-
- if (error.length > 0 && options.error) {
- options.error(error.text());
- } else {
- if (options.inner) {
- var result = [];
- for (var i = 0; i < doc.documentElement.childNodes.length; i++) {
- result.push(serialize(doc.documentElement.childNodes[i]).join(''));
- };
- options.success(result.join(''));
- } else {
- options.success(serialize(doc.documentElement).join(''));
- }
- }
- }, function() { options.error && options.error('Nie udało się załadować XSLT'); });
+const NAMESPACES = {
+ undefined: "",
+ null: "",
+ "": "",
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf:",
+ "http://purl.org/dc/elements/1.1/": "dc:",
+ "http://www.w3.org/XML/1998/namespace": "xml:"
};
+function html2text(rootElement) {
+ var stack = [];
+ var result = "";
+
+ stack.push([ELEM_START, rootElement]);
+ console.log("SERIALIZING")
+
+ while( stack.length > 0) {
+ var pair = stack.pop();
+
+ var event = pair[0];
+ var node = pair[1];
+
+ // console.log("NODE", event, node);
+
+ if(event == ELEM_END) {
+ result += "</" + node + ">\n";
+ continue;
+ };
+
+ switch(node.nodeType) {
+ case ELEMENT_NODE:
+ if(!node.hasAttribute('x-node'))
+ break;
+
+ var tag_name = NAMESPACES[node.getAttribute('x-ns')] + node.getAttribute('x-node');
+ // console.log("ELEMENT: ", tag_name);
+
+ /* retrieve attributes */
+ var attr_ids = [];
+ for(var i=0; i < node.attributes.length; i++) {
+ var attr = node.attributes.item(i);
+
+ // check if name starts with "x-attr-name"
+ var m = attr.name.match(XATTR_RE);
+ if(m !== null)
+ attr_ids.push(m[1]);
+
+ };
+
+ result += '<' + tag_name;
+
+ $.each(attr_ids, function() {
+ result += ' ' + NAMESPACES[node.getAttribute('x-attr-ns-'+this)];
+ result += node.getAttribute('x-attr-name-'+this);
+ result += '="'+node.getAttribute('x-attr-value-'+this) +'"';
+ });
+ result += '>'
+
+ stack.push([ELEM_END, tag_name]);
+ for(var i = node.childNodes.length-1; i >= 0; i--)
+ stack.push([ELEM_START, node.childNodes.item(i)]);
+
+ break;
+ case TEXT_NODE:
+ result += node.nodeValue;
+ break;
+ }
+ }
+
+ return result;
+}
+
+function html2xml(options) {
+ try {
+ return options.success(html2text(options.htmlElement));
+ } catch(e) {
+ options.error("Nie udało się zserializować tekstu:" + e)
+ }
+};
\ No newline at end of file
+++ /dev/null
-<xsl:stylesheet \r
- version="1.0"\r
-\r
- xmlns:html="http://www.w3.org/1999/xhtml"\r
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\r
- xmlns:dc="http://purl.org/dc/elements/1.1/"\r
->\r
-\r
- <xsl:output method="xml" encoding="utf-8" indent="no" omit-xml-declaration="yes" />\r
- <!--\r
- Ten dokument definiuję przekształcenie odwrotne do wl2html\r
- -->\r
-\r
- <xsl:template match="comment()"><xsl:copy /></xsl:template>\r
-\r
- <!-- libxslt has fuck-ed prorities -->\r
- <!-- <xsl:template match="@*[not(starts-with(name(), 'x-')) and name() != 'class']">\r
- <xsl:message>Boom!: <xsl:value-of select="name()" /></xsl:message>\r
- </xsl:template> -->\r
-\r
- <xsl:template match="@*" priority="0" />\r
-\r
- <!-- Specjalne reguły dla przypisów -->\r
- <xsl:template match="*[@x-annotation-box]|*[@class='theme-text-list']">\r
- <xsl:apply-templates select="node()" />\r
- </xsl:template>\r
-\r
- <xsl:template match="*[@x-node]">\r
- <xsl:element name="{@x-node}" namespace="{@x-ns}">\r
- <xsl:apply-templates select="@*" />\r
- <xsl:apply-templates select="node()" />\r
- </xsl:element>\r
- </xsl:template> \r
- \r
- <xsl:template match="*[@x-node = 'out-of-flow-text']">\r
- <xsl:apply-templates select="child::node()" />\r
- </xsl:template>\r
-\r
- <xsl:template match="*[@x-node = 'out-of-flow-text']/text()"><xsl:value-of select="." /></xsl:template>\r
-\r
- <!-- Specjalne reguły dla wersów -->\r
- <xsl:template match="*[@x-node = 'wers']">\r
- <xsl:apply-templates select="node()" />\r
- <xsl:if test="count(following-sibling::*[starts-with(@x-node, 'wers')]) > 0"><xsl:text>/
</xsl:text></xsl:if>\r
- </xsl:template>\r
-\r
- <xsl:template match="*[starts-with(@x-node, 'wers_')]">\r
- <xsl:element name="{@x-node}" namespace="{@x-ns}"><xsl:apply-templates select="@*|node()" /></xsl:element>\r
- <xsl:if test="count(following-sibling::*[starts-with(@x-node, 'wers')]) > 0"><xsl:text>/
</xsl:text></xsl:if>\r
- </xsl:template>\r
- \r
- <xsl:template match="@*[starts-with(name(), 'x-attr-qname-')]">\r
- <xsl:variable name="attr-id" select="substring-after(name(), 'x-attr-qname-')" />\r
- <xsl:attribute name="{.}" namespace="{parent::*/@*[name() = concat('x-attr-ns-', $attr-id)]}">\r
- <xsl:value-of select="parent::*/@*[name() = concat('x-attr-value-', $attr-id)]" />\r
- </xsl:attribute>\r
- </xsl:template>\r
-\r
- <!-- upper case duplicates for the brain-dead Firefox -->\r
-\r
- <xsl:template match="@*[starts-with(name(), 'X-ATTR-QNAME-')]">\r
- <xsl:variable name="attr-id" select="substring-after(name(), 'X-ATTR-QNAME-')" />\r
- <xsl:attribute name="{.}" namespace="{parent::*/@*[name() = concat('X-ATTR-NS-', $attr-id)]}">\r
- <xsl:value-of select="parent::*/@*[name() = concat('X-ATTR-VALUE-', $attr-id)]" />\r
- </xsl:attribute>\r
- </xsl:template>\r
-\r
- <xsl:template match="*[@X-ANNOTATION-BOX]">\r
- <xsl:apply-templates select="node()" />\r
- </xsl:template>\r
-\r
- <xsl:template match="*[@X-NODE]">\r
- <xsl:element name="{@X-NODE}" namespace="{@X-NS}">\r
- <xsl:apply-templates select="@*" />\r
- <xsl:apply-templates select="node()" />\r
- </xsl:element>\r
- </xsl:template> \r
- \r
- <xsl:template match="*[@X-NODE = 'out-of-flow-text']" priority="1">\r
- <xsl:apply-templates select="child::node()" />\r
- </xsl:template>\r
- \r
- <xsl:template match="*[@X-NODE = 'out-of-flow-text']/text()"><xsl:value-of select="." /></xsl:template>\r
-\r
- <!-- Specjalne reguły dla wersów -->\r
- <xsl:template match="*[@X-NODE = 'wers']">\r
- <xsl:apply-templates select="node()" />\r
- <xsl:if test="count(following-sibling::*[starts-with(@X-NODE, 'wers')]) > 0"><xsl:text>/
</xsl:text></xsl:if>\r
- </xsl:template>\r
-\r
- <xsl:template match="*[starts-with(@X-NODE, 'wers_')]">\r
- <xsl:element name="{@X-NODE}" namespace="{@X-NS}"><xsl:apply-templates select="@*|node()" /></xsl:element>\r
- <xsl:if test="count(following-sibling::*[starts-with(@X-NODE, 'wers')]) > 0"><xsl:text>/
</xsl:text></xsl:if>\r
- </xsl:template>\r
- \r
- <xsl:template match="*" />\r
- \r
- \r
-</xsl:stylesheet>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Dokument ten opisuje jednoznaczne przekształcenie WLML 0.1 -> XHTML.
-->
- <xsl:output method="xml" encoding="utf-8" indent="no" omit-xml-declaration="yes" />
-
- <!-- <xsl:template match="/">
- <xsl:apply-templates select="chunk|utwor" />
- </xsl:template> -->
+ <xsl:output method="html" omit-xml-declaration="yes" encoding="utf-8" indent="no" />
<!--
Base tag for rendering a fragment of text
<xsl:template match="utwor">
<div>
<xsl:call-template name="standard-attributes" />
- <xsl:apply-templates select="child::* | text()">
+ <xsl:apply-templates select="child::node()">
<xsl:with-param name="mixed" select="false()" />
</xsl:apply-templates>
</div>
<xsl:param name="extra-class" />
<xsl:attribute name="class"><xsl:value-of select="local-name()" /><xsl:text> </xsl:text><xsl:value-of select="$extra-class" /></xsl:attribute>
- <!-- we use upper-case attribute names, so we don't have to wory about HTML parsers -->
- <xsl:attribute name="x-node"><xsl:value-of select="name()" /></xsl:attribute>
+ <xsl:attribute name="x-node"><xsl:value-of select="local-name()" /></xsl:attribute>
<xsl:if test="local-name() != name()">
<xsl:attribute name="x-ns"><xsl:value-of select="namespace-uri()" /></xsl:attribute>
<xsl:for-each select="@*">
<xsl:variable name="id" select="generate-id()" />
<xsl:attribute name="x-attr-value-{$id}"><xsl:value-of select="."/></xsl:attribute>
- <xsl:attribute name="x-attr-qname-{$id}"><xsl:value-of select="name()"/></xsl:attribute>
+ <xsl:attribute name="x-attr-name-{$id}"><xsl:value-of select="local-name()"/></xsl:attribute>
<xsl:if test="namespace-uri()">
<xsl:attribute name="x-attr-ns-{$id}"><xsl:value-of select="namespace-uri()"/></xsl:attribute>
</xsl:if>