Sublime Forum

ExportHtml Plugin (rename from PrintHtml)

#50

OK, I checked Win 7 64 and did not have the absolute path there so went back to XP machine and changed to another theme and had relative path then. Edited the naming for the theme in the directory and the problem went away so it looks like absolute path handling is not needed after all. I think this occurred because I must have added the color scheme directly off of the github download without editing the name and that triggered an absolute path mapping in sublime somehow.

0 Likes

#51

You can click the link and go straight to the annotation in the HTML.

Version 0.3.0

  • Add annotation jump table for the HTML. Show table with “alt+double_click”

Let me know if you find any bugs.

0 Likes

#52

Very cool!

Any plans on making this available in package manager? I think you mentioned once that you would if folks wanted that… +1 from me, if you’re taking requests. :wink:

0 Likes

#53

[quote=“SeanWcom”]Very cool!

Any plans on making this available in package manager? I think you mentioned once that you would if folks wanted that… +1 from me, if you’re taking requests. :wink:[/quote]

I have put in a request. As soon as wbond gets around to it, it should be there.

0 Likes

#54

I modified ExportHtml.py a little bit because I prefer own font face and font size for the Html view:

It tries at first to find font_size and font_face from ExportHtml.subleme-settings before using the defaults.
Just replace lines 469-470 containing

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

with


        self.font_size = sublime.load_settings(PACKAGE_SETTINGS).get("font_size", settings.get('font_size', 10))
        self.font_face = sublime.load_settings(PACKAGE_SETTINGS).get("font_face", settings.get('font_face', 'Consolas'))
0 Likes

#55

You can now specify an alternate font_size and font_face via the settings file.

[pre=#000000] // By default, ExportHtml uses your current font_face and font_size.
// You can change this setting to always use this value. By default,
// the setting is a literal false, but you can change it to an actual
// font_face to enable this setting.
“alternate_font_face”: false,

// By default, ExportHtml uses your current font_face and font_size.
// You can change this setting to always use this value.  By default,
// the setting is a literal false, but you can change it to an actual
// font_size to enable this setting.
"alternate_font_size": false,[/pre]
0 Likes

#56

Plugin is now on package control.

Also, a couple of fixes have been made.

Version 0.4.0

  • Fix regression with option numbers = false
  • Fix issue where if transparency was included in hex color, color would not render
  • Fix regression where annotation table would not show
0 Likes

#57

For a moment I thought that the active color schemes were being applied, but now that I’ve changed color schemes, it doesn’t seem to be taking effect. Was it ever observing the active color scheme or does it play by its own rules?

For example, I have tried exporting the ExportHtml.sublime-settings file using this Tango theme and what I see in the browser is not what is displayed in Sublime Text 2.

BTW, I do have “alternate_scheme” set to false, as in the default settings.



0 Likes

#58

[quote=“Grant”]For a moment I thought that the active color schemes were being applied, but now that I’ve changed color schemes, it doesn’t seem to be taking effect. Was it ever observing the active color scheme or does it play by its own rules?

For example, I have tried exporting the ExportHtml.sublime-settings file using this Tango theme and what I see in the browser is not what is displayed in Sublime Text 2.

BTW, I do have “alternate_scheme” set to false, as in the default settings.[/quote]

Just remove the “color_scheme” setting form the particular setting you wish to adopt the current theme. If the “color_scheme” is specified, it will use it, if it isn’t, it grabs whatever is the current theme.

For instance, I have this in my settings file to give show the current theme in the browser:

[pre=#000000] // Browser view color (selections and multi-selections allowed)
{
“Browser View - Current Color”: {
“numbers”: true,
“multi_select”: true
}
},[/pre]

0 Likes

#59

That’s it. Thanks!

0 Likes

#60

Any chance in getting formatted into the clipboard?

Here’s a couple links that I found that may be of some use:
CoffeeGhost - Pyperclip – A cross-platform clipboard module for Python
HTML Clipboard Format (MSDN)

0 Likes

#61

It is possible. I haven’t looked into how to get it formatted into the clipboard proper. Just copying the HTML is not the same. Thanks for the links. I will take a look at them when I get some time. Once i understand what needs to be done to get it properly in the clipboard, I can probably add the feature. Can’t promise when I will get around to it, but I will take a look into it.

0 Likes

#62

Yea, that’s fine. I figured that calling “SetText” on a clipboard object does what you said just as if you were copying text from ST itself. Copying to clipboard would make it easier to paste the formatted text into emails or documents and give this fine text editor one more leg up on Visual Studio :wink:

0 Likes

#63

I understand. Personally I would love to take out the step of opening the browser so I can copy the content and paste it in an email. Hopefully it will be pretty simple once I read up on it. It is just one of those things were the stop gap solution works and hasn’t annoyed me enough yet to force me to fix it, yet it is still annoying enough that I keep thinking I will fix it down the road. :smile:

0 Likes

#64

I grabbed the following code from the Python docs and ran it (Windows 7) and it sent an email for me :smile:

The SMTP settings can be added to the package settings and send() might be replaced with display() or show().

But perhaps it’s not so straight-forward on non-Windows OSes(?).

[code]import smtplib

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

me == my email address

you == recipient’s email address

me = "my@email.com"
you = "your@email.com"

Create message container - the correct MIME type is multipart/alternative.

msg = MIMEMultipart(‘alternative’)
msg’Subject’] = “Link”
msg’From’] = me
msg’To’] = you

Create the body of the message (a plain-text and an HTML version).

text = “Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org”
html = “”"\

Hi!
How are you?
Here is the link you wanted.

"""

Record the MIME types of both parts - text/plain and text/html.

part1 = MIMEText(text, ‘plain’)
part2 = MIMEText(html, ‘html’)

Attach parts into message container.

According to RFC 2046, the last part of a multipart message, in this case

the HTML message, is best and preferred.

msg.attach(part1)
msg.attach(part2)

Send the message via local SMTP server.

s = smtplib.SMTP(‘localhost:25’)

sendmail function takes 3 arguments: sender’s address, recipient’s address

and message to send - here it is sent as one string.

s.sendmail(me, you, msg.as_string())
s.quit()[/code]

0 Likes

#65

[quote=“agibsonsw”]I grabbed the following code from the Python docs and ran it (Windows 7) and it sent an email for me :smile:

The SMTP settings can be added to the package settings and send() might be replaced with display() or show().

But perhaps it’s not so straight-forward on non-Windows OSes(?).

[code]import smtplib

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

me == my email address

you == recipient’s email address

me = "my@email.com"
you = "your@email.com"

Create message container - the correct MIME type is multipart/alternative.

msg = MIMEMultipart(‘alternative’)
msg’Subject’] = “Link”
msg’From’] = me
msg’To’] = you

Create the body of the message (a plain-text and an HTML version).

text = “Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org”
html = “”"\

Hi!
How are you?
Here is the link you wanted.

"""

Record the MIME types of both parts - text/plain and text/html.

part1 = MIMEText(text, ‘plain’)
part2 = MIMEText(html, ‘html’)

Attach parts into message container.

According to RFC 2046, the last part of a multipart message, in this case

the HTML message, is best and preferred.

msg.attach(part1)
msg.attach(part2)

Send the message via local SMTP server.

s = smtplib.SMTP(‘localhost:25’)

sendmail function takes 3 arguments: sender’s address, recipient’s address

and message to send - here it is sent as one string.

s.sendmail(me, you, msg.as_string())
s.quit()[/code][/quote]

Yeah, I use smtplib at work to email myself stuff when certain events occur. If you use something like minirelay or hMailServer on windows, you can set up your own outgoing smtp service on that computer bypassing having to use an external smtp server.

On Mac, and I believe Linux, you can use mailx to send out mail. On mac it uses username@yourpc…something like that. I think in Linux you can actually specify the sender, so yeah sending mail is completely possible.

0 Likes

#66

Simple example that works on Mac or windows (assuming you have a smtp relay setup on windows so you can use localhost as your outgoing smtp server; notice no authentication is needed unless you configure it that way). Keep in mind this is not very robust, only an example.

mailx was a little broken out of the box on Mountain Lion. To fix on Mountain Lion

sudo mkdir -p /Library/Server/Mail/Data/spool sudo /usr/sbin/postfix set-permissions

[pre=#000000]import platform

def send_mail_windows(receiver,* subject*,* body*,* sender*,* server*):
import smtplib
from email.mime.text import MIMEText
msg = MIMEText(body)
msg’to’] = receiver
msg’from’] = sender
msg’subject’] = subject
smtpObj = smtplib.SMTP(server)
smtpObj.sendmail(sender, receiver], msg.as_string())
smtpObj.quit()

def send_mail_mac(receiver,* subject*,* body*):
import subprocess
cmd = “”“echo “%s” | mailx -s “%s” %s”"" % (body, subject, receiver)
p = subprocess.Popen(cmd, shell=True,* stdout*=subprocess.PIPE)
output, errors = p.communicate()
if errors != None:
print errors
if output:
print output

system = platform.system()
if system == “Darwin”:
send_mail_mac(
‘me@gmail.com’,
‘Mail Time’,
“Look mom, I am sending an email!”
)
elif system == “Windows”:
send_mail_windows(
‘me@gmail.com’,
‘Mail Time’,
“Look mom, I am sending an email!”,
‘noreply@CaptainLaserFace.com’,
‘localhost’
)
else:
# Do some linux stuff, probably use mailx
pass[/pre]

0 Likes

#67

As I have found here at my office, our proxy blocks outbound SMTP calls directly. I’d found a way to make calls to send mail through Exchange via a VB script, but that probably won’t help much here.

My point about sending via email was just an example. There are plenty of times where I want to paste code snippets into Word documents SharePoint (yuck) pages, or even (more frequently for me) Evernote where I can save off commonly used snippets of code for searching later.

If we want to email our happily formatted code, is it possible to make a new plugin that piggy-backs off of this one?

0 Likes

#68

[quote=“Grant”]As I have found here at my office, our proxy blocks outbound SMTP calls directly. I’d found a way to make calls to send mail through Exchange via a VB script, but that probably won’t help much here.

My point about sending via email was just an example. There are plenty of times where I want to paste code snippets into Word documents SharePoint (yuck) pages, or even (more frequently for me) Evernote where I can save off commonly used snippets of code for searching later.

If we want to email our happily formatted code, is it possible to make a new plugin that piggy-backs off of this one?[/quote]

Don’t worry, I have no intention of supporting email in this plugin. The code I posted was an example because agibsonw brought it up. I tried to get a script to send emails directly with outlook at work, but it is a pain. I was just showing a basic example I use at work to send emails to myself with some fake email. It works great to notify myself of events when I am away from my computer, but I do not want to write a plugin where I have to support X mail server and Y mail protocol because firewall Z blocks A etc. I just don’t want to support stuff like that.

I will be happy if I can get the HTML formatted properly for clipboard with the major the major OS variants…assuming I can get that done :smile:.

0 Likes

#69

@facelessuser

Soz. I was just pleasantly surprised that the email code worked out of the box :sunglasses:. But, on reflection, I realise that there is a lot more to this than meets the eye. Besides which, the html would need to be stripped of all JS, stylesheets, HTML headers etc… *

Andy.*

0 Likes