Skip to content

how to custom attr in node? #1884

Closed Answered by Saul-Mirone
dingshaohua-com asked this question in Q&A
Discussion options

You must be logged in to vote

You'll also need to extend the heading schema and modify the parseMarkdown and toMarkdown method.

const yourSchema = headingSchema.extendSchema((prev) => {
  return ctx => {
    const baseSchema = prev(ctx)
    return {
      ...baseSchema,
      attrs: {
        ...baseSchema.attrs,
        hProperties: {
          default: null,
        },
        parseMarkdown: {
          ...baseSchema.parseMarkdown,
          runner: (state, node, type) => {
            const depth = node.depth as number
            const hProperties = node.data.hProperties,
            state.openNode(type, { level: depth, hProperties })
            state.next(node.children)
            state.closeNode()
          }

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by dingshaohua-com
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1883 on May 15, 2025 14:42.