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

Support ClassAttributor if prefix == '' #149

Open
StanlyShauro opened this issue Jul 25, 2024 · 0 comments
Open

Support ClassAttributor if prefix == '' #149

StanlyShauro opened this issue Jul 25, 2024 · 0 comments

Comments

@StanlyShauro
Copy link

Dear all,

Problem:
There is a list of classes, e.g. class1, class2, class3.
We have them rolled up into format my_class like this

import { ClassAttributor, Scope} from 'parchment';
const config = {
  scope: Scope.BLOCK,
  whitelist: ['class1', 'class2', 'class3']
};

const AlignClass = new ClassAttributor('align', '', config);

Draw attention, prefix is an empty string.

In this case I expect dom element classes like class1, class2, class3, but they are -class1, -class2 -class3.

Current code does not support empty prefix
src/attributor/class.ts

function match(node: HTMLElement, prefix: string): string[] {
  const className = node.getAttribute('class') || '';
  return className
    .split(/\s+/)
    .filter((name) => name.indexOf(`${prefix}-`) === 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant