From 7e552b6eb3680b8f8daf8161b446219c38cce22b Mon Sep 17 00:00:00 2001
From: weru <onewesh@gmail.com>
Date: Fri, 13 Nov 2020 06:54:45 +0000
Subject: [PATCH] update

---
 assets/js/search.js          |    8 ++++----
 assets/js/functions.js       |   40 ++++++++++++++++++++++++++++------------
 assets/sass/_components.sass |    2 +-
 3 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/assets/js/functions.js b/assets/js/functions.js
index 9b17076..a72f3d3 100644
--- a/assets/js/functions.js
+++ b/assets/js/functions.js
@@ -107,33 +107,49 @@
   }
 }
 
-
-function wrapText(text, context, wrapper = 'div') {
-  let c = context.textContent;
-  let index = c.indexOf(text);
-
-  function wrap() {
+function wrapText(text, context) {
+  function wrap(context, wrapper = 'mark') {
+    let c = context.innerHTML;
+    let open = `<${wrapper}>`;
+    let close = `</${wrapper}>`;
+    let index = c.indexOf(text);
     if (index >= 0) {
       let stop = index + text.length;
       let s = c.substring(index,stop);
       let before = c.substring(0,index);
       let after = c.substring(stop);
-      c = `${before}<${wrapper}>${s}</${wrapper}>${after}`;
-      context.textContent = c;
+      c = `${before}${open}${s}${close}${after}`;
+      context.innerHTML = c;
+
+      // add class attribute later if need be
+      const attributes = ["href", "id", "title"];
+      attributes.forEach(function(attr){
+        if(context.hasAttribute(attr)) {
+          let attrValue = context.getAttribute(attr);
+          context.setAttribute(attr, attrValue.replaceAll(`${open}`,"").replaceAll(`${close}`,""));
+        }
+      });
     }
   }
 
-  const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code"];
-  const attributes = ["href", "title", "class", "id"];
+  const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code", "td", "pre"];
   const children = ["span", "em", "strong", "b", "a"];
   contents.forEach(function(c){
-    const cs = elems(c);
+    const cs = elems(c, context);
     if(cs.length) {
       cs.forEach(function(cx){
-        // console.log(cx);
+        if(cx.children.length >= 1) {
+          wrap(cx);
+          Array.from(cx.children).forEach(function(child){
+            wrap(child);
+          })
+        } else {
+          wrap(cx);
+        }
         // check if
         // if has children
            // check if childen is in children array above
+           // filter out children if listed in cs array above
            // check if children contain attributes
           // process before replacing
         // else replace and move on
diff --git a/assets/js/search.js b/assets/js/search.js
index cb485e2..e9a4347 100644
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -70,9 +70,9 @@
   const urlParams = new URLSearchParams(window.location.search);
   if(urlParams.has(query)){
     let c = urlParams.get(query);
-    window.find(c);
+    // window.find(c);
     cc = `${c.charAt(0).toUpperCase()}${c.substring(1,c.length)}`;
-    window.find(cc);
+    // window.find(cc);
     return [c, cc];
   }
   return ["",""];
@@ -84,7 +84,7 @@
 }
 const searchQuery = findQuery();
 // console.log(searchQuery);
-// wrapText(searchQuery[0],main,'mark');
-wrapText(searchQuery[1],main,'mark');
+wrapText(searchQuery[0],main);
+wrapText(searchQuery[1],main);
 
 window.addEventListener('load', () => search());
\ No newline at end of file
diff --git a/assets/sass/_components.sass b/assets/sass/_components.sass
index 81a505d..560e7dc 100644
--- a/assets/sass/_components.sass
+++ b/assets/sass/_components.sass
@@ -71,7 +71,7 @@
   background-color: var(--theme)
   color: var(--light)
   border-radius: 0.25rem
-  display: inline-grid
+  display: inline-flex
   padding: 0.75rem 1.5rem
   text-align: center
   &:hover

--
Gitblit v1.10.0