xkcd-substitutions icon indicating copy to clipboard operation
xkcd-substitutions copied to clipboard

Fix recursive substitutions, add an option to use the XKCD font, and add mouseovers.

Open piquan opened this issue 8 years ago • 1 comments

I had to rewrite much of the substitution code, but tried to keep the original style. Let me know if there's anything I missed.

This hasn't been heavily tested.

piquan avatar May 20 '16 01:05 piquan

@bencoveney: My original pull request would catch nested terms like #28 describes if we're the only thing mutating the DOM. However, since we can get called multiple times, if another extension changed our subtree, we might end up reprocessing it. I've updated the pull request to account for this.

For instance, we substitute "expand" → "physically expand". Suppose that another extension classifies words according to their parts of speech. Now, see how that would play out.

We substitute expand<span class="xkcd">physically expand</span>. The other extension makes that <span class="xkcd"><span class="adverb">physically</span> <span class="verb">expand</span></span>. Later, we may get another document_end event and reprocess the tree, leading to <span class="xkcd"><span class="adverb">physically</span> <span class="verb"><span class="xkcd">physically expand</span></span></span>. You see the problem.

In the code I originally submitted, we only checked the immediate parent to see if it was a span of class xkcdSubstitutionsExtensionSubbed. Clearly, we should behave well in the presence of other DOM-mutating extensions.

I've updated the pull request to prune the entire subtree at the point of xkcdSubstitutionsExtensionSubbed. This also prunes the subtrees of elements on the ignore list, which has elements like form etc. (Again, previously the code only checked the immediate parent, which makes me wonder if form should have been in the ignore list in the first place.)

piquan avatar May 21 '16 06:05 piquan