Skip to content

Commit

Permalink
feat: heading button that resets heading back to paragraph (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
smsochneg authored Feb 15, 2024
1 parent 67c2300 commit 475c879
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/extensions/yfm/YfmHeading/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ import {setBlockType} from 'prosemirror-commands';
import type {Command} from 'prosemirror-state';
import {findParentNodeOfType} from 'prosemirror-utils';

import {toParagraph} from '../../../extensions/base';

import {hType} from './YfmHeadingSpecs/utils';
import {HeadingLevel, YfmHeadingAttr} from './const';
import {HeadingLevel, YfmHeadingAttr, headingLevelAttr} from './const';

export {resetHeading} from '../../markdown/Heading/commands';

export const toHeading =
(level: HeadingLevel): Command =>
(state, dispatch) => {
(state, dispatch, view) => {
const parentHeading = findParentNodeOfType(hType(state.schema))(state.selection);
if (parentHeading) {
dispatch?.(
state.tr.setNodeMarkup(parentHeading.pos, undefined, {
...parentHeading.node.attrs,
[YfmHeadingAttr.Level]: level,
}),
);

return true;
if (parentHeading && parentHeading.node.attrs[headingLevelAttr] === level) {
return toParagraph(state, dispatch, view);
}

// const text = state.selection.$head.parent.textContent;
Expand Down

0 comments on commit 475c879

Please sign in to comment.