Added anchor hash to break blocks
This commit is contained in:
parent
14622450cf
commit
8557df4753
|
@ -2,7 +2,9 @@ import {
|
||||||
BreakBlockType,
|
BreakBlockType,
|
||||||
Collections,
|
Collections,
|
||||||
PageType,
|
PageType,
|
||||||
|
RichTextBreakBlock,
|
||||||
RichTextContent,
|
RichTextContent,
|
||||||
|
RichTextSectionBlock,
|
||||||
isBlockNodeBreakBlock,
|
isBlockNodeBreakBlock,
|
||||||
isBlockNodeSectionBlock,
|
isBlockNodeSectionBlock,
|
||||||
isNodeBlockNode,
|
isNodeBlockNode,
|
||||||
|
@ -57,22 +59,33 @@ const handleContent = (
|
||||||
{ root: { children, ...others } }: RichTextContent,
|
{ root: { children, ...others } }: RichTextContent,
|
||||||
parentPrefix = ""
|
parentPrefix = ""
|
||||||
): RichTextContent => {
|
): RichTextContent => {
|
||||||
let sectionCount = 0;
|
let index = 0;
|
||||||
return {
|
return {
|
||||||
root: {
|
root: {
|
||||||
...others,
|
...others,
|
||||||
children: children.map((node) => {
|
children: children.map((node) => {
|
||||||
if (isNodeBlockNode(node) && isBlockNodeSectionBlock(node)) {
|
if (isNodeBlockNode(node)) {
|
||||||
sectionCount++;
|
if (isBlockNodeSectionBlock(node)) {
|
||||||
const anchorHash = `${parentPrefix}${sectionCount}.`;
|
index++;
|
||||||
return {
|
const anchorHash = `${parentPrefix}${index}.`;
|
||||||
...node,
|
const newNode: RichTextSectionBlock = {
|
||||||
fields: {
|
...node,
|
||||||
...node.fields,
|
fields: {
|
||||||
|
...node.fields,
|
||||||
|
content: handleContent(node.fields.content, anchorHash),
|
||||||
|
},
|
||||||
anchorHash,
|
anchorHash,
|
||||||
content: handleContent(node.fields.content, anchorHash),
|
};
|
||||||
},
|
return newNode;
|
||||||
};
|
} else if (isBlockNodeBreakBlock(node)) {
|
||||||
|
index++;
|
||||||
|
const anchorHash = `${parentPrefix}${index}.`;
|
||||||
|
const newNode: RichTextBreakBlock = {
|
||||||
|
...node,
|
||||||
|
anchorHash,
|
||||||
|
};
|
||||||
|
return newNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -198,7 +198,8 @@ export interface RichTextBlockNode extends RichTextNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RichTextSectionBlock extends RichTextBlockNode {
|
export interface RichTextSectionBlock extends RichTextBlockNode {
|
||||||
fields: SectionBlock & { anchorHash: string };
|
fields: SectionBlock;
|
||||||
|
anchorHash: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RichTextTranscriptBlock extends RichTextBlockNode {
|
export interface RichTextTranscriptBlock extends RichTextBlockNode {
|
||||||
|
@ -207,6 +208,7 @@ export interface RichTextTranscriptBlock extends RichTextBlockNode {
|
||||||
|
|
||||||
export interface RichTextBreakBlock extends RichTextBlockNode {
|
export interface RichTextBreakBlock extends RichTextBlockNode {
|
||||||
fields: BreakBlock;
|
fields: BreakBlock;
|
||||||
|
anchorHash: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isNodeParagraphNode = (node: RichTextNode): node is RichTextParagraphNode =>
|
export const isNodeParagraphNode = (node: RichTextNode): node is RichTextParagraphNode =>
|
||||||
|
|
Loading…
Reference in New Issue