aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ComparisonBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/ComparisonBox.tsx')
-rw-r--r--src/client/views/nodes/ComparisonBox.tsx44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx
index ccbe98257..f8cf0f464 100644
--- a/src/client/views/nodes/ComparisonBox.tsx
+++ b/src/client/views/nodes/ComparisonBox.tsx
@@ -425,6 +425,27 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
}
}
+ textToRtf = (text: string, img?: Doc) =>
+ new RichTextField(
+ JSON.stringify({
+ // this is a RichText json that has the question text placed above a related 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: [
+ ...(text ? [{ type: 'text', text }] : []), //
+ ...(img ? [{ type: 'dashDoc', attrs: { width: '200px', height: '200px', title: 'dashDoc', float: 'unset', hidden: false, docId: img[Id] } }] : []),
+ ],
+ },
+ ],
+ },
+ selection: { type: 'text', anchor: 2, head: 2 },
+ }),
+ text
+ );
/**
* Transfers the content of flashcards into a flashcard pile.
*/
@@ -440,25 +461,8 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
const questionTxt = question[0].includes('Answer: ') ? question[0].split('Answer: ')[0] : question[0];
const answerTxt = question[0].includes('Answer: ') ? question[0].split('Answer: ')[1] : question[1];
this.fetchImages(question[1]).then(img => {
- const rtfiel = new RichTextField(
- JSON.stringify({
- // this is a RichText json that has the question text placed above a related image
- doc: {
- type: 'doc',
- content: [
- {
- type: 'paragraph',
- attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null },
- content: [{ type: 'text', text: questionTxt }, img ? { type: 'dashDoc', attrs: { width: '200px', height: '200px', title: 'dashDoc', float: 'unset', hidden: false, docId: img[Id] } } : {}],
- },
- ],
- },
- selection: { type: 'text', anchor: 2, head: 2 },
- }),
- questionTxt
- );
- newDoc[DocData][this.fieldKey + '_1'] = Docs.Create.TextDocument(questionTxt, { text: rtfiel });
- newDoc[DocData][this.fieldKey + '_0'] = Docs.Create.TextDocument(answerTxt);
+ newDoc[DocData][this.fieldKey + '_1'] = Docs.Create.TextDocument(this.textToRtf(questionTxt));
+ newDoc[DocData][this.fieldKey + '_0'] = Docs.Create.TextDocument(this.textToRtf(answerTxt, img));
});
}
@@ -723,7 +727,7 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
const side = this._frontSide ? 1 : 0;
const dataSplit = StrCast(this.dataDoc.data).includes('Keyword: ') ? StrCast(this.dataDoc.data).split('Keyword: ') : StrCast(this.dataDoc.data).split('Answer: ');
const textCreator = (which: number, title: string, text: string) => {
- const newDoc = Docs.Create.TextDocument(text, {
+ const newDoc = Docs.Create.TextDocument(this.textToRtf(text), {
title, //
_layout_autoHeight: true,
_layout_centered: true,