jgm/pandocfilters

Prevent recursion into returned object

garethstockwell opened this issue · 1 comments

Is there any way to prevent recursion into the object returned by a filter?

For example:

from pandocfilters import Link, Str

def my_filter(key, value, format, meta):
    if key == 'Str':
        if 'something' in value:
            return Link(attr, [Str(value)], 'my_target')

The above will result in infinite recursion into the string. One possible solution would be to introduce pseudo-types NoFilterInline and NoFilterBlock, which cause pandocfilters.walk to abort recursion down a path of the AST:

from pandocfilters import NoFilterInline, Link, Str

def my_filter(key, value, format, meta):
    if key == 'Str':
        if 'something' in value:
            return Link(attr, [NoFilterInline([Str(value)])], 'my_target')

Is there a better solution?

jgm commented