What is the best way to store WMD input/markdown in SQL server and display later?

后端 未结 2 1960
深忆病人
深忆病人 2020-12-24 03:59

I\'m looking at using WMD in my project instead of my existing RadEditor. I have been reading a few posts on how to store and retrieve the data, and I want to make sure I h

2条回答
  •  隐瞒了意图╮
    2020-12-24 04:12

    So one of the ides behind Markdown is that it will produce "safe" html - there should be no need for separate encoding.

    More generally I would recommend storing "raw" data in the database, without transforming it or sanitising it. You should always sanitise or transform as close to the rendering point as possible - it gives greater flexibility (oh, suddenly I need to render as RSS. Or JSON. Damn, I can't because I pre-formatted for HTML) and, should the sanitiser or renderer be updated you see the effects of the update on every piece of data.

    I would say store the markdown text in the database, and then convert it when you want it rendered, using the markdown library for this which, in theory, should all safe HTML built from its safe list of tags and attributes.

提交回复
热议问题