mirror of https://github.com/onweru/compose.git

weru
12.50.2020 7a6cd4a40be60be67aa1cc5534fffa2e348e329a
assets/js/functions.js
@@ -107,17 +107,37 @@
  }
}
function wrapText(text, context, wrapper = 'div') {
  let c = context.textContent;
  let index = c.indexOf(text);
  console.log(context);
  // h1, h2, h3, h4, h5, h6, p, code, a,
  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;
  function wrap() {
    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;
    }
  }
  const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code"];
  const attributes = ["href", "title", "class", "id"];
  const children = ["span", "em", "strong", "b", "a"];
  contents.forEach(function(c){
    const cs = elems(c);
    if(cs.length) {
      cs.forEach(function(cx){
        // console.log(cx);
        // check if
        // if has children
           // check if childen is in children array above
           // check if children contain attributes
          // process before replacing
        // else replace and move on
      });
    }
  });
}