From 02659eaa018774735c428123e9746f5cb8d8c349 Mon Sep 17 00:00:00 2001
From: weru <onewesh@gmail.com>
Date: Fri, 13 Nov 2020 07:37:24 +0000
Subject: [PATCH] update

---
 assets/js/functions.js |   36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/assets/js/functions.js b/assets/js/functions.js
index a72f3d3..f6d2d52 100644
--- a/assets/js/functions.js
+++ b/assets/js/functions.js
@@ -107,11 +107,11 @@
   }
 }
 
-function wrapText(text, context) {
-  function wrap(context, wrapper = 'mark') {
+function wrapText(text, context, wrapper = 'mark') {
+  let open = `<${wrapper}>`;
+  let close = `</${wrapper}>`;
+  function wrap(context) {
     let c = context.innerHTML;
-    let open = `<${wrapper}>`;
-    let close = `</${wrapper}>`;
     let index = c.indexOf(text);
     if (index >= 0) {
       let stop = index + text.length;
@@ -120,20 +120,11 @@
       let after = c.substring(stop);
       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", "td", "pre"];
-  const children = ["span", "em", "strong", "b", "a"];
+
   contents.forEach(function(c){
     const cs = elems(c, context);
     if(cs.length) {
@@ -146,14 +137,17 @@
         } 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
+        // sanitize urls and ids
       });
     }
   });
+
+  const hyperLinks = elems('a');
+  if(hyperLinks) {
+    hyperLinks.forEach(function(link){
+      const href = link.href.replaceAll(encodeURI(open), "").replaceAll(encodeURI(close), "");
+      console.log(open, close);
+      link.href = href;
+    });
+  }
 }
\ No newline at end of file

--
Gitblit v1.10.0