@facelessuser
A grey-scale option occurred to me a while ago
Wouldnāt JS be overkill? I removed the left-margin (when not printing line numbers) with a couple of css-tweaks.
Iāve posted the code below in case it has anything useful to you - but Iām still using a list.
Iām building a temporary string of the spans before writing them;
Iām able to skip a line entirely if itās empty;
Iām stripping ā\r\nā in case there are any, particularly ā\rā, left over;
Iām only replacing spaces with nbsp if they occur at the beginning of the span. This is helpful when copying the HTML, but I donāt know how it would affect your* fake alignment* of, for example, dictionary assignments;
Iām not writing the temporary line if itās empty.
[code]
def convert_view_to_html(self, the_html):
for line in self.view.split_by_newlines(sublime.Region(self.pt, self.size)):
self.pt = line.begin(); self.end = self.pt + 1
if line.empty():
the_html.write(ā
\n
continue
self.line_end = line.end()
temp_line = āā
while self.end <= self.line_end:
scope_name = self.view.scope_name(self.pt)
while (self.end <= self.line_end and (self.view.scope_name(self.end) == scope_name
or (self.view.substr(self.end) in ā\tā, ā ', āā]))):
self.end += 1
region = sublime.Region(self.pt, self.end)
the_colour = self.guess_colour(scope_name.strip())
tidied_text = self.view.substr(region)
tidied_text = tidied_text.replace('&', '&')
tidied_text = tidied_text.replace('<', '<')
tidied_text = tidied_text.replace('>', '>')
tidied_text = tidied_text.replace('\t', ' ' * self.tab_size)
tidied_text = tidied_text.strip('\r\n')
if len(tidied_text):
without_init_sp = tidied_text.lstrip(' ')
init_spaces = len(tidied_text) - len(without_init_sp)
if init_spaces:
without_init_sp = (' ' * init_spaces) + without_init_sp
tidied_text = without_init_sp
temp_line += '<span style=\"color:' + the_colour + '\">'
temp_line += tidied_text + '</span>'
self.pt = self.end
self.end = self.pt + 1
if temp_line != '':
the_html.write(temp_line)
the_html.write('</li>\n<li>')[/code]
[Copied from HTML ]
There might be a neater way of replacing the spaces only at the beginning of the line (non-regex).
I tried āclosingā your pull request but Iām still unable to update to my local version
Added: Oops. My version doesnāt copy the line numbers, Doh! Iāve only just noticed this . I think you may have hinted at this earlier
Added again: No worries, I can always copy/save the HTML if I want the line numbers.