syntax-tree / hast-util-sanitize

utility to sanitize hast nodes
https://unifiedjs.com
MIT License
48 stars 20 forks source link

Add support for allowing comments #11

Closed esatterwhite closed 6 years ago

esatterwhite commented 6 years ago

I see in the tests, that it removes comments, but I'd actaully like to keep comments. Is there an option for it, or how would I be able to do that?

I added

{
  comment: {value: handleValue}
}

in the node schema and that seems to do what I want. Not sure if that is ideal or if there is a better place for it.

wooorm commented 6 years ago

Hmm, that’s funky! a) why? and b) how should we do this?

esatterwhite commented 6 years ago

Well I want comments in the html basically. I'm using HAST to generate html documents from user input via JSON api. So in translating to html, its exceptionally helpful to use html comments to debug.

I use this package to remove scripts, clean up html, etc. But it's also removing my comment markers.

{
   "type": "conversation"
  , ... options
}
<!-- START BLOCK CONVERSATION -->
   ... 3000 lines of generated html
<!-- END BLOCK CONVERSATION -->

That is all I'm really after.

I have a fork, where i did this

const NODES = {
  root: {children: all}
, element: {
    tagName: handleTagName
  , properties: handleProperties
  , children: all
  }
, text: {value: handleValue}
, comment: {value: handleValue}
, '*': {
    data: allow
  , position: allow
  }
}

that allows them, just not sure if that is the most efficient thing? of if you know of a better way?

wooorm commented 6 years ago

That works for your fork, as it allows every comment, right? but that’s no how GH does it, and should be configurable I think.

I think we should check some property in the schema, roughly around here, to see if comments should be allowed?

wooorm commented 6 years ago

@esatterwhite Are you into writing a PR for this?