jgm / djot.js

JavaScript implementation of djot
MIT License
141 stars 15 forks source link

Fix filters to not run twice #61

Closed marrus-sh closed 1 year ago

marrus-sh commented 1 year ago

There are two related changes here:

  1. In the Walker code, this.enter gets set to false unnecessarily early if the node has no children. This causes it to skip the if branch which would otherwise cause the filter to run a second time for exit, and move straight to advancing to the parent node.

  2. In applyFilterPartToNode, the exit filter will be run if enter == false OR if !("enter" in trans). But it should only run in the first case, NOT the second. This commit refactors the code to prevent the exit filter from running twice in the case that no enter filter is defined.

    A test has been added to check for this.

jgm commented 1 year ago

Thanks!