From 757742e79c0b62cfe1045194027bd03fcbdb668d Mon Sep 17 00:00:00 2001
From: Silvio Giebl <silvio.giebl@hivemq.com>
Date: Thu, 2 Jan 2020 14:20:09 +0100
Subject: [PATCH] Fixed search result word wrap

---
 _sass/search.scss          |  5 +++++
 assets/js/just-the-docs.js | 21 +++++++++------------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/_sass/search.scss b/_sass/search.scss
index 8c18149a..42ff90de 100644
--- a/_sass/search.scss
+++ b/_sass/search.scss
@@ -166,6 +166,11 @@
     height: $sp-4;
     margin-right: $sp-2;
     fill: $link-color;
+    flex-shrink: 0;
+  }
+
+  .search-result-doc-title {
+    overflow: auto;
   }
 }
 
diff --git a/assets/js/just-the-docs.js b/assets/js/just-the-docs.js
index 126822e3..b0be84e7 100644
--- a/assets/js/just-the-docs.js
+++ b/assets/js/just-the-docs.js
@@ -187,16 +187,17 @@ function searchLoaded(index, docs) {
         resultDoc.innerHTML = '<svg viewBox="0 0 24 24" class="search-result-icon"><use xlink:href="#svg-doc"></use></svg>';
         resultTitle.appendChild(resultDoc);
 
-        var resultDocSpan = document.createElement('span');
-        resultDocSpan.innerHTML = doc.doc;
-        resultDoc.appendChild(resultDocSpan);
-        var resultDocOrSection = resultDocSpan;
+        var resultDocTitle = document.createElement('div');
+        resultDocTitle.classList.add('search-result-doc-title');
+        resultDocTitle.innerText = doc.doc;
+        resultDoc.appendChild(resultDocTitle);
+        var resultDocOrSection = resultDocTitle;
 
         if (doc.doc != doc.title) {
           resultDoc.classList.add('search-result-doc-parent');
           var resultSection = document.createElement('div');
           resultSection.classList.add('search-result-section');
-          resultSection.innerHTML = doc.title;
+          resultSection.innerText = doc.title;
           resultTitle.appendChild(resultSection);
           resultDocOrSection = resultSection;
         }
@@ -325,18 +326,14 @@ function searchLoaded(index, docs) {
       var index = start;
       for (var i in positions) {
         var position = positions[i];
-        var span = document.createElement('span');
-        span.innerHTML = text.substring(index, position[0]);
-        parent.appendChild(span);
+        parent.appendChild(document.createTextNode(text.substring(index, position[0])));
         index = position[0] + position[1];
         var highlight = document.createElement('span');
         highlight.classList.add('search-result-highlight');
-        highlight.innerHTML = text.substring(position[0], index);
+        highlight.innerText = text.substring(position[0], index);
         parent.appendChild(highlight);
       }
-      var span = document.createElement('span');
-      span.innerHTML = text.substring(index, end);
-      parent.appendChild(span);
+      parent.appendChild(document.createTextNode(text.substring(index, end)));
     }
   }
 
-- 
GitLab