benjycui / jsonml.js Goto Github PK
View Code? Open in Web Editor NEWJsonML-related tools for losslessly converting between XML/HTML and JSON, including mixed-mode XML. http://jsonml.org
License: MIT License
JsonML-related tools for losslessly converting between XML/HTML and JSON, including mixed-mode XML. http://jsonml.org
License: MIT License
When calling utils.appendChild
with a child fragment, the fragment is mutated, resulting in an empty array.
const jml = ['div'];
const fragment = ['', 'hello world'];
utils.appendChild(jml, fragment);
// jml === ['div', 'hello world']
// fragment === []
Ideally, the fragment should not be mutated.
See discussion: #5 (comment)
Original comments: #5 (comment)
Calling utils.appendChild
with a raw element throws an error.
const html = require('jsonml.js/lib/html');
const utils = require('jsonml.js/lib/utils');
const jml = ['div']
const rawEl = html.raw('foo');
utils.appendChild(jml, rawEl); // TypeError: exports.isRaw is not a function
Indeed, exports.isRaw
is not defined within utils.js
. It is, however, defined within html.js
. So, the fix should be fairly straightforward.
When writing tests for the utils methods, I came across some logic that was confusing:
https://github.com/benjycui/jsonml.js/blob/master/lib/utils.js#L132
} else if (child || !parent.length) {
// append
parent.push(child);
This allows for some unclear behavior, particularly when allowing exception for a parent with no length.
const jml = [];
utils.appendChild(jml, '');
// jml === ['']
const jml = [];
utils.appendChild(jml, ['p', 'hello']);
// jml === [ ['p', 'hello'] ]
Is this a real use case or an edge case bug? I'm guessing this would never be desired and should probably not be allowed.
Hey @benjycui,
I'm using this module in some libraries and applications and it's been helpful. I'd like to contribute back and help with the maintenance of the project. Are you accepting contributions at this time? Where is the best place to begin? It looks like there's a need for complete test coverage, eslint cleanup, and documentation. If you're interested, we could begin opening issues to track this work.
I've gone ahead and opened a few PRs that should help move things along:
在 windows
下面报错:
https://github.com/benjycui/jsonml.js/blob/master/lib/utils.js#L68
windows
下面才有这个问题,mac
下面同样的代码运行没有问题
jsdom
is too heavy.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.