Conversation
dgtlmoon#4477 A `source:` watch passes append_pretty_line_formatting=False to the filter helpers, and then keeps the filtered text verbatim instead of running it through html_to_text(). TEXT_FILTER_LIST_LINE_SUFFIX ('<br>') only works because Inscriptis turns it into a newline, so for that path no separator was emitted at all and every match ran into the next on a single line. Add filter_match_separator(), which picks '\n' instead of '<br>' when the result will not be passed through Inscriptis, and use it from xpath_filter(), xpath1_filter() and include_filters() - all three carried the same condition. The first match still never gets a separator, so no leading newline is introduced, and the Inscriptis path is byte-for-byte unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4477
The problem
A watch on a
source:URL passesappend_pretty_line_formatting=Falseto the filter helpers, and its filtered text is then kept verbatim instead of being run throughhtml_to_text():TEXT_FILTER_LIST_LINE_SUFFIXis"<br>", which only works as a line separator because Inscriptis turns it back into a newline later on. For asource:watch that step never runs, so the code skipped the separator entirely — and with no separator at all, every match ran straight into the next on one line.Reported on
source:https://www.wikipedia.org/with the//link/@hreffilter:The fix
filter_match_separator()picks a real"\n"instead of"<br>"when the result will not be passed through Inscriptis:xpath_filter(),xpath1_filter()andinclude_filters()all carried the sameif append_pretty_line_formatting and len(html_block) and ...condition, so all three now call the helper. That also fixes the CSS andxpath1:variants of the same bug, which had the identical symptom.Two details preserved:
<br>marker, same skip forbr/hr/div/p(which already break a line).Result for the reported case:
Tests
New
changedetectionio/tests/unit/test_filter_match_separator.pycovers the multi-match case for XPath,xpath1:and CSS, the single-match and no-match cases (no stray leading newline), and the helper itself for both paths.