尝试在用户帖子中替换/自动格式化字符串

好的!看来 decorateCookedElement 正是我需要的(根据 @Arkshine 的注释)。

我还发现了这篇帖子,其中包含一些关于过滤感兴趣元素的不错示例:
如何在 DOM 中渲染主题 HTML 后触发脚本? - dev - Discourse Meta

特别是,我觉得这个非常有帮助:

$.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 });

谢谢!

2 个赞