NaturalIntelligence / NaturalIntelligence/fast-xml-builder
Introduce initialIndentationLevel option for the XMLBuilder
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 22
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
Hello there! I’ve started using XMLParser/XMLBuilder in my project markdown-translation and arrived at use case that is not really supported in the XMLBuilder.
First i render XML template/wrapper which makes skeleton base of the rendered document with {format: true} options.
example of the generated template:
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="file.md" source-language="ru-RU" target-language="en-US" datatype="markdown">
<header>
<skeleton>
<external-file href="file.skl.md"></external-file>
</skeleton>
</header>
<body>
<!-- split point -->
</body>
</file>
</xliff>
After rendering template i split it at the <!-- split point --> so that later i can dynamically render <trans-unit></trans-unit> with content inside the body tag.
The problem is that later when i render each trans-unit tag XMLBuilder unaware of the fact that trans-unit tag is going to be injected into other document(template) at the level: 3 point of indentation.
Result is going to be something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="file.md" source-language="ru-RU" target-language="en-US" datatype="markdown">
<header>
<skeleton>
<external-file href="file.skl.md"></external-file>
</skeleton>
</header>
<body>
<trans-unit>
<source>str</source>
<target>target</target>
</trans-unit>
</body>
</file>
</xliff>
Hence i propose the solution - Introduce new option initialIndentationLevel and initialize builder with it instead of the literal value 0.
The option initialIndentationLevel is going to default to 0 so that default behaviour will be preserved.
Yet will allow my use case and generally make it more convenient building part of the XML document in the pretty format.
Please let me know what you think about it.
There is already PR for this feature: NaturalIntelligence/fast-xml-parser#566.
Would you like to work on this issue?
- Yes
- No
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the XMLBuilder initialization described in the issue, where the indentation level is currently fixed at 0, and review the proposed PR NaturalIntelligence/fast-xml-parser#566. Done means supporting initialIndentationLevel while preserving the default output and producing correctly indented inserted trans-unit content.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100