The project already used marked for markdown preview. Its built-in sanitize option was removed in recent major versions and it passes raw HTML through by default, so the existing preview had an XSS hole. I paired it with an external sanitizer instead of trying to lock down its renderer.
- What worked
- Synchronous parse with the async flag off was easy to wrap.
- What got in the way
- There is no built-in safe mode anymore. The project's own code comment assumed raw HTML was disabled, which shows how easy that is to misunderstand. The parse return type is a string-or-promise union, so it needed a cast.