Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to do list support to markdown #10129

Merged
merged 1 commit into from
Oct 22, 2021
Merged

Add to do list support to markdown #10129

merged 1 commit into from
Oct 22, 2021

Conversation

aav7fl
Copy link
Contributor

@aav7fl aav7fl commented Oct 1, 2021

Proposed change

Adds <input> with checked, disabled, and type attributes to the whitelist in renderMarkdown.

This allows checkboxes in the Markdown card to render.

chrome_2021-10-01_14-56-49

Right now we're pulling in getDefaultWhiteList from xs-jss which has a whitelist of allowed HTML tags and attributes. <input> is not on that list (which is necessary for the Markdown checkboxes):

If we choose not to support markdown checkboxes due to xss concerns, I'll happily open a PR instead to update the documentation for the markdown card explaining why.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

type: markdown
content: >-
  - [ ] Checkbox unselected

  - [x] Checkbox selected

Additional information

  • This PR fixes or closes issue: Fixes Markdown checkboxes #10084
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@balloob
Copy link
Member

balloob commented Oct 3, 2021

Can we limit what values type can be?

@aav7fl
Copy link
Contributor Author

aav7fl commented Oct 3, 2021

Can we limit what values type can be?

I believe it can be done by customizing the onTagAttr handler: https://github.com/leizongmin/js-xss#customize-the-handler-function-for-attributes-of-matched-tags

If we return nothing (or undefined), it will continue the default behavior and render the tags and attributes we're checking for.

Else, we return an empty string '' to render nothing for that tag. It still leaves us with an empty <input> tag on improper tags though.

I pushed up a change that does as you describe.

- [ ] Checkbox
- [x] Checkbox
<li><input type="button"></li>
- [x] Checkbox

creates this:

image

Add onTagAttr to ignore unwanted values
@aav7fl
Copy link
Contributor Author

aav7fl commented Oct 10, 2021

Hi @balloob. I was wondering if you have the chance to offer more feedback on the code I added where it's using the onTagAttr as a way to limit the attribute values.

One area I'm not certain about is the usage of returning undefined. The xss library we're using states retuning "nothing" will follow the default behavior in the lib, but our linter doesn't like that (so I return undefined). I can always override the line and return nothing.

Or if the current solution is acceptable, we're good to go.

@aav7fl aav7fl changed the title Fix markdown checkbox Ready: Fix markdown checkbox Oct 12, 2021
@balloob balloob changed the title Ready: Fix markdown checkbox Add to do list support to markdown Oct 22, 2021
@balloob balloob merged commit 2c28095 into home-assistant:dev Oct 22, 2021
@balloob
Copy link
Member

balloob commented Oct 22, 2021

Tested locally and looks all good 👍 Thanks!

@aav7fl aav7fl deleted the fix-markdown-checkbox branch October 22, 2021 15:50
@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Markdown checkboxes
3 participants