Why the DOM tree is such complicated? #3013
-
I know that the DOM Tree StructureComplicated DOM TreeFlatten DOM TreeAs shown above, there is no visual difference between FlattenIn other highlighting libraries, each line are wrapped, but PrismJS does not. An example of other highlighting libraries:one layer of
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The nested DOM tree is a byproduct of Prism's recursive highlighting algorithm. The DOM structure just reflects the language definitions (e.g. Markup tag is nested, so the DOM tree it produces also has that nesting). This is also quite useful because the CSS themes have access to (simple) structural information about the code. This allows for very specific custom highlighting. You won't see this kind of highlighting with Prism's standard themes (they are all quite simple) but we have users that do that. Regarding the lines: Many syntax highlighters are line-based (e.g. all TextMate-based syntax highlighters) but Prism is not. Prism highlights the whole text in one go. Splitting everything into lines is actually quite challenging. That being said, a plugin that splits everything into lines is being worked on and will be part of Prism v2. |
Beta Was this translation helpful? Give feedback.
The nested DOM tree is a byproduct of Prism's recursive highlighting algorithm. The DOM structure just reflects the language definitions (e.g. Markup tag is nested, so the DOM tree it produces also has that nesting).
This is also quite useful because the CSS themes have access to (simple) structural information about the code. This allows for very specific custom highlighting. You won't see this kind of highlighting with Prism's standard themes (they are all quite simple) but we have users that do that.
Regarding the lines: Many syntax highlighters are line-based (e.g. all TextMate-based syntax highlighters) but Prism is not. Prism highlights the whole text in one go. Splitting everything…