From cbfa15561e8f030d153b448da3d0427bd450b8f3 Mon Sep 17 00:00:00 2001
From: anisa kusumadewi <kusumadewi@itc.rwth-aachen.de>
Date: Wed, 26 Oct 2022 11:47:12 +0200
Subject: [PATCH] fix comment pdf view

---
 locallib.php    |  2 +-
 shared/index.js | 24 +++++++++++-------------
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/locallib.php b/locallib.php
index 7a0daf6..ebcbcc9 100644
--- a/locallib.php
+++ b/locallib.php
@@ -64,7 +64,7 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page =
     // Load and execute the javascript files.
     $PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/pdf.js?ver=00002"));
     $PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/textclipper.js"));
-    $PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/index.js?ver=00030"));
+    $PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/index.js?ver=00031"));
     $PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00005"));
 
     // Pass parameters from PHP to JavaScript.
diff --git a/shared/index.js b/shared/index.js
index f3f1002..42e1753 100644
--- a/shared/index.js
+++ b/shared/index.js
@@ -809,16 +809,16 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
                                      * it contains latex formulae images or not and place its text and/or images on the pdf
                                      */
                                     function breakLines(author=null, timemodified=null, post, characters = 130) {
-                                        if (typeof post === "string") { // Answer contains text only.
-                                            printTextblock(author, timemodified, post, characters);        
-                                        }
-
-                                        if (typeof post === "object") { // Answer is an array of text (optional) and a png image of a latex formula.
-                                            // 1. print the author right away
-                                            printAuthor(author, timemodified);
-                                            // 2. Print text and - if present - images (latex formulae).
-                                            post.forEach(printItem);
-                                        }
+                                        // 1. print the author right away
+                                        printAuthor(author, timemodified);
+                                        post.forEach(function(subContent) {
+                                            // Answer contains text only or any object such as array.
+                                            if (typeof subContent === "string") { 
+                                                printTextblock(author, timemodified, subContent, characters);
+                                            } else if (typeof subContent === "object") {
+                                                printItem(subContent);
+                                            }
+                                        });
                                     }
                                     /**
                                      * Take a text block, split it into pieces no larger than 130 characters
@@ -831,9 +831,7 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
                                         text = text.replace(/<br \/>/g, "\n");
                                         // Remove all other HTML-Tags.
                                         text = $("<div>").html(text).text();
-                                        if (author !== null) {
-                                            printAuthor(author, timemodified);
-                                        }
+                                        
                                         var stringarray = doc.splitTextToSize(text, characters);
                                         var textbit;
                                         for (var j = 0; j < stringarray.length; j++) {
-- 
GitLab