htmlparser2 icon indicating copy to clipboard operation
htmlparser2 copied to clipboard

feat: Add PositionTracker

Open fb55 opened this issue 4 years ago • 3 comments

I took a stab at implementing a position tracker that works for streams. This is something that's been asked for every once in a while, and it seems easy enough to add.

  • [ ] Directly integrate into Parser

fb55 avatar Aug 23 '21 13:08 fb55

Pull Request Test Coverage Report for Build 1158889962

  • 34 of 34 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.06%) to 98.286%

Totals Coverage Status
Change from base Build 1158875845: 0.06%
Covered Lines: 975
Relevant Lines: 992

💛 - Coveralls

coveralls avatar Aug 23 '21 13:08 coveralls

@thewilkybarkid I haven't made up my mind if I want to have this in the module or not. Curious if the parser providing this directly would be a value-add for you.

My current plan is to provide a getPosition(index) method on the parser, which allows you to get a position like this:

const startPos = parser.getPosition(parser.startIndex);

fb55 avatar Aug 23 '21 13:08 fb55

Probably worth not adding it to start with at least (feels a little too specialist).

An aside, but I think this has the same problem that https://github.com/posthtml/posthtml-parser/pull/80 had to work around: needing to be able to backtrack (a bit).

thewilkybarkid avatar Aug 24 '21 08:08 thewilkybarkid