xoofx / markdig

A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
BSD 2-Clause "Simplified" License
4.21k stars 444 forks source link

Question: Sanitize Markdown #762

Closed molinch closed 6 months ago

molinch commented 6 months ago

First of all thanks for the awesome lib!

Are you aware of a possibility to parse a string that contains Markdown and sanitize it to ensure only the allowed Markdown functionalities remain? In our case we want to guarantee we want to guarantee we can only use bold/italic/lists/links.

xoofx commented 6 months ago

Are you aware of a possibility to parse a string that contains Markdown and sanitize it to ensure only the allowed Markdown functionalities remain? In our case we want to guarantee we want to guarantee we can only use bold/italic/lists/links.

Yes, it is possible. Markdig provides the full Abstract Syntax Tree (AST) of a parsed Markdown document. You can process this AST to remove any nodes that are not relevant for your case.

molinch commented 6 months ago

Merci Alexandre. I'll go that way :)