本文整理匯總了TypeScript中@wordpress/blocks.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了parse函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: updateEditorCitations
function* updateEditorCitations(citations: Processor.CitationMeta[]) {
const doc = getEditorDOM();
for (const { html, id, sortedItems } of citations) {
const node = doc.querySelector<HTMLElement>(
createSelector(
...CitationElement.legacyClassNames.map(cls => ({
classNames: [cls],
attributes: { id },
})),
),
);
if (node) {
node.innerHTML = html;
node.dataset.items = sortedItems;
if (node.firstElementChild) {
node.dataset.hasChildren = 'true';
node.firstElementChild.innerHTML =
ZERO_WIDTH_SPACE +
node.firstElementChild.innerHTML +
ZERO_WIDTH_SPACE;
} else {
delete node.dataset.hasChildren;
node.innerHTML = ZERO_WIDTH_SPACE + html + ZERO_WIDTH_SPACE;
}
}
}
yield dispatch('core/block-editor').resetBlocks(parse(doc.innerHTML));
}
示例2: removeReferences
export function* removeReferences(itemIds: string[]) {
const doc = getEditorDOM();
const toDelete = [
...doc.querySelectorAll<HTMLSpanElement>(CitationElement.selector),
].reduce(
(idsToDelete, citation) => {
const existingIds = CitationElement.getItems(citation);
const filteredItemIds = existingIds.filter(
id => !itemIds.includes(id),
);
if (filteredItemIds.length === 0 && citation.parentNode) {
citation.parentNode.removeChild(citation);
} else {
citation.dataset.items = JSON.stringify(filteredItemIds);
}
return idsToDelete.filter(id => !existingIds.includes(id));
},
[...itemIds],
);
yield dispatch('core/block-editor').resetBlocks(parse(doc.innerHTML));
if (toDelete.length > 0) {
yield {
type: Actions.REMOVE_REFERENCES,
itemIds: toDelete,
};
yield save();
}
}
示例3: parseFootnotes
export function* parseFootnotes() {
const doc = getEditorDOM();
doc.querySelectorAll(FootnoteElement.selector).forEach((footnote, i) => {
footnote.innerHTML = FootnoteElement.createMarker(i);
});
yield dispatch('core/block-editor').resetBlocks(parse(doc.innerHTML));
yield setFootnotes();
}
示例4: removeAllCitations
export function* removeAllCitations() {
const doc = getEditorDOM();
for (const el of doc.querySelectorAll(CitationElement.selector)) {
if (el.parentNode) {
el.parentNode.removeChild(el);
}
}
yield dispatch('core/block-editor').resetBlocks(parse(doc.innerHTML));
}