aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/formattedText/ParagraphNodeSpec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/formattedText/ParagraphNodeSpec.ts')
-rw-r--r--src/client/views/nodes/formattedText/ParagraphNodeSpec.ts36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/client/views/nodes/formattedText/ParagraphNodeSpec.ts b/src/client/views/nodes/formattedText/ParagraphNodeSpec.ts
index 8799964b3..d41938698 100644
--- a/src/client/views/nodes/formattedText/ParagraphNodeSpec.ts
+++ b/src/client/views/nodes/formattedText/ParagraphNodeSpec.ts
@@ -1,18 +1,18 @@
-import { Node, DOMOutputSpec } from 'prosemirror-model';
+import { Node, DOMOutputSpec, AttributeSpec, TagParseRule } from 'prosemirror-model';
import clamp from '../../../util/clamp';
import convertToCSSPTValue from '../../../util/convertToCSSPTValue';
import toCSSLineSpacing from '../../../util/toCSSLineSpacing';
// import type { NodeSpec } from './Types';
type NodeSpec = {
- attrs?: { [key: string]: any };
+ attrs?: { [key: string]: AttributeSpec };
content?: string;
draggable?: boolean;
group?: string;
inline?: boolean;
name?: string;
- parseDOM?: Array<any>;
- toDOM?: (node: any) => DOMOutputSpec;
+ parseDOM?: Array<TagParseRule>;
+ toDOM?: (node: Node) => DOMOutputSpec;
};
// This assumes that every 36pt maps to one indent level.
@@ -30,7 +30,7 @@ function convertMarginLeftToIndentValue(marginLeft: string): number {
return clamp(MIN_INDENT_LEVEL, Math.floor(ptValue / INDENT_MARGIN_PT_SIZE), MAX_INDENT_LEVEL);
}
-function getAttrs(dom: HTMLElement): Object {
+export function getAttrs(dom: HTMLElement): object {
const { lineHeight, textAlign, marginLeft, paddingTop, paddingBottom } = dom.style;
let align = dom.getAttribute('align') || textAlign || '';
@@ -50,9 +50,31 @@ function getAttrs(dom: HTMLElement): Object {
return { align, indent, lineSpacing, paddingTop, paddingBottom, id };
}
-function toDOM(node: Node): DOMOutputSpec {
+export function getHeadingAttrs(dom: HTMLElement): { align?: string; indent?: number; lineSpacing?: string; paddingTop?: string; paddingBottom?: string; id: string; level?: number } {
+ const { lineHeight, textAlign, marginLeft, paddingTop, paddingBottom } = dom.style;
+
+ let align = dom.getAttribute('align') || textAlign || '';
+ align = ALIGN_PATTERN.test(align) ? align : '';
+
+ let indent = parseInt(dom.getAttribute(ATTRIBUTE_INDENT) || '', 10);
+
+ if (!indent && marginLeft) {
+ indent = convertMarginLeftToIndentValue(marginLeft);
+ }
+
+ indent = indent || MIN_INDENT_LEVEL;
+
+ const lineSpacing = lineHeight ? toCSSLineSpacing(lineHeight) : undefined;
+
+ const level = Number(dom.nodeName.substring(1)) || 1;
+
+ const id = dom.getAttribute('id') || '';
+ return { align, indent, lineSpacing, paddingTop, paddingBottom, id, level };
+}
+
+export function toDOM(node: Node): DOMOutputSpec {
const { align, indent, inset, lineSpacing, paddingTop, paddingBottom, id } = node.attrs;
- const attrs: { [key: string]: any } | null = {};
+ const attrs: { [key: string]: unknown } | null = {};
let style = '';
if (align && align !== 'left') {