[TxMt] Scope, Document and insert_text
Allan Odgaard
throw-away-1 at macromates.com
Sun Oct 1 09:33:42 UTC 2006
On 1/10/2006, at 5:07, Brett Terpstra wrote:
> [...] After I've accepted an entire document as input, chosen tags
> and have a string ready to print, what's the most elegant way to
> make sure that string gets inserted in the blog post headers rather
> than at the end of the file?
Assuming this is Ruby:
header = "Category: dummy\n"
document.sub!(/^(?![A-Za-z0-9]+:)/, header)
That should insert the header below the last header line, or top of
file if no headers.
For bonus points you might want to insert an additional blank line,
when there were no preexisting headers.
More information about the textmate
mailing list