Awhile back I noted some ways to copy syntax-highlighted text from TextMate to other applications like VoodooPad and MarsEdit. In some cases it was a simple procedure of two or three steps. But getting syntax-highlighted text into MarsEdit was comparatively tedious.
In all cases the procedure started with the Experimental -> View Document as HTML
bundle. This morning I finally got around to browsing that bundle's definition and lo! it's just a simple Perl script invocation.
Better yet, it can act on either a complete document or just the text you've selected within that document. So if you want to post a code snippet? No problem.
It's also easy to make a copy of the bundle which, instead of creating a new HTML document, creates a plaintext document containing the HTML mark-up. You can copy the contents of this document and paste it directly into MarsEdit. (With a few caveats, i.e. you need to modify the stylesheet to avoid affecting the appearance of your entire post.)
The steps are simple:
Bundles->Bundle Editor->Show Bundle Editor...
Experimental
and select the View Document as HTML
command@My Stuff
bundle, which won't get overwritten when I upgrade TextMateFormat as Raw HTML
Output
popup menu's value from Show as HTML
to Create New Document
Select Bundle Item
command window. Then type in the name of your new command, and hit return.<div>
with a unique timestamp for its id, and to modify the CSS so it applies only to that div. That'll make it easier to create markup that can be dumped directly into a blog regardless of what else might be on the blog page.<style>
block inside the body of a blog post, rather than the head, but it renders okay in WebKit and Firefox 2.
#!/bin/sh
now=date +'%Y%m%d%H%M%S'
cat <
#source_${now} {
font-family: "Bitstream Vera Sans Mono", "Monaco", monospace;
font-size: 12px;
width: 400px;
overflow: auto;
margins: auto;
padding: 4px;
background-color: #ffffff;
border: 1px solid #777788;
}
#source_${now} .comment {
font-style: italic;
color: #888;
}
#source_${now} .keyword {
font-weight: bold;
}
#source_${now} .string {
color: #00F;
}
#source_${now} .entity {
text-decoration: underline;
}
#source_${now} .storage {
color: #888;
}
#source_${now} .support {
color: #0b0;
}
#source_${now} .constant, #source_${now} .variable {
color: #F0F;
}
HTML
perl -pe 's/<\/[^>]+>/<\/span>/g' \
| perl -pe 's/<([^\/.>]+)[^>]*>//g' \
| perl -pe 's/\t/ /g'
echo ""