Skip to content

Support ClassAttributor if prefix == '' #149

@StanlyShauro

Description

@StanlyShauro

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions