Have you ever wanted to publish your source code with your syntax highlighting intact? That is, formatted the way that TextMate sees it? Well, thanks to a recent update to TextMate[1], it's now possible. I've created two commands that are in the TextMate subversion repository[2] that are in the Experimental bundle:
Create HTML from Document / Selection: This command will take your entire document and create a new one that is an HTML file which recreates the view of your document as TextMate renders it. It also preserves the colors that you're using as your current TextMate theme, since it generates the CSS from your theme file. If you have a selection, this command will only output a '<pre>' block for that section (instead of generating a full HTML document plus stylesheet).
Create CSS from Theme: This command creates a new CSS document that is based on your current theme.
So, what is this good for? Well, if you want to publish snippets of code, nicely highlighted, but don't want to create images. Besides, textual examples are better than images since they're searchable. So, you could create the CSS rules based on your theme, then add it to your existing site's stylesheet. Then, you can invoke the "Create HTML..." command to create the HTML.
Why did I do this? There are many syntax highlighting solutions out there (indeed, TM itself has a few commands that do this kind of thing, but they don't reliably reproduce the document the way TM sees it). But this one leverages the document parsing TM does-- and therefore, it works with any language definition that is in your TextMate bundle set. It also doesn't require any additional software to be installed.
Please report any errors you find to me. And thanks again to Allan for adding support necessary to do this.
Brad Choate http://bradchoate.com/
[1] - Release 948's "One can now access the document as parsed by TextMate." new feature. So these commands require that release or later. [2] - http://anon:anon@macromates.com/svn/Bundles/trunk/Bundles/ Experimental.tmbundle/Commands/
On 5/7/06, Brad Choate bchoate@gmail.com wrote:
Have you ever wanted to publish your source code with your syntax highlighting intact? That is, formatted the way that TextMate sees it? Well, thanks to a recent update to TextMate[1], it's now possible. I've created two commands that are in the TextMate subversion repository[2] that are in the Experimental bundle:
Thanks. I have been looking for this.
ip
On May 7, 2006, at 10:31 PM, Brad Choate wrote:
Create CSS from Theme: This command creates a new CSS document that is based on your current theme.
You so totally rock!
thomas Aylott—subtleGradient—oblivious@subtleGradient.com
this is SOOO cool! thank you!
it doesn't color textile-code though. i couldn't figure out, why. sorry.
kind regards, niko.
On 08.05.2006, at 04:31, Brad Choate wrote:
Have you ever wanted to publish your source code with your syntax highlighting intact?
This is one of the best commands ever! Too bad, I don't have any source code to publish.
And as mentioned on IRC, we should convert all the standard themes (at least one of each black on white vs. a white on black) to CSS and put a <select /> box there to switch it.
Soryu.
Please report any errors you find to me
I just replaced the code snapshot of the Balance Jr2 regex on my blog [1] with your stuff. [1] http://subtlegradient.com/articles/2006/05/06/balance-jr-2-0-for- textmate-screencast
It worked out nicely. It looks pretty good. This is an incredibly awesome thing!
Unfortunately the alpha background colors aren't supported across all browsers. Nothing you can really do about that. Also, the .comment class interfered with my blogs .comment class. But there's not really anything that should change about the command for that. People just need to be aware of it.
I don't think there's any way to handle the bool logic in the tmthemes. But you should change it to not include the class name for the style if the name has a minus in front of it.
EG: string -meta_tag -meta_doctype should translate into string not .string .-meta_tag .-meta_doctype
Thanks SO much for this AWESOME stuff!
thomas Aylott—subtleGradient—oblivious@subtleGradient.com
Thanks-- I haven't even noticed the boolean not operator in themes. I'll amend that with the next update.
-Brad
On May 8, 2006, at 10:20 AM, thomas Aylott wrote:
Please report any errors you find to me
I just replaced the code snapshot of the Balance Jr2 regex on my blog[1] with your stuff. [1] http://subtlegradient.com/articles/2006/05/06/balance-jr-2-0- for-textmate-screencast
It worked out nicely. It looks pretty good. This is an incredibly awesome thing!
Unfortunately the alpha background colors aren't supported across all browsers. Nothing you can really do about that. Also, the .comment class interfered with my blogs .comment class. But there's not really anything that should change about the command for that. People just need to be aware of it.
I don't think there's any way to handle the bool logic in the tmthemes. But you should change it to not include the class name for the style if the name has a minus in front of it.
EG: string -meta_tag -meta_doctype should translate into string not .string .-meta_tag .-meta_doctype
Thanks SO much for this AWESOME stuff!
thomas Aylott—subtleGradient—oblivious@subtleGradient.com
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Also, the .comment class interfered with my blogs .comment class. But there's not really anything that should change about the command for that. People just need to be aware of it.
You could actually give the <pre> a class, then make all the css selectors a decentant of the .tmcode class. Might be a nifty thing to have done by default actually.
Also, the .comment class interfered with my blogs .comment class. But there's not really anything that should change about the command for that. People just need to be aware of it.
You could actually give the <pre> a class, then make all the css selectors a decentant of the .tmcode class. Might be a nifty thing to have done by default actually.
That's basically what I did for my blog post.
That would be a nice option, but I don't think I'd like that every time.
thomas Aylott—subtleGradient—oblivious@subtleGradient.com
Yes, I'm taking that approach with the next update.
On May 8, 2006, at 1:22 PM, Michael Sheets wrote:
Also, the .comment class interfered with my blogs .comment class. But there's not really anything that should change about the command for that. People just need to be aware of it.
You could actually give the <pre> a class, then make all the css selectors a decentant of the .tmcode class. Might be a nifty thing to have done by default actually.
You could actually give the <pre> a class, then make all the css selectors a decentant of the .tmcode class. Might be a nifty thing to have done by default actually.
What about having multiple themed code snippets on the same page? You could add the themes name to each item in the CSS to let them play nicely together
thomas Aylott—subtleGradient—oblivious@subtleGradient.com
On 08.05.2006, at 23:47, thomas Aylott wrote:
You could actually give the <pre> a class, then make all the css selectors a decentant of the .tmcode class. Might be a nifty thing to have done by default actually.
What about having multiple themed code snippets on the same page? You could add the themes name to each item in the CSS to let them play nicely together
NO! CSS selectors are the way to go.
pre.twilight .comment
Soryu.
On May 9, 2006, at 1:30 PM, Soryu wrote:
What about having multiple themed code snippets on the same page? You could add the themes name to each item in the CSS to let them play nicely together
NO! CSS selectors are the way to go.
pre.twilight .comment
That's what I said ;)
thomas Aylott—subtleGradient—oblivious@subtleGradient.com