Commit 9ab97c3b authored by Dmitry Nikulin's avatar Dmitry Nikulin Committed by Dmitry

Исправлена проблема с регистром тега clipPath

parent 5ee757c6
......@@ -244,8 +244,8 @@ exports.env = exports.jsdom.env = function () {
return req;
};
exports.serializeDocument = function (doc) {
return domToHtml([doc]);
exports.serializeDocument = function (doc, lowerCaseTagNames) {
return domToHtml([doc], lowerCaseTagNames);
};
function processHTML(config) {
......
......@@ -2,72 +2,79 @@
const idlUtils = require("../living/generated/utils");
// Tree traversing
exports.getFirstChild = function (node) {
  • Очень странно, что тут пришлось убирать все exports. Среди них потерялись изменения, внесённые в jsdom.

    Edited
Please register or sign in to reply
  • Я мог бы просто убрать .toLowerCase() в getTagName, но тогда это поведение нельзя было бы изменять. Могу вернуть все на место и изменить только одну строчку.

Please register or sign in to reply
  • Я только к тому, что коммит, в котором предложено решение, должен быть лаконично оформлен, чтобы в нём это самое решение можно было увидеть. Там не должно быть других изменений, за которыми теряется суть. Например, вот зачем в этом коммите ещё и area.svg меняется?

Please register or sign in to reply
  • Спасибо, ошибку понял. Оформил более "чистое" решение в отдельной ветке: ссылка

Please register or sign in to reply
Please register or sign in to reply
return node.childNodes[0];
};
exports.getChildNodes = function (node) {
// parse5 treats template elements specially, assuming you return an array whose single item is the document fragment
const children = node._templateContents ? [node._templateContents] : [];
if (children.length === 0) {
for (let i = 0; i < node.childNodes.length; ++i) {
children.push(idlUtils.implForWrapper(node.childNodes[i]));
class DocumentAdapter {
constructor(lowerCaseTagNames){
this.lowerCaseTagNames = lowerCaseTagNames;
}
getFirstChild (node) {
return node.childNodes[0];
}
getChildNodes (node) {
// parse5 treats template elements specially, assuming you return an array whose single item is the document fragment
const children = node._templateContents ? [node._templateContents] : [];
if (children.length === 0) {
for (let i = 0; i < node.childNodes.length; ++i) {
children.push(idlUtils.implForWrapper(node.childNodes[i]));
}
}
return children;
}
return children;
};
exports.getParentNode = function (node) {
return node.parentNode;
};
getParentNode (node) {
return node.parentNode;
}
exports.getAttrList = function (node) {
return node.attributes;
};
getAttrList (node) {
return node.attributes;
}
// Node data
getTagName (element) {
return this.lowerCaseTagNames?element.tagName.toLowerCase():element.tagName;
}
// Node data
exports.getTagName = function (element) {
return element.tagName.toLowerCase();
};
getNamespaceURI (element) {
return element.namespaceURI || "http://www.w3.org/1999/xhtml";
}
exports.getNamespaceURI = function (element) {
return element.namespaceURI || "http://www.w3.org/1999/xhtml";
};
getTextNodeContent (textNode) {
return textNode.nodeValue;
}
exports.getTextNodeContent = function (textNode) {
return textNode.nodeValue;
};
getCommentNodeContent (commentNode) {
return commentNode.nodeValue;
}
exports.getCommentNodeContent = function (commentNode) {
return commentNode.nodeValue;
};
getDocumentTypeNodeName (doctypeNode) {
return doctypeNode.name;
}
exports.getDocumentTypeNodeName = function (doctypeNode) {
return doctypeNode.name;
};
getDocumentTypeNodePublicId (doctypeNode) {
return doctypeNode.publicId || null;
}
exports.getDocumentTypeNodePublicId = function (doctypeNode) {
return doctypeNode.publicId || null;
};
getDocumentTypeNodeSystemId (doctypeNode) {
return doctypeNode.systemId || null;
}
exports.getDocumentTypeNodeSystemId = function (doctypeNode) {
return doctypeNode.systemId || null;
};
// Node types
isTextNode (node) {
return node.nodeName === "#text";
}
// Node types
exports.isTextNode = function (node) {
return node.nodeName === "#text";
};
isCommentNode (node) {
return node.nodeName === "#comment";
}
exports.isCommentNode = function (node) {
return node.nodeName === "#comment";
};
isDocumentTypeNode (node) {
return node.nodeType === 10;
}
exports.isDocumentTypeNode = function (node) {
return node.nodeType === 10;
};
isElementNode (node) {
return Boolean(node.tagName);
}
}
exports.isElementNode = function (node) {
return Boolean(node.tagName);
};
module.exports = DocumentAdapter;
"use strict";
const parse5 = require("parse5");
const documentAdapter = require("./documentAdapter");
const DocumentAdapter = require("./documentAdapter");
const NODE_TYPE = require("../living/node-type");
const idlUtils = require("../living/generated/utils");
const serializer = new parse5.TreeSerializer(documentAdapter);
exports.domToHtml = function (iterable) {
exports.domToHtml = function (iterable, lowerCaseTagNames) {
if(typeof lowerCaseTagNames === 'undefined') {
lowerCaseTagNames = true;
}
var documentAdapter = new DocumentAdapter(lowerCaseTagNames);
var serializer = new parse5.TreeSerializer(documentAdapter);
let ret = "";
for (const node of iterable) {
if (node.nodeType === NODE_TYPE.DOCUMENT_NODE) {
......
......@@ -16,8 +16,16 @@ function loadCompleteCallback(err, window){
if(err){
console.error("Произошла ошибка при загрузке DOM: "+err.toString());
} else {
// Сериализируем DOM в строку
var serializedSvg = jsdom.serializeDocument(window.document);
/* Сериализируем DOM в строку.
* Опытным путем было выяснено, что регистр "портится" при сериализации.
* В код jsdom внесены изменения: теперь serializeDocument принимает
* необязательный аргумент, отвечающий за перевод имен тегов в нижний
* регистр. Если он не указан или же его значение равно true, то
* serializeDocument ведет себя так же, как и ранее. Если этот параметр
* равен false, то имена тегов не переводятся в нижний регистр.
* В данном случае требуется не переводить имена тегов в нижний регистр,
* поэтому передаем false вторым аргументом. */
var serializedSvg = jsdom.serializeDocument(window.document, false);
try {
fs.writeFileSync(OUTPUT_FILE, serializedSvg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment