Home Download Buy Blog Forum Support

Copy text with highlighted colors

Re: Copy text with highlighted colors

Postby agibsonsw on Thu Apr 12, 2012 10:11 pm

@facelessuser: Signing off now, you'll be pleased to hear.

I'm v. happy with my code but I think I'll explore a couple of ideas tomorrow evening - just for my own Python education:

1. I'm storing the spans in a temporary string before writing to the file. If, instead, I store a list of tuples (tidied_text, the_colour) then I can perform the entity-escaping, etc., in one fell swoop, perhaps with a list comprehension.

2. I'd like to gain a better understanding of generators. It's screaming at me that processing spans within a line could be a good example for this. (This is probably an alternative to 1.)

BTW A while ago (yesterday? can't remember) I did notice '\r' popping up on occasion, but presumably split_by_newlines has removed this issue. Personally, I'm using:

Code: Select all
tidied_text = tidied_text.replace('\t', ' ' * self.tab_size).strip('\r\n')

But, as I say, it's probably no longer an issue.

Laterz, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Copy text with highlighted colors

Postby facelessuser on Fri Apr 13, 2012 2:28 am

agibsonsw wrote:@facelessuser: Signing off now, you'll be pleased to hear.

I'm v. happy with my code but I think I'll explore a couple of ideas tomorrow evening - just for my own Python education:

1. I'm storing the spans in a temporary string before writing to the file. If, instead, I store a list of tuples (tidied_text, the_colour) then I can perform the entity-escaping, etc., in one fell swoop, perhaps with a list comprehension.

2. I'd like to gain a better understanding of generators. It's screaming at me that processing spans within a line could be a good example for this. (This is probably an alternative to 1.)

BTW A while ago (yesterday? can't remember) I did notice '\r' popping up on occasion, but presumably split_by_newlines has removed this issue. Personally, I'm using:

Code: Select all
tidied_text = tidied_text.replace('\t', ' ' * self.tab_size).strip('\r\n')

But, as I say, it's probably no longer an issue.

Laterz, Andy.


I think the \r is a non-issue, but as stated earlier, it hurts nothing to try to strip them.

I went ahead and posted the last currently planned features.
-color and black and white default color schemes.
-quick panel access to configurations stored in settings file.
-multi-select available
-option to turn off gutter styling (mainly for when you want to print)
-code cleanup

At this point I just need to do some good testing and write up the documentation.

@agibsonsw
I will keep an eye on what you are working on. Good luck!
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Copy text with highlighted colors

Postby facelessuser on Fri Apr 13, 2012 3:41 pm

working on unicode issues in html.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Copy text with highlighted colors

Postby facelessuser on Fri Apr 13, 2012 4:46 pm

Unicode fix is now in.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Copy text with highlighted colors

Postby agibsonsw on Fri Apr 13, 2012 4:59 pm

facelessuser wrote:working on unicode issues in html.

I'm interested to hear a little more detail?

Because we are using an HTML5 DOCTYPE, we could add

Code: Select all
<meta charset="UTF-8">

immediately after the opening <head> tag, but it isn't strictly required link here. But I assume you've come across more specific issues?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Copy text with highlighted colors

Postby facelessuser on Fri Apr 13, 2012 5:07 pm

Unicode could not be written to the file for one. That just required some encoding to pass it to the file write command. But then the unicode characters didn't show up right.

So really what needed to happen was the text needed to be converted to ASCII, but also escaped for HTML to something like &#XXXX;.

So now I just pass the text to a function:
escape.png
escape.png (10.21 KiB) Viewed 1091 times
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Copy text with highlighted colors

Postby agibsonsw on Fri Apr 13, 2012 5:54 pm

@facelessuser: I came across encode() the other day and was considering 'xmlcharrefreplace', although I wasn't sure how it fitted in to the project. The Python docs don't indicate that encode() takes varargs - must be out of date.

BTW, and out of interest, I conquered adding comments last night (in my head ;) ). Here's my outline, but I'm not sure if it's worth doing. Nevertheless, it's interesting 8-):

1. Create a shortcut to store the current view, point, word under the point - and a comment read from the input panel - in a dictionary of tuples, using the view as key. If there isn't a proper a-z word under the point, then bail, and it cannot be a selection (just a single point).

Allowing a selection is too messy, as it would cover a number of spans. Similarly, extending the comment across the current span could be messy, particularly if within a comment line. (Why would someone put a comment in a comment, Doh!)

2. Add CSS rule(s) to a tag such as 'b' or 'tt', or possibly a little bit of JS, based on a class that would create the tooltip on hover. (JS might use ids instead: e.g. 'comment' + pt)
2b. Format the tag so it stands out. Can't really use a colour, so perhaps underline or italic. (But perhaps allow yet another setting for 'comment_colour'.)
2c. Might need another styled-span, that JS would use to display the tooltip.
3. During parsing of the lines/spans - but after entity escaping the HTML - examine the comment-points to see if any fall within the current region/span.
4. If so, compare the word-under-point. If it's not the same, then bail - they've added more code and the comment is no longer relevant.
5. Find the same word in tidied_text, and replace it with '<b class=\"comment\" title=\"The comment text\">word</b>".
6. If using JS for the tooltip, would need to insert the (new) styled-span just inside this b-tag, containing the comment text. (It could be positioned to display underneath the line.)

I recall/believe that tooltips can be created with just CSS, particularly CSS3. They could even just be <a> links, but a little JS might be better.

Anyway, I haven't decided how far I might pursue this. Although, it's still kinda cool 8-)

I shall have a look at your current work in a while. Regards, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Copy text with highlighted colors

Postby agibsonsw on Fri Apr 13, 2012 6:45 pm

@facelessuser

self.font_size = settings.get('font_size', 10)


He, he, I was looking at this yesterday, and wondered why ST didn't offer the second, default, argument. But it does - must have been in my blind-spot when I glanced at the docs.

Curious as to why you created theme files, rather than just creating a dictionary? Perhaps you feel users would be more comfortable modifying the plist.

My idiom (notice the Python reference there?) would be to delete all the ' self.bground = '' ' as they are now always assigned a value, but we had a similar discussion before ;)

Are 'activeGuide', etc., standard pList items in ST? Or have you made them up for the plug-in? (I've struggled to find a list of the possible items.)

Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Copy text with highlighted colors

Postby facelessuser on Fri Apr 13, 2012 7:13 pm

agibsonsw wrote:@facelessuser

self.font_size = settings.get('font_size', 10)


He, he, I was looking at this yesterday, and wondered why ST didn't offer the second, default, argument. But it does - must have been in my blind-spot when I glanced at the docs.

Curious as to why you created theme files, rather than just creating a dictionary? Perhaps you feel users would be more comfortable modifying the plist.

My idiom (notice the Python reference there?) would be to delete all the ' self.bground = '' ' as they are now always assigned a value, but we had a similar discussion before ;)

Are 'activeGuide', etc., standard pList items in ST? Or have you made them up for the plug-in? (I've struggled to find a list of the possible items.)

Andy.


I just took the Monokai Bright Color Scheme file and modified it. I figured it needed to be in accordance with other scheme files. People can modify them if they want. I left everything in the settings section so it would be functional if some used it (I can't imagine people using the grayscale one though). In the gray scale one, I gutted everything scope wise because everything is black accept comments which is gray. If something was italic or something, I left it in.

'activeGuide' controls the color of the stippled tab guides.

People can use my other plugin and convert the plist to a JSON file if they like that better for modifications. But I wanted to be universal with how I handle all input colors schemes.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Copy text with highlighted colors

Postby agibsonsw on Fri Apr 13, 2012 7:37 pm

@facelessuser: I like this 8-)

Code: Select all
class PrintHtmlCommand(sublime_plugin.WindowCommand):
    def run(self, **kwargs):
        view = self.window.active_view()
        if view != None:
            PrintHtml(view).run(**kwargs)

class PrintHtml(object):
    def __init__(self, view):
        self.view = view

I still prefer my idea of skipping past tabs and spaces, to reduce the number of spans:

Code: Select all
         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

but, then again, you need to keep an eye out for highlights and multi-selects.

The penny hasn't quite dropped: are you using a table of two-columns, one for the gutter, and then spans in the second column? And using nbsp to keep your alignment?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

PreviousNext

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 5 guests