Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Allow including node metadata (startIndex) in output #593

Open
6 tasks done
ewlsh opened this issue Jun 22, 2023 · 3 comments
Open
6 tasks done

Feature Request: Allow including node metadata (startIndex) in output #593

ewlsh opened this issue Jun 22, 2023 · 3 comments
Labels
Feature-Request New features suggested by users

Comments

@ewlsh
Copy link

ewlsh commented Jun 22, 2023

  • 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

Feature request to have a way to include metadata such as startIndex in the parser output

Potentially related: #345

Background

I'm working on a project that uses fast-xml-parser to parse XML files, it needs to report where a certain string was found in a given file. To support this I'm currently monkeypatching XmlNode: https://github.com/ewlsh/tree-gettext/blob/main/src/languages/xml.ts#L11

Would you like to work on this issue?

  • Yes
  • No

I am open to contributing but am submitting this feature request first to gather input.

Bookmark this repository for further updates. Visit SoloThought to know about recent features.

@github-actions
Copy link

We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.

@amitguptagwl
Copy link
Member

Do you mean tag index line number, or line number with col number? There is a plan to add tag index in v5.

@amitguptagwl amitguptagwl added the Feature-Request New features suggested by users label Jun 22, 2023
@ewlsh
Copy link
Author

ewlsh commented Jul 5, 2023

Do you mean tag index line number, or line number with col number? There is a plan to add tag index in v5.

@amitguptagwl I'm looking for startIndex (and maybe endIndex), I can calculate lines and columns off of that value.

Currently I'm doing something like this against ^4.0.0-beta.2

/// Temporarily construct our own Xml parser from fast-xml-parser which preserves start indices
import { parseToOrderedJsObj } from 'fast-xml-parser/src/xmlparser/OrderedObjParser';
import { buildOptions } from 'fast-xml-parser/src/xmlparser/OptionsBuilder';

import XmlNode from 'fast-xml-parser/src/xmlparser/xmlNode';
import { ParseResult } from '../parse';

const addChild = XmlNode.prototype.addChild;
XmlNode.prototype.addChild = function _addChild(node) {
  addChild.call(this, node);
  this.child[this.child.length - 1].$startIndex = node.startIndex ?? null;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature-Request New features suggested by users
Projects
None yet
Development

No branches or pull requests

2 participants