Tokenize first, and replace tokens with emphasis tags on a second pass using an algorithm close to one used in CM.