Uploaded image for project: 'OpenOLAT'
  1. OpenOLAT
  2. OO-3531

QTI2 editor: <u> elements are removed from DOM when copy/paste text

    XMLWordPrintable

    Details

      Description

      There is a special case where <u> elements and their subelements are removed from DOM. This happens if a text i.g. "this is an important question" is copied from LibreOffice or Word and pasted in TinyMCE editor element. The underlined text is tagged with <u> elements in the clipboard. The QTI2 parser removes the whole element from DOM because <u> is not defined in QTI2 standard. This is okay because <u> is marked as deprecated since HTML 4.01 and is redefined in HTML5 i.g. for spell checking (underlining misspelled words). For underlining text TinyMCE uses <span style="text-decoration: underline;">

      The following patch redefines <u> with <span style=...> in the DOM:

      diff --git a/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java b/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java
      --- a/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java
      +++ b/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java
      @@ -243,6 +243,11 @@
       					video = true;
       					return;
       				}
      +			} else if("u".equals(localName)) {
      +				qName = "span";
      +				AttributesImpl attribute = new AttributesImpl("");
      +				attribute.addAttribute("style", "text-decoration: underline;");
      +				attributes = attribute;
       			}
       			super.startElement(uri, localName, qName, attributes);
       		}
      

      Another optipon can be to replace substrings in the pure HTML:

      diff --git a/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java b/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java
      --- a/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java
      +++ b/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java
      @@ -149,6 +149,7 @@
       				if(htmlFragment.startsWith("<p>&nbsp;")) {
       					htmlFragment = htmlFragment.replace("<p>&nbsp;", "<p>");
       				}
      +				htmlFragment = htmlFragment.replace("<u>", "<span style=\"text-decoration: underline;\">").replace("</u>", "</span>");
       			} else {
       				htmlFragment = "<p>" + htmlFragment + "</p>";
       			}
      

        Attachments

          Activity

            People

            Assignee:
            srosse Stéphane Rossé
            Reporter:
            stephan Stephan Clemenz
            Tester:
            Mandy Menzel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 40 minutes
                40m