This treats a line starting with #123 - where 123 is a valid
issue or pull request ID - as an implicit link, rather than as
a header line.
Doing this is a bit complicated, as markdown does header line
processing early, in the block processors (that's before the
inline patterns we usually use). So we can't do this entirely
with inline patterns. We have to add a preprocessor that runs
before the block processors, and mungs the relevant strings so
the block processor doesn't turn them into header HTML. Then
we adjust the ImplicitIssuePattern to handle these modified
strings as well.
This also adds tests for implicit links, enabled by mocking out
enough bits of flask that _get_ns_repo_user is happy.
We also clean up IMPLICIT_ISSUE_RE, and the similar
IMPLICIT_PR_RE, a bit. The [^|\w] bit of these regexes was
both bizarre and unnecessary. That is an inverted set which
will match anything but a literal pipe or any character in the
\w class. The following bit, (?<!\w), is a negative lookbehind
assertion which means 'match unless the previous character is in
the \w class'. So these two actually apply to the same character
and are almost entirely redundant.
I think the weird set was meant to be something like (^|w),
and the approximate idea here was to match 'start of string
or any non-word character followed by a #'. If so, then in fact
just removing the wacky inverted set is all we need to do, as
negative lookbehind assertions are allowed to match at the start
of the string. (There is actually a whole hidden complication
here where markdown, behind the scenes, adds some more bits to
the pattern we feed it to form a complete regex, but it happens
that everything works OK with that). The tests should suffice to
demonstrate that these regexes still behave as we expect. These
regexes originally came from @ralph, who says he's OK with this
change.
This treats a line starting with #123 - where 123 is a valid
issue or pull request ID - as an implicit link, rather than as
a header line.
Doing this is a bit complicated, as markdown does header line
processing early, in the block processors (that's before the
inline patterns we usually use). So we can't do this entirely
with inline patterns. We have to add a preprocessor that runs
before the block processors, and mungs the relevant strings so
the block processor doesn't turn them into header HTML. Then
we adjust the ImplicitIssuePattern to handle these modified
strings as well.
This also adds tests for implicit links, enabled by mocking out
enough bits of flask that
_get_ns_repo_useris happy.We also clean up IMPLICIT_ISSUE_RE, and the similar
IMPLICIT_PR_RE, a bit. The
[^|\w]bit of these regexes wasboth bizarre and unnecessary. That is an inverted set which
will match anything but a literal pipe or any character in the
\w class. The following bit,
(?<!\w), is a negative lookbehindassertion which means 'match unless the previous character is in
the \w class'. So these two actually apply to the same character
and are almost entirely redundant.
I think the weird set was meant to be something like (^|w),
and the approximate idea here was to match 'start of string
or any non-word character followed by a #'. If so, then in fact
just removing the wacky inverted set is all we need to do, as
negative lookbehind assertions are allowed to match at the start
of the string. (There is actually a whole hidden complication
here where markdown, behind the scenes, adds some more bits to
the pattern we feed it to form a complete regex, but it happens
that everything works OK with that). The tests should suffice to
demonstrate that these regexes still behave as we expect. These
regexes originally came from @ralph, who says he's OK with this
change.
Signed-off-by: Adam Williamson awilliam@redhat.com