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

Docs schema #28

Closed
wants to merge 4 commits into from
Closed

Docs schema #28

wants to merge 4 commits into from

Conversation

ben519
Copy link

@ben519 ben519 commented Sep 22, 2023

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

TODO

@github-actions github-actions bot added the 👋 phase/new Post is being triaged automatically label Sep 22, 2023
@github-actions

This comment has been minimized.

Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting work in! Some initial feedback!

- [Security](#security)
- [Related](#related)
- [Contribute](#contribute)
- [License](#license)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run npm test to format correctly

Follows [GitHub][] style sanitation.
Follows [GitHub][] style sanitation.

#### Overriding the default schema
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a separate Example section, see for example https://github.com/rehypejs/rehype-sanitize?tab=readme-ov-file#example


// === Output ========
// <h1 id="user-content-bohemian">I'm just a poor boy</h1>
// <h2>From a poor family</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if you don’t use this package directly here, perhaps it should go in rehype-sanitize instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this example doesn’t match project style. Save it in an example.js, run npm test, and you’d get it back formatted

],
...
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to actually fix this bug. So I’d prefer it if this example was unrelated to h2 and className.

@ben519
Copy link
Author

ben519 commented Sep 29, 2023

Appreciate the feedback. I'll try to fix these items tomorrow.

@ben519
Copy link
Author

ben519 commented Sep 29, 2023

Hey, I reviewed this a little more and I thought I'd share my thoughts..

  1. Consider this example from the current docs
// This allows `className` on all elements
const schema = deepmerge(defaultSchema, {attributes: {'*': ['className']}})

This is a little bit misleading. Yes, it allows className on all elements but only if that className does not contradict another rule in the schema. For example, h2 can only have the class name 'sr-only' due to the rule for h2 in the default schema.

I know you mentioned fixing this "bug", but personally I don't see this as a bug. In English, to me this means

Every attribute should be allowed to have the className property

which is distinctly different than saying

The className property should be allowed to have any value

Frankly I think both of these objectives should be supported. (Perhaps they already are, but I think only the first one is.)

  1. The existing schema structure is kind of awkward. For example, input: [['type', 'checkbox', 'radio']] allows type equal to 'checkbox' or 'radio'. This would be more clear with a data structure like input: { type: ['checkbox', 'radio'] } and this data structure would be easier to extend.

Let me know how you want me to proceed. I meant to spend ~10 mutes on this but I'm already a few hours in haha.

@wooorm
Copy link
Member

wooorm commented Oct 26, 2023

I know you mentioned fixing this "bug"

Which bug did you think I meant?

For me this is about solving what these mean:

const a = {
  attributes: {
    '*': ['className', 'x'],
    h2: ['className', 'y']
  }
}

const b = {
  attributes: {
    '*': ['className'],
    h2: ['className', 'x']
  }
}

@wooorm
Copy link
Member

wooorm commented Oct 26, 2023

Yeah so, trying to solve this, runs into two actual problems.

GH allows disabled on all elements. It’s useless but you can have a <p disabled="x"></p> and it will remain.
So we allow it with any value:

'disabled',
.

However, GH normally doesn’t allow inputs at all. Only if they themselves generate them from tasklists (- [ ] to do). To get as close as we can, we also only allow disabled checkboxes:

input: [
['disabled', true],
['type', 'checkbox']
],
.

So this behavior conflicts: if disabled is normally allowed to have any value, your wish also affects inputs.

There’s one more case: id, which is now forced by h2 to be 'footnote-label', and generally allowed.

disabled is useless outside of input, so IMO we can drop that.
And if we by default allow id already, it’s not needed to lock it down on h2. Also, maybe this was a mistake on my part because id should indeed be on headings by default and clobbering solves them

@wooorm wooorm closed this in 63c34b6 Oct 26, 2023
@github-actions

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Oct 26, 2023
@github-actions github-actions bot removed the 👋 phase/new Post is being triaged automatically label Oct 26, 2023
@ben519
Copy link
Author

ben519 commented Oct 27, 2023

Hey, saw your latest commit. I'll test it out and let you know if I run into any problems. In regards to your question, I would assume the answers below

const a = {
  attributes: {
    '*': ['className', 'x'],  // every element can have a className of 'x'
    h2: ['className', 'y']  // h2 can only have a className of 'y'. This supersedes the more general rule above
  }
}

const b = {
  attributes: {
    '*': ['className'],         // every element can have a className with any value
    h2: ['className', 'x']   // h2 can only have a className of 'x'. This supersedes the more general rule above
  }
}

In other words, my assumption is that granular rules supersede (overwrite) generic rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

Successfully merging this pull request may close these issues.

2 participants