You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
This definitely seems like a flaw in the walking
algorithm; I don't think we should recurse into
newly introduced items like this. I'd rather just
make this the default; perhaps you want to submit a
PR?
By the way, with lua filters it works perfectly!
```lua
function Str(el)
if el.text:match("something") then
return pandoc.Link(pandoc.Str(el.text), "my_target", "", el.attributes)
end
end
```
Is there any way to prevent recursion into the object returned by a filter?
For example:
The above will result in infinite recursion into the string. One possible solution would be to introduce pseudo-types
NoFilterInline
andNoFilterBlock
, which causepandocfilters.walk
to abort recursion down a path of the AST:Is there a better solution?
The text was updated successfully, but these errors were encountered: