Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

The amount of <span> elements can impact rendering performance #70

@janko

Description

@janko

Prerequisites

Description

I'm using this package separately from Atom, for syntax highlighting code snippets in markdown files. I've noticed that when I switched from Highlight.js/Prism to Highlights, my page rendering performance reduced.

This appears to be due to the number of <span> elements Highlights generates. In addition to the ones that have class attributes with token names, there are also a lot of <span> elements generated which don't have any class attribute.

When I tried stripping just the classless <span> tags, the rendering performance was now instant again.

Steps to Reproduce

const Highlights = require("highlights")

const highlighter = new Highlights()

const html = highlighter.highlightSync({
  fileContents: 'answer = 42',
  scopeName: 'source.ruby',
})

console.log(html)
<pre class="editor editor-colors">
  <div class="line">
    <span class="source ruby">
      <span>answer&nbsp;</span>
      <span class="keyword operator assignment ruby">
        <span>=</span>
      </span>
      <span>&nbsp;</span>
      <span class="constant numeric ruby">
        <span>42</span>
      </span>
    </span> 
  </div>
</pre>

Expected behavior:

That highlighting produces only the tags that are necessary.

Actual behavior:

Highlighting produces many <span> tags that are not needed (the script above produces 4 such tags).

Versions

Highlights 3.1.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions