My function parses through text, grabs parts and generates text only email format. But it also needs to generate html format.
The brain-dead way would be to use if … else … and add additional html tags around each paragraph or element. But it will violate DRY (don’t repeat yourself) rule.
Is there an elegant way to solve this problem?
As @Pointy said, you should look into templates. jQuery templates, while in beta, are good enough – although there are lots of alternatives for good javascript templates.
In your case, you would do something like:
And then use them like this: