Sublime Forum

ExportHtml Plugin (rename from PrintHtml)

#15

Convert code to forum post. I have seen @castles_made_sand_post posting with highlighted text, and figured now that we have the framework to print HTML color coded, why not forum posts as well.

Here is an example. I still have work to do, but stay tuned.

[pre=#000000] 396 def convert_view_to_post(self, the_post):
397 for line in self.view.split_by_newlines(sublime.Region(self.end, self.size)):
398 self.size = line.end()
399 line = self.convert_line_to_post()
400 the_post.write(self.print_line(line, self.curr_row))
401 self.curr_row += 1
402
403 def format_text(self, line, text, the_colour, the_style, highlight=False):
404 code = (FORUM_CODE % {“color”: the_colour, “content”: text}).replace(’\n’, ‘’)
405 line.append(code)
406
407 def convert_line_to_post(self):
408 line = ]
409 hl_found = False
410
411 # Continue highlight form last line
412 if self.hl_continue != None:
413 self.curr_hl = self.hl_continue
414 self.hl_continue = None[/pre]

0 Likes

#16

Be nice if *someone *added similar annotations- with simple sample code - to the ST API page :smile: . This small improvement could make a big difference.

0 Likes

#17

That is going to be it. It should support bold and italic as well.

No Gutter
[pre=#FFFFFF]* def* convert_view_to_post(self,* the_post*):
for line in self.view.split_by_newlines(sublime.Region(self.end, self.size)):
self.empty_space = None
self.size = line.end()
line = self.convert_line_to_post()
the_post.write(self.print_line(line, self.curr_row))
self.curr_row += 1[/pre]

Gutter
[pre=#FFFFFF] 149 * def* convert_view_to_post(self,* the_post*):
150 for line in self.view.split_by_newlines(sublime.Region(self.end, self.size)):
151 self.empty_space = None
152 self.size = line.end()
153 line = self.convert_line_to_post()
154 the_post.write(self.print_line(line, self.curr_row))
155 self.curr_row += 1[/pre]

Forum posts will only work in forums that allow “[pre’]”, “”, "", and "" blocks. If you use any forum syntax blocks in your code, it will mess things up since there is really no way to escape forum blocks. Gutter numbers are allowed, but fancy styling of the gutter will not be allowed though due to the limitations of the forum post syntax; the default foreground and background color will be used. Highlighting selections will also specific words will also not be allowed due to limitations of the forum post syntax. It will copy the the code to your clipboard and/or open the code in a sublime view.

0 Likes

#18

Ok, that’s too cool.

0 Likes

#19

It’s rather beside the point (sorry!), but I was wondering about the provenance of the Print-Color theme. It looks like a black-on-white Monokai. Did you make it for this plugin or did you derive it from somewhere else?

0 Likes

#20

I took the base Monokai Bright and darkened all of the colors or changed them to look decent on a white background. Changed the background to white, styled the gutter, choose a suitable color for selections etc., adjusted line coloring, blah, blah, blah. You get the idea. Colors were tweaked and adjusted where they made sense. Colors like yellow needed far more aggressive tweaking to work on white.

The Grayscale was also derived from Monokai Bright. Gutted out all colors and left only what changed the font style. Changed all text to black except comments which were light gray color…you get the idea.

I just needed something that looked okay printed, and I needed a template, so I grabbed Monokai Bright and forced it to meet my needs. So in short, I heavily modded it for this plugin.

Probably should mention that in the readme.

0 Likes

#21

Thanks for the info.

I am (slowly) putting together a light (i.e., black-on-white) theme that looks good when working on my usual stuff (HTML, CSS, Text/Markdown), so I’ve been peeking into all the light tmThemes I come across. I’m currently using Espresso Soda as a base with some bits of Monokai and my own eccentricities thrown in, but I think you may be onto something with this one :smile:

0 Likes

#22

[quote=“quodlibet”]Thanks for the info.

I am (slowly) putting together a light (i.e., black-on-white) theme that looks good when working on my usual stuff (HTML, CSS, Text/Markdown), so I’ve been peeking into all the light tmThemes I come across. I’m currently using Espresso Soda as a base with some bits of Monokai and my own eccentricities thrown in, but I think you may be onto something with this one :smile:[/quote]

Thanks. I was pretty pleased with it, but I know tastes can vary greatly when it comes to people’s code themes. I am glad it to hear you like it. I will keep an eye out for what you are cooking up.

0 Likes

#23

I suppose it would be possible :laughing: to have settings for the colours of things like ‘keyword’, ‘comment’, ‘string’, etc., and push them into the colour dictionary. That is, overwriting the values extracted from the user’s theme. But I feel a little guilty mentioning this :smile:

0 Likes

#24

It would be, but I figure if someone wants different colors than XXXXXX.tmTheme, they can just copy the tmTheme file and modify it how they want and use that. Keeping a separate file format to style the text when we already have tmTheme files just doesn’t seem like something that would be useful.

0 Likes

#25

@facelessuser: Quite right :wink:

0 Likes

#26

This is awesome. Great work!

0 Likes

#27

Annotations and Forum Post Format is in…

Let the syntax highlighted posts commence :smile:.

I will update documentation today or tomorrow, and then I will update the revision.

If the context menu items are too much (there are 3 items), I can shove them under one common fly out menu.

0 Likes

#28

I will probably rename the forum command to Print BBCode which is more accurate.

0 Likes

#29

Awesome, now we can all feel as cool as @castles_made_of_sand when we post code on the forum :stuck_out_tongue:

0 Likes

#30

:smile:

0 Likes

#31

Great job with the updates - loving the context menu stuff. :smile:

0 Likes

#32

Glad you like it. I have to say, the context menu makes it easier to use.

0 Likes

#33

Hi,
great Plugin! Unfortunately there seems to be a problem with PHP files (for me) - JSON or Plain Text is working. I have installed the plugin and didn’t change any settings. When I want to print a PHP file (from the menu), the console says:

Traceback (most recent call last):
  File ".\sublime_plugin.py", line 356, in run_
  File ".\PrintToHTML.py", line 44, in run
  File ".\PrintToHTML.py", line 170, in convert_to_html
  File ".\PrintToHTML.py", line 124, in get_lexer
  File ".\pygments\lexers\__init__.py", line 74, in get_lexer_by_name
  File ".\pygments\lexer.py", line 470, in __call__
  File ".\pygments\lexers\web.py", line 870, in __init__
ImportError: No module named _phpbuiltins

Is it a bug or do I have do configure something for PHP files?

Setup: ST2 2194 Nightly, WIN7.

Best regards, Thorsten.

0 Likes

#34

Your error message refers to an alternative plugin **PrintToHtml **rather than PrintHtml. You may want to disable or un-install it so you can test this one without conflict.

0 Likes