Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/extensions/base/BaseSchema/BaseSchemaSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export enum BaseNode {
Paragraph = 'paragraph',
}

const headingLineNumberAttr = 'data-line';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headingLineNumberAttr

it's paragraph's attribute name)


export const pType = nodeTypeFactory(BaseNode.Paragraph);

export type BaseSchemaSpecsOptions = {
Expand Down Expand Up @@ -38,11 +40,18 @@ export const BaseSchemaSpecs: ExtensionAuto<BaseSchemaSpecsOptions> = (builder,
}))
.addNode(BaseNode.Paragraph, () => ({
spec: {
attrs: {[headingLineNumberAttr]: {default: null}},
content: 'inline*',
group: 'block',
parseDOM: [{tag: 'p'}],
toDOM() {
return ['p', 0];
toDOM(node) {
const lineNumber = node.attrs[headingLineNumberAttr];

return [
'p',
lineNumber === undefined ? {} : {headingLineNumberAttr: lineNumber},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{default: null}

so maybe check should be lineNumber === null ?

{headingLineNumberAttr: lineNumber}

square brackets is missed: {[headingLineNumberAttr]: lineNumber}

0,
];
},
placeholder: opts.paragraphPlaceholder
? {
Expand Down
11 changes: 9 additions & 2 deletions src/extensions/markdown/Heading/HeadingSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {nodeTypeFactory} from '../../../../utils/schema';

export const headingNodeName = 'heading';
export const headingLevelAttr = 'level';
export const headingLineNumberAttr = 'data-line';
export const headingType = nodeTypeFactory(headingNodeName);

const DEFAULT_PLACEHOLDER = (node: Node) => 'Heading ' + node.attrs[headingLevelAttr];
Expand All @@ -18,7 +19,7 @@ export type HeadingSpecsOptions = {
export const HeadingSpecs: ExtensionAuto<HeadingSpecsOptions> = (builder, opts) => {
builder.addNode(headingNodeName, () => ({
spec: {
attrs: {[headingLevelAttr]: {default: 1}},
attrs: {[headingLevelAttr]: {default: 1}, [headingLineNumberAttr]: {default: null}},
content: '(text | inline)*',
group: 'block',
defining: true,
Expand All @@ -31,7 +32,13 @@ export const HeadingSpecs: ExtensionAuto<HeadingSpecsOptions> = (builder, opts)
{tag: 'h6', attrs: {[headingLevelAttr]: 6}},
],
toDOM(node) {
return ['h' + node.attrs[headingLevelAttr], 0];
const lineNumber = node.attrs[headingLineNumberAttr];

return [
'h' + node.attrs[headingLevelAttr],
lineNumber === undefined ? {} : {headingLineNumberAttr: lineNumber},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

0,
];
},
placeholder: {
content:
Expand Down
1 change: 1 addition & 0 deletions src/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export {headingLevelAttr, headingNodeName} from '../../../markdown/Heading/Headi
export const YfmHeadingAttr = {
Level: headingLevelAttr,
Id: 'id',
DataLine: 'data-line',
} as const;
7 changes: 6 additions & 1 deletion src/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const YfmHeadingSpecs: ExtensionAuto<YfmHeadingSpecsOptions> = (builder,
attrs: {
[YfmHeadingAttr.Id]: {default: ''},
[YfmHeadingAttr.Level]: {default: 1},
[YfmHeadingAttr.DataLine]: {default: null},
},
content: '(text | inline)*',
group: 'block',
Expand All @@ -36,9 +37,13 @@ export const YfmHeadingSpecs: ExtensionAuto<YfmHeadingSpecsOptions> = (builder,
],
toDOM(node) {
const id = node.attrs[YfmHeadingAttr.Id];
const lineNumber = node.attrs[YfmHeadingAttr.DataLine];
return [
'h' + node.attrs[YfmHeadingAttr.Level],
id ? {id} : {},
{
id: id || null,
[YfmHeadingAttr.DataLine]: lineNumber === undefined ? null : lineNumber,
},
0,
// [
// 'a',
Expand Down