Sublime Forum

Copy text with highlighted colors

#105

Considering myself a JS guy :wink: itā€™s just

[code]
// or, if you must
//

[/code] I haven't read your code in detail but I'm sure you're aware that attempting to read **width** if it hasn't been set can lead to unexpected return values (in different browsers). But a quick glance tells me that you've set it to a value anyway :smile:
0 Likes

#106

[quote=ā€œagibsonswā€]Considering myself a JS guy :wink: itā€™s just

[code]
// or, if you must
//

[/code] I haven't read your code in detail but I'm sure you're aware that attempting to read **width** if it hasn't been set can lead to unexpected return values (in different browsers). But a quick glance tells me that you've set it to a value anyway :smile:[/quote] Yeah, I was a little sloppy (mainly just tinkering right now). I haven't done javascript since I wrote a plugin for the TonidoPlug (I have been taking a long javascript break since then). I find JS fun, but I find all the different web browser inconsistencies not fun. Some of it isn't as fresh in my brain. I will be running it through the browser gamut when I get closer to a finalized plugin. I probably need to reference my old JS code to remember everything; I really got deep into JS and browsers when I was doing it.
0 Likes

#107

Iā€™m keen on JS (wrote my own library :smiley: ) which makes me dislike all the fake Python assignments ( something = why! ). So let me know if you need a second opinion at any stage.

Andy.

0 Likes

#108

[quote=ā€œagibsonswā€]Iā€™m keen on JS (wrote my own library :smiley: ) which makes me dislike all the fake Python assignments ( something = why! ). So let me know if you need a second opinion at any stage.

Andy.[/quote]

Thanks, I will let you know if I have any specific questions. That TonidoPlug plugin I mentioned, it has my javascript library built into it too :smile: (I got really in to JS for that span of time). But as with anything use it or lose it. The good thing about this plugin, it should be very light on JS. I think I really on have two small applications for it right now: open browser print dialog, and wrap html at XXX px. I want to keep it very very light.

0 Likes

#109

@facelessuser: Wonā€™t be as light as mine - Iā€™ve finished for the moment :wink:

[quote] def write_header(self, the_html):
header = CSS % (
path.basename(the_html.name), # Title
str(self.font_size), # Code font size
self.font_face, # Code font face
self.bground, # Page background color
self.gbground, # Gutter background color
self.fground # Default text color
)
the_html.write(header)[/quote]

Named parameters are cool:

print '<a href="%(url)s">%(url)s</a>' % {'url': my_url}

but itā€™s probably not worth amending. It just means you/we wouldnā€™t have to worry about the order, or comments.

0 Likes

#110

I will have to check it out :smile:. Since my requirements are slightly different, I probably cannot pull in your format, but if it works better and fulfills my requirementsā€¦I do like lighter.

[quote=ā€œagibsonswā€]

[quote] def write_header(self, the_html):
header = CSS % (
path.basename(the_html.name), # Title
str(self.font_size), # Code font size
self.font_face, # Code font face
self.bground, # Page background color
self.gbground, # Gutter background color
self.fground # Default text color
)
the_html.write(header)[/quote]

Named parameters are cool:

print '<a href="%(url)s">%(url)s</a>' % {'url': my_url}

but itā€™s probably not worth amending. It just means you/we wouldnā€™t have to worry about the order, or comments.[/quote]

That would be pretty useful. Man , why didnā€™t I realize I could do that. I will pick that up for sure.

0 Likes

#111

@facelessuser

You can also repeat an argument

(some_fn(), ) * x

(Iā€™m sure you know thisā€¦) but I donā€™t think itā€™s relevant.

**

0 Likes

#112

Well hereā€™s my updated repository on GitHub.

@facelessuser: They only minor changes worth mentioning are that:

Iā€™ve set ā€˜curr_row = 1ā€™ for numbers/not partial, just to leave the future possibility that I might want to number them differently.

And, borrowing from syntax you introduced me to:

# Get general theme colors from color scheme file self.bground = colour_settings"background"] if "background" \ in colour_settings else '#FFFFFF' self.fground = colour_settings"foreground"] if "foreground" \ in colour_settings else '#000000' self.gfground = colour_settings"gutterForeground"] if "gutterForeground" \ in colour_settings else self.fground
This also means I donā€™t have to check ā€˜if self.fground == ā€˜ā€™ā€™ when creating the style-rules (or initialize them to ā€˜ā€™ ).

0 Likes

#113

Just trivia:

I spent ages racking my brain to obtain a neat way of replacing the spaces, but only at the beginning of a string. After a few attempts I ended up with:

if len(tidied_text): init_spaces = len(tidied_text) - len(tidied_text.lstrip(' ')) if init_spaces: tidied_text = (init_spaces * '&nbsp;') + tidied_text.lstrip(' ')
But it made me smile as this was practically the very first (and best) method that I had tried :laughing: :sunglasses:

0 Likes

#114

[quote=ā€œagibsonswā€]Well hereā€™s my updated repository on GitHub.

@facelessuser: They only minor changes worth mentioning are that:

Iā€™ve set ā€˜curr_row = 1ā€™ for numbers/not partial, just to leave the future possibility that I might want to number them differently.

And, borrowing from syntax you introduced me to:

# Get general theme colors from color scheme file self.bground = colour_settings"background"] if "background" \ in colour_settings else '#FFFFFF' self.fground = colour_settings"foreground"] if "foreground" \ in colour_settings else '#000000' self.gfground = colour_settings"gutterForeground"] if "gutterForeground" \ in colour_settings else self.fground
This also means I donā€™t have to check ā€˜if self.fground == ā€˜ā€™ā€™ when creating the style-rules (or initialize them to ā€˜ā€™ ).[/quote]

Cool, I will check it out.

Here is a preview of multi-select support :wink: ā€¦


0 Likes

#115

@facelessuser: Oh, I see :sunglasses: Very clever, and useful!

I misunderstood; I was thinking, previously, of highlighting the text that they have selected (with their selection colour) - but are you doing this as well?

As youā€™ve mentioned JS :smile: a silly, but interesting idea is to allow text to be highlighted and annotations added using the input panel. These could then become tooltips, or popup boxes in the HTML - even just with CSS. This would make the page dynamicā€¦ and cool. But I donā€™t want you to have another sleepless night.

BTW I might look at Word at the weekend. Not because itā€™ll be useful, but purely for my Python education. Alternatively, an Outlook/ send to option - which begins an email with the HTML in the body - should not be too tricky. In fact, it may only require a handful of code-lines.

Andy.

0 Likes

#116

Actually, doesnā€™t have to be Outlook.

Iā€™ll pursue this a little bit. Thereā€™s a mailer module which is a simple wrapper around the ā€˜emailā€™ module. Itā€™s under an MIT licence :question: but if itā€™s possible I could copy the source-code and remove the bits I donā€™t need (as itā€™s for a quite specific purpose).

If I canā€™t just *rip *the code then Iā€™ll have to study the email module and build a wrapper myself (I suppose).

Otherwise, should be a breeze. Andy.

Actually, I need to tear off the header, etc., from the_html - leaving just a list or table.

0 Likes

#117

[quote=ā€œagibsonswā€]@facelessuser: Oh, I see :sunglasses: Very clever, and useful!

I misunderstood; I was thinking, previously, of highlighting the text that they have selected (with their selection colour) - but are you doing this as well?
[/quote]

I meant both:


[quote=ā€œagibsonswā€]
As youā€™ve mentioned JS :smile: a silly, but interesting idea is to allow text to be highlighted and annotations added using the input panel. These could then become tooltips, or popup boxes in the HTML - even just with CSS. This would make the page dynamicā€¦ and cool. But I donā€™t want you to have another sleepless night.

BTW I might look at Word at the weekend. Not because itā€™ll be useful, but purely for my Python education. Alternatively, an Outlook/ send to option - which begins an email with the HTML in the body - should not be too tricky. In fact, it may only require a handful of code-lines.

Andy.[/quote]

That would be interesting. Especially if you were looking for an annotated document of your code. I am wondering how useful it would be? It is kind of a cool idea though. Donā€™t worry about me not sleeping. I am almost done with all features on my immediate todo list. Anything like this would come after I take a nice long break :smile:. I just want to round out the basic features and put it through some good testing and give it a 1.0.0 release version.

0 Likes

#118

[quote=ā€œagibsonswā€]Actually, doesnā€™t have to be Outlook.

Iā€™ll pursue this a little bit. Thereā€™s a mailer module which is a simple wrapper around the ā€˜emailā€™ module. Itā€™s under an MIT licence :question: but if itā€™s possible I could copy the source-code and remove the bits I donā€™t need (as itā€™s for a quite specific purpose).

If I canā€™t just *rip *the code then Iā€™ll have to study the email module and build a wrapper myself (I suppose).

Otherwise, should be a breeze. Andy.

Actually, I need to tear off the header, etc., from the_html - leaving just a list or table.[/quote]

MIT is pretty forgiving. You can use it and even modify it as I understand, but you must not claim it as your own and you must provide the license as well or at least have it in the code file. GNU GPL is a bit more annoying (though there are a couple of versions) but in general it kind of infects your project, and the project including it must also be released under the same license. Technically, I think the desktop module that we are including is GNU GPL (that is the one downside of it). But keep in mind, I am no expert in all of this license stuff. For anything we are doing, I donā€™t think it matters, but combining MIT and GPL, I am not sure how that works together or if it can.

0 Likes

#119

It appears the Desktop module is the Lesser GPL which I think is compatible with MIT. So I think you would be fine.

0 Likes

#120

@facelessuser: Thought you were doing both, as I noticed you storing the ā€˜selectionā€™ colour. Been a bit pre-occupied to study your code in more detail though :smile:

The mailer source code includes the following comment:

[quote]A lot of this code was taken from the online examples in the
email module documentation:
docs.python.org/library/email-examples.html

Released under MIT license.[/quote]

which seems very noble. At the end of the day, we are ALL *borrowing *code from somewhere :smile:

Actuallyā€¦ just had an inspiring idea about the tooltips/ popup boxes. They could be (editable - TextArea) to-do items/ comments. What a cool idea :sunglasses: :bulb:. But Iā€™m getting a little carried away nowā€¦

Andy.

0 Likes

#121

@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:

tidied_text = tidied_text.replace('\t', '&nbsp;' * self.tab_size).strip('\r\n')

But, as I say, itā€™s probably no longer an issue.

Laterz, Andy.

0 Likes

#122

[quote=ā€œagibsonswā€]@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:

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.[/quote]

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!

0 Likes

#123

working on unicode issues in html.

0 Likes

#124

Unicode fix is now in.

0 Likes