Skip to content

Instantly share code, notes, and snippets.

@nortonwong
Last active July 25, 2019 16:46
Show Gist options
  • Save nortonwong/e2f9b07391088bcf05ab11b9369d629f to your computer and use it in GitHub Desktop.
Save nortonwong/e2f9b07391088bcf05ab11b9369d629f to your computer and use it in GitHub Desktop.
(() => {
const wrap = (prefix, suffix=prefix) => {
const pref = prefix instanceof Function ? prefix : () => prefix;
const suff = suffix instanceof Function ? suffix : () => suffix;
return e => e.innerHTML = `${pref(e)}${e.innerHTML}${suff(e)}`;
};
const tab = `<span style="white-space: pre;"> </span>`;
$$(`b, strong`).map(wrap(`*`));
$$(`h1, h2, h3, h4, h5, h6`).map(wrap(`**`));
$$(`i, em`).map(wrap(`/`));
$$(`a[href]`).map(wrap(``, e => ` &lt;${e.href}&gt;`));
$$(`ol > li`).map(wrap(`#${tab}`, ``));
$$(`ul > li`).map(wrap(`*${tab}`, ``));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment