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

markdown--filter-visible makes hyperlinks unclickable #693

Closed
astoff opened this issue Mar 7, 2022 · 4 comments
Closed

markdown--filter-visible makes hyperlinks unclickable #693

astoff opened this issue Mar 7, 2022 · 4 comments

Comments

@astoff
Copy link

astoff commented Mar 7, 2022

Expected Behavior

When filter-buffer-substring is used to copy some nicely formatted markdown buffer for display somewhere else, hyperlinks should remain clickable (at least with the mouse, perhaps with some special key as well).

Actual Behavior

Hyperlinks are formatted as such, but clicking them does not visit the URL.

Steps to Reproduce

Evaluate this in a fundamental-mode buffer, try to click the link:

(insert ?\n
  (with-temp-buffer
    (insert "[link](htt" "ps://www.example.com)")
    (gfm-view-mode)
    (font-lock-ensure)
    (string-trim (filter-buffer-substring (point-min) (point-max)))))

(Curiously, if the hyperlink text appears verbatim in the buffer, say if you "deobfuscate" the argument to insert, then the link can be clicked).

Software Versions

  • Markdown Mode: 2.5
  • Emacs: 28.0.91
  • OS: Fedora
@astoff
Copy link
Author

astoff commented Mar 7, 2022

@joaotavora This affects Eglot. Moreover, if I change the following line with simply (string-trim (buffer-string)), then the hyperlinks work (you can click them with the mouse). I haven't noticed adverse effects yet, although presumably they exist.

https://github.com/joaotavora/eglot/blob/d03235f39a39bdf2e74571d695163aa42f5b9506/eglot.el#L1439

@joaotavora
Copy link

Right now, I don't know exactly why Eglot is using filter-buffer-substring. Can you clarify if this is some kind of regression or did it "never work"?

In the latter case, it's a question of understanding the root cause and then deciding where to fix it. If Eglot's use of f-b-substring is unreasonable, it should somehow be fixed there. Else it should be fixed here, where that fix would presumably benefit other users.

@astoff
Copy link
Author

astoff commented Mar 7, 2022

AFAIR it never worked. Eglot is probably following the best practice here, so changing it is a bit of a workaround. As I mentioned, an improved filter-buffer-substring-function could have additional benefits, like adding an actual keybinding (apart from clicking) to follow links.

@syohex
Copy link
Collaborator

syohex commented Mar 8, 2022

I suppose that markdown-mode's filter-buffer-substring-function implementation is correct. org-mode implements it same as markdown's. It strips text properties.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Buffer-Contents.html

Lisp code should use this function instead of buffer-substring, buffer-substring-no-properties, or delete-and-extract-region when copying into user-accessible data structures such as the kill-ring, X clipboard, and registers. Major and minor modes can modify filter-buffer-substring-function to alter such text as it is copied out of the buffer

I think you should not use filter-buffer-substring for your purpose.

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

No branches or pull requests

3 participants