Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to skip some HTML tags in processing #183

Open
igormironchik opened this issue Feb 21, 2024 · 1 comment
Open

Add possibility to skip some HTML tags in processing #183

igormironchik opened this issue Feb 21, 2024 · 1 comment

Comments

@igormironchik
Copy link

I'd like to have a possibility to disable emoji conversion in <code> blocks.

@igormironchik
Copy link
Author

I solved this issue in my own code with:

function replace_emoji() {
  let elementsToReplace = document.querySelectorAll('p, h1, h2, h3, h4, h5, h6, li, table');
  let elementsToIgnore = document.querySelectorAll('code');
  for (let i = 0; i < elementsToReplace.length; i++) {
    replace_emoji_in_node(elementsToReplace[i]);
  }

  function replace_emoji_in_node(node) {
    if (node.constructor === Text) {
      node.data = emoji.replace_colons(node.data);
    } else if (node.constructor === HTMLScriptElement || [].indexOf.call(elementsToIgnore, node) >= 0) {
      return;
    } else {
      let childNodes = node.childNodes;
      for (let i = 0; i < childNodes.length; i++) {
        replace_emoji_in_node(childNodes[i]);
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant