fix: false positives for inline elements in no-reversed-media-syntax
#597
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.
Prerequisites checklist
What is the purpose of this pull request?
Which language are you using?
CommonMark and GFM.
What did you do?
I expected the following examples to be ignored and not to generate errors, but they generate errors (false positives).
Within each section of the code snippet there are HTML comments, HTML, images, and inline code, so these parts shouldn't be interpreted as error-prone link syntax (
[description](URL)).What did you expect to happen?
I expected the above examples to be ignored and not to generate errors, but they generate errors (false positives).
Link to minimal reproducible Example
The following Markdown code may help identify the problem:
What changes did you make? (Give an overview)
In this PR, I've fixed false positives for inline elements in
no-reversed-media-syntax.The previous logic only checked the
startOffsetof the ignored position, as shown below:markdown/src/rules/no-reversed-media-syntax.js
Lines 84 to 86 in 07dac6e
So, the following code was ignored as expected:
However, for the following snippets it doesn't work as expected and produces false positives:
A concrete way to resolve this problem is to test the regex against whitespace-masked text, rather than checking only the
startOffset.For example, the previous logic checked the following code, which caused false positives:
However, after this change, the text is tested against whitespace-masked text, so it no longer causes false positives.
( ] ^----^ Now, The text is whitespace-masked.The whitespace-masking idea was inspired by the existing
no-space-in-emphasisrule, and I've modified its logic slightly.markdown/src/rules/no-space-in-emphasis.js
Lines 111 to 138 in 07dac6e
Related Issues
N/A
Is there anything you'd like reviewers to focus on?
The
findReversedMediaSyntaxhelper function was only used in one place, so I've moved it directly under:matches(heading, paragraph, tableCell):exit.