I've struggled with this myself recently - here's what I came up with:
http://tinyurl.com/5d364o
(http://trac.tiddlywiki.org/browser/Trunk/contributors/FND/plugins/TiddlerPreviewPlugin.js#L73)
Essentially, the gatherSaveFields method should do most of what you need.
HTH.
-- F.