Introduce initialIndentationLevel option for the XMLBuilder

Open
#10 6 comments 1 reaction 0 assignees View on GitHub

@moki is already working on this.

Since Apr 23, 2023.

  • #566 by @moki — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript
Domain
tooling

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.

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
Dominant language
JavaScript
Stars
22
Forks
9
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NaturalIntelligence/fast-xml-builder

All issues in NaturalIntelligence/fast-xml-builder

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.