This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Additional non-breaking space added at the end of lines #69
Copy link
Copy link
Open
Labels
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Reproduced the problem in Safe Mode: https://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
- Followed all applicable steps in the debugging guide: https://flight-manual.atom.io/hacking-atom/sections/debugging/
- Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
- Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
- Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages
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