-
Couldn't load subscription status.
- Fork 30
Add data-line attrs support for heading and paragraph #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ export enum BaseNode { | |
| Paragraph = 'paragraph', | ||
| } | ||
|
|
||
| const headingLineNumberAttr = 'data-line'; | ||
|
|
||
| export const pType = nodeTypeFactory(BaseNode.Paragraph); | ||
|
|
||
| export type BaseSchemaSpecsOptions = { | ||
|
|
@@ -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}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
so maybe check should be
square brackets is missed: |
||
| 0, | ||
| ]; | ||
| }, | ||
| placeholder: opts.paragraphPlaceholder | ||
| ? { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]; | ||
|
|
@@ -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, | ||
|
|
@@ -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}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| 0, | ||
| ]; | ||
| }, | ||
| placeholder: { | ||
| content: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's paragraph's attribute name)