aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
authoraaravkumar <aarav.kumar1510@gmail.com>2025-03-07 00:13:01 -0500
committeraaravkumar <aarav.kumar1510@gmail.com>2025-03-07 00:13:01 -0500
commit696ae072b1f00d616450d76bc016aebcc1c102fc (patch)
tree97010a729b063ffe39b3b17438b5bf99d5859100 /src/fields
parent1ab6f6c87b746e0c2898694216db50d5faadf7f5 (diff)
attempted adding formatting
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/RichTextField.ts46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts
index 4b1403b88..79ba34ada 100644
--- a/src/fields/RichTextField.ts
+++ b/src/fields/RichTextField.ts
@@ -111,7 +111,7 @@ export class RichTextField extends ObjectField {
type: 'paragraph',
attrs: { align: 'center', color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null },
content: [
- ...(text ? [{ type: 'text', text }] : []), //
+ ...(text ? [{ type: 'text', text }] : []),
...(imgDocId ? [{ type: 'dashDoc', attrs: { width: '200px', height: '200px', title: 'dashDoc', float: 'unset', hidden: false, docId: imgDocId } }] : []),
],
},
@@ -122,4 +122,48 @@ export class RichTextField extends ObjectField {
text
);
}
+
+ // AARAV ADD
+
+ public static textToRtfFormatting(
+ text: string,
+ imgDocId?: string,
+ selectBack?: number,
+ styles?: { bold?: boolean, italic?: boolean, fontSize?: number, color?: string }
+ ) {
+ return new RichTextField(
+ !imgDocId
+ ? this.ToProsemirrorState(text, selectBack)
+ : JSON.stringify({
+ // This is the RichText JSON with the text and optional image
+ doc: {
+ type: 'doc',
+ content: [
+ {
+ type: 'paragraph',
+ attrs: { align: 'center', color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null },
+ content: [
+ {
+ type: 'text',
+ text: text,
+ marks: [
+ ...(styles?.bold ? [{ type: 'bold' }] : []),
+ ...(styles?.italic ? [{ type: 'italic' }] : []),
+ ...(styles?.fontSize ? [{ type: 'textStyle', style: `font-size:${styles.fontSize}px` }] : []),
+ ...(styles?.color ? [{ type: 'textStyle', style: `color:${styles.color}` }] : []),
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ selection: { type: 'text', anchor: 2 + text.length, head: 2 + text.length },
+ }),
+ text
+ );
+ }
+
+
+
+
}