accept RegExp type block class config
This commit is contained in:
@@ -89,7 +89,7 @@ function isSVGElement(el: Element): boolean {
|
|||||||
function serializeNode(
|
function serializeNode(
|
||||||
n: Node,
|
n: Node,
|
||||||
doc: Document,
|
doc: Document,
|
||||||
blockClass: string,
|
blockClass: string | RegExp,
|
||||||
): serializedNode | false {
|
): serializedNode | false {
|
||||||
switch (n.nodeType) {
|
switch (n.nodeType) {
|
||||||
case n.DOCUMENT_NODE:
|
case n.DOCUMENT_NODE:
|
||||||
@@ -105,7 +105,16 @@ function serializeNode(
|
|||||||
systemId: (n as DocumentType).systemId,
|
systemId: (n as DocumentType).systemId,
|
||||||
};
|
};
|
||||||
case n.ELEMENT_NODE:
|
case n.ELEMENT_NODE:
|
||||||
const needBlock = (n as HTMLElement).classList.contains(blockClass);
|
let needBlock = false;
|
||||||
|
if (typeof blockClass === 'string') {
|
||||||
|
needBlock = (n as HTMLElement).classList.contains(blockClass);
|
||||||
|
} else {
|
||||||
|
(n as HTMLElement).classList.forEach(className => {
|
||||||
|
if (blockClass.test(className)) {
|
||||||
|
needBlock = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
const tagName = (n as HTMLElement).tagName.toLowerCase();
|
const tagName = (n as HTMLElement).tagName.toLowerCase();
|
||||||
let attributes: attributes = {};
|
let attributes: attributes = {};
|
||||||
for (const { name, value } of Array.from((n as HTMLElement).attributes)) {
|
for (const { name, value } of Array.from((n as HTMLElement).attributes)) {
|
||||||
@@ -219,7 +228,7 @@ export function serializeNodeWithId(
|
|||||||
n: Node,
|
n: Node,
|
||||||
doc: Document,
|
doc: Document,
|
||||||
map: idNodeMap,
|
map: idNodeMap,
|
||||||
blockClass: string,
|
blockClass: string | RegExp,
|
||||||
skipChild = false,
|
skipChild = false,
|
||||||
): serializedNodeWithId | null {
|
): serializedNodeWithId | null {
|
||||||
const _serializedNode = serializeNode(n, doc, blockClass);
|
const _serializedNode = serializeNode(n, doc, blockClass);
|
||||||
|
|||||||
Reference in New Issue
Block a user