Comments (7)
It's not actively maintained and you need to do some hacky things such as replacing script/style/no script content otherwise the ranges will be off since it still matches on those tokens inside (e.g. no state switching)
from html5ever.
Changes in line numbers are available to client code in the tree builder (
html5ever/markup5ever/interface/tree_builder.rs
Lines 237 to 238 in 98d3c0c
from html5ever.
Simiarly, the tokenizer receives a line number with each token:
html5ever/html5ever/src/tokenizer/interface.rs
Lines 97 to 98 in 98d3c0c
from html5ever.
thank you @jdm ! :-)
I am working on some code that checks links in documents, and tells the user which ones are valid and which not (anymore). For this, I have to be able to tell the user where exactly these links are in the document, so they can fix them.
I am currently using some very shady, ueber-simple, self-made HTML parser, because none of the libraries for HTML parsing seem to supply line&column info. I understand, it makes no sense to track these for each little detail, in 99% of use-cases for these libraries, so I am not suggesting to add this. Would be glad for some hints about how to go about this.
Will I need to maintain a fork of one of these libraries (eg. html5ever)?
from html5ever.
Yeah the line number on its own is kind of useless for certain applications. For my own project I'm having to resort to https://github.com/y21 just to get the exact byte positions of each DOM node.
Positions for DOM nodes were also recently added to JSoup and also seems available in HTML parsers in other major languages, so I think it would make sense if we could figure out a way for html5ever to provide the same. Also there's been several issues over the years asking for similar features.
One thing that I was trying to make work but couldn't quite yet is to provide a byte stream that I can read the offset from as tokens are emitted from html5ever, however since tokens are actually consumed ahead of time it doesn't quite give the right positions. This could maybe be fixed by providing something that's Peekable, but tbh. I didn't really like the direction anyways.
Are there any better ideas of how this could potentially be added in such a way that it's an opt-in performance penalty?
from html5ever.
hey @RXminuS :-)
... you resorted to https://github.com/y21/tl?
why is it not optimal?
from html5ever.
For anyone else running into this problem, in whatwg/html-build#291 I'm creating a RcDomWithLineNumbers
which overrides the two methods necessary to at least track line numbers in the errors recorded. I'm very much a Rust beginner so it's just kind of been a process of flailing around until I got something working, and the fact that Rust makes you delegate all methods of TreeSink
just to override set_current_line
(to record the current line) and parse_error
(to augment the recorded error with the current line) seems bonkers. But it seems to work so far.
Column numbers, of course, are not so easy.
from html5ever.
Related Issues (20)
- html5ever lags far behind on html5lib-tests
- Yank xml5ever 0.16.0 and html5ever 0.25.0 HOT 5
- `<template />` contents are not serialized HOT 1
- Please release a new version of rcdom HOT 2
- cannot find function `precise_time_ns` in crate `time` HOT 2
- the trait `TreeSink` is not implemented for `RcDom` with html5ever 0.26 HOT 3
- doc: how to run example, for n00bs HOT 3
- bug: cargo doesn't know how to resolve dependencies for print-rcdom HOT 1
- Make async ergonomics nicer. HOT 1
- This line of code causes me to print lots of annoying warnings when I used. HOT 1
- html5ever v0.24.1 incompatibilities problems HOT 4
- `html5ever::tokenizer::Tokenizer::process_token_and_continue` needs to go away HOT 3
- Using html5ever in wasm package for an isomorphic html sanitizer HOT 3
- cargo bench fails HOT 1
- How to use html5ever to find comment in html??? HOT 4
- HTML Entities cause split after the next character HOT 4
- Malformed HTML parsed differently from browsers HOT 1
- html5ever parses document in unexpected way HOT 1
- New release HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from html5ever.