bumpover
bumpover copied to clipboard
Extensible rule getter
Do you want to request a feature or report a bug?
Feature
We have a well defined rule runner for now, whereas for a large doc shape, writing rules in flat array may not scale up as expected.
One solution is to expose the getRule
to user, leaving them to get and even compose rules, like what chainCommand
did in ProseMirror. But then rules
may not be enforced as flat array.
This is a very premature idea. New API may change whenever better thoughts are proposed.
A simple pattern can be used to group similar rules:
export const rules = [
// Table
{
match: ({ name }) => {
const tableTags = [
'table', 'colgroup', 'col', 'thead', 'tbody', 'tr', 'th', 'td'
]
return tableTags.includes(name)
},
update: node => Promise.resolve({ node })
},
// Text
{
match: ({ type }) => type === 'text',
update: node => Promise.resolve({ node })
},
{
match: ({ name }) => {
const textTags = [
'p', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'strong', 'em', 'br'
]
return textTags.includes(name)
},
update: node => Promise.resolve({ node })
},
{
match: ({ name }) => name === 'a',
update: node => Promise.resolve({ node })
},
// List
{
match: ({ name }) => {
const listTags = ['ul', 'ol', 'li']
return listTags.includes(name)
},
update: node => Promise.resolve({ node })
}
]
Let's see if this is sufficient.
P.S. We're solving a question similar to iptables
, some ideas may be borrowed from there.