-
-
Notifications
You must be signed in to change notification settings - Fork 335
Closed
Labels
Feature-RequestNew features suggested by usersNew features suggested by users
Description
- Are you running the latest version?
- Have you included sample input, output, error, and expected output?
- Have you checked if you are using correct configuration?
- Did you try online tool?
Description
We often need to parse/build HTML and not traditional XML with this tool. However, in HTML world, blunt force on the empty tags is not good. We would like to see an empty div, span, p, etc...remain in tact with a close and open tag. However, for say a br or hr, we would rather suppress it. Would love to see a configurable list for which tags we suppress in the XmlBuilder instead of a global boolean.
Input
- Create a simple XML string with an empty tag you DO NOT want to suppress and one you do want to supress.
- Use XmlParser
- Use an XmlBuilder to regenerate the XML from the output in step 2
Code
const sample = '<article><div style="padding: 20px"></div><br/></article>';
const sharedFastXmlConfiguration = {};
const parser = new XmlParser(sharedFastXmlConfiguration);
const builder = new XmlBuilder(sharedFastXmlConfiguration);
const elements = parser.parse(sample);
const sampleAfterFastXmlParser = builder.build(elements);
expect(sampleAfterFastXmlParser).to.equal(sample);
Output
Depending on how you configure it, you end up with either (suppress empty tags true):
const sampleAfterFastXmlParser = '<article><div style="padding: 20px"/><br/></article>';
Or(suppress empty tags true):
const sampleAfterFastXmlParser = '<article><div style="padding: 20px"></div><br><br/></article>';
expected data
Instead, I should be able to get closer to proper HTML (and conceivably match my input):
const sampleAfterFastXmlParser = '<article><div style="padding: 20px"></div><br/></article>';
Would you like to work on this issue?
- Yes
- No
Bookmark this repository for further updates.
Metadata
Metadata
Assignees
Labels
Feature-RequestNew features suggested by usersNew features suggested by users