marp-team / marp-core

The core of Marp converter
MIT License
777 stars 130 forks source link

Preserve HTML comments within html block #282

Closed yhatt closed 2 years ago

yhatt commented 2 years ago

Marp Core HTML sanitizer has no longer stripped HTML comments written within HTML block. When allowed HTML by html constructor option, Marp Core will keep HTML comment(s) if wrapped by the HTML tag.

This behavior is helpful for user-side script usage. By wrapping JS by HTML comment, users can prevent escaping special characters in the script into HTML entities (Reported in marp-team/marp#250).

<script>
<!--
if (1 < 2) console.log(true)
-->
</script>

For safety, we have not taken the approach of recognizing script context to switch whether escape or not. Users who want to use the raw inline script always must wrap the script in HTML comment.

When HTML block is consisted by only a single HTML comment, it will be collected as the presenter note by Marpit framework.