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.