Trying to replace / auto-format strings in user posts

All right! It seems that decorateCookedElement is what I needed (per @Arkshine note).

I also found this post that has some nice examples to filter on elements of interest:
How do we fire scripts after topic HTML is rendered in DOM? - dev - Discourse Meta

In particular, I found this very helpful:

$.fn.doSomething = function() {
  const targetElement = $(this).children("[data-theme-test]").length;
  if (!targetElement) return;

  // do your work
  
  return this;
};

api.decorateCooked($elem => $elem.doSomething(), { onlyStream: true });

Thank you!

2 Likes