Prerequisites
Description
I'm using highlights as a library outside of Atom. It works great, except that I noticed that in certain cases it adds trailing <span> </span> at the end of lines.
This is not a problem visually, but when developers are copy-pasting code into their editors, the trailing whitespace will get pasted as well.
Steps to Reproduce
Run the following script:
const Highlights = require('highlights')
const highlighter = new Highlights()
const rubyCode = `Sequel.migration do
change do
add_column :photos, :image_data, :text # or :jsonb
end
end`
let html = highlighter.highlightSync({
fileContents: rubyCode,
scopeName: `source.ruby`,
})
console.log(html)
Expected behavior:
I expect only whitespace to be translated into .
Actual behavior:
Additional trailing character is added after the # or :jsonb comment:
<pre class="editor editor-colors">
<div class="line"><span class="source ruby"><span class="support class ruby"><span>Sequel</span></span><span class="punctuation separator method ruby"><span>.</span></span><span>migration </span><span class="keyword control start-block ruby"><span>do</span></span></span></div>
<div class="line"><span class="source ruby"><span> change </span><span class="keyword control start-block ruby"><span>do</span></span></span></div>
<div class="line"><span class="source ruby"><span> add_column </span><span class="constant other symbol ruby"><span class="punctuation definition constant ruby"><span>:</span></span><span>photos</span></span><span class="punctuation separator object ruby"><span>,</span></span><span> </span><span class="constant other symbol ruby"><span class="punctuation definition constant ruby"><span>:</span></span><span>image_data</span></span><span class="punctuation separator object ruby"><span>,</span></span><span> </span><span class="constant other symbol ruby"><span class="punctuation definition constant ruby"><span>:</span></span><span>text</span></span><span> </span><span class="comment line number-sign ruby"><span class="punctuation definition comment ruby"><span>#</span></span><span> or :jsonb</span><span> </span></span></span></div>
<div class="line"><span class="source ruby"><span> </span><span class="keyword control ruby"><span>end</span></span></span></div>
<div class="line"><span class="source ruby"><span class="keyword control ruby"><span>end</span></span></span></div>
</pre>
I believe this is because highlights converts empty strings into , we can see there is one extra empty string in the list of tokens:
[ [ { value: 'Sequel', scopes: [Array] },
{ value: '.', scopes: [Array] },
{ value: 'migration ', scopes: [Array] },
{ value: 'do', scopes: [Array] } ],
[ { value: ' change ', scopes: [Array] },
{ value: 'do', scopes: [Array] } ],
[ { value: ' add_column ', scopes: [Array] },
{ value: ':', scopes: [Array] },
{ value: 'photos', scopes: [Array] },
{ value: ',', scopes: [Array] },
{ value: ' ', scopes: [Array] },
{ value: ':', scopes: [Array] },
{ value: 'image_data', scopes: [Array] },
{ value: ',', scopes: [Array] },
{ value: ' ', scopes: [Array] },
{ value: ':', scopes: [Array] },
{ value: 'text', scopes: [Array] },
{ value: ' ', scopes: [Array] },
{ value: '#', scopes: [Array] },
{ value: ' or :jsonb', scopes: [Array] },
{ value: '', scopes: [Array] } ],
[ { value: ' ', scopes: [Array] },
{ value: 'end', scopes: [Array] } ],
[ { value: 'end', scopes: [Array] } ] ]
Reproduces how often:
Every time.
Versions
Highlights 3.1.4
Prerequisites
Description
I'm using
highlightsas a library outside of Atom. It works great, except that I noticed that in certain cases it adds trailing<span> </span>at the end of lines.This is not a problem visually, but when developers are copy-pasting code into their editors, the trailing whitespace will get pasted as well.
Steps to Reproduce
Run the following script:
Expected behavior:
I expect only whitespace to be translated into
.Actual behavior:
Additional trailing
character is added after the# or :jsonbcomment:I believe this is because
highlightsconverts empty strings into , we can see there is one extra empty string in the list of tokens:Reproduces how often:
Every time.
Versions
Highlights 3.1.4