Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@usernames aren't linked at the beginnings of lines, except for the first line #267

Closed
phil-s opened this issue Mar 11, 2024 · 1 comment · Fixed by #268
Closed

@usernames aren't linked at the beginnings of lines, except for the first line #267

phil-s opened this issue Mar 11, 2024 · 1 comment · Fixed by #268

Comments

@phil-s
Copy link

phil-s commented Mar 11, 2024

For the following example message, the first username on the second line does not end up linked:

@phil.catalyst:matrix.org linked? @phil.catalyst:matrix.org linked?
@phil.catalyst:matrix.org linked? @phil.catalyst:matrix.org linked?

So the respective output end up like this:

phil.catalyst​:
11:40 phil.catalyst linked? phil.catalyst linked? @phil.catalyst:matrix.org linked? phil.catalyst linked?

It looks like the issue is the regexp in ement--format-body-mentions. For a @ immediately following a newline, that initial (or bos bow (1+ blank)) doesn't match because @ isn't word syntax, and newlines aren't [:blank:]. Let's simply add a newline to that set of alternatives?

(rx (or bos bow (1+ blank))
    (or (seq (group
              ;; Group 1: full @-prefixed MXID.
              "@" (group
                   ;; Group 2: displayname.  (NOTE: Does not work
                   ;; with displaynames containing spaces.)
                   (1+ (seq (optional ".") alnum)))
              (optional ":" (1+ (seq (optional ".") alnum))))
             (or ":" eow eos (syntax punctuation)))
        (seq (group
              ;; Group 3: MXID username or displayname.
              (1+ (not blank)))
             ":" (1+ blank))))
@phil-s
Copy link
Author

phil-s commented Mar 11, 2024

This?

-                 (regexp (rx (or bos bow (1+ blank))
+                 (regexp (rx (or bos bow (1+ (or blank "\n"))

Looks like it does the trick.

Does that 1+ help? Maybe preventing some potential backtracking? It doesn't look necessary for matching purposes, but I'm interested to know if it's better that way.

If there's no benefit to that, then I think we could alternatively simplify slightly to:

-                 (regexp (rx (or bos bow (1+ blank))
+                 (regexp (rx (or bos bow blank "\n")

@phil-s phil-s changed the title Usernames aren't linked at the beginnings of lines, except for the first line @usernames aren't linked at the beginnings of lines, except for the first line Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant