On enter keep font-family(mark)

i have font family as a mark(style attribute) i am trying to keep the font family mark on new paragraph

i tried the code below, but its not working :frowning:

 keymap({
      ...baseKeymap,
      Enter: (state, dispatch, view) => {
        const marks = getSelectionMarks(view.state);
        const mark = marks.find(m => m.attrs && m.attrs.fontFamily);
        chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitBlock)(view.state, view.dispatch)
        if(mark && mark.attrs && mark.attrs.fontFamily) {
          const blockType = view.state.selection.$head.parent;
          const newAttrs = {...blockType.attrs, fontFamily:  mark.attrs.fontFamily};
          setBlockType(blockType.type, newAttrs)(view.state, view.dispatch)
        }
        return true;
      }
    })

Is font-family represented as a mark or a block attribute in your schema? Or both?

block attribute example: <span style="font-family: sun serif"> </div>

why we using link as mark and not as node ? what would be the reasons for that ?

Then the thing the code is doing scanning for marks isn’t going to work, right? You need to look at state.selection.$from.parent.attrs instead.

Marks are what ProseMirror uses to model this kind of metadata on inline content. Inline nodes with content are much more awkward to work with.