1160
Bird (lemmy.world)

you are viewing a single comment's thread
view the rest of the comments
[-] cypherpunks@lemmy.ml 17 points 5 days ago

URL perfectly clickable from PieFed

PieFed W

that is not a W... i surrounded the URL with backticks, which means it should be treated as code and not made into a link.

cc: PyFedi developer @rimu@piefed.social

I had a glance at the source and don't see a very quick fix, but I think the solution involves getting rid of the auto-linkification here and instead have that be done by the markdown library. This issue indicates that the markdown library PyFedi is using is capable of doing that.

Here is a test I wrote which I think should pass which does not currently :)

diff --git a/tests/test_markdown_to_html.py b/tests/test_markdown_to_html.py
index 329b19be..108276c5 100644
***
a/tests/test_markdown_to_html.py
+++ b/tests/test_markdown_to_html.py
@@ -37,6 +37,12 @@ class TestMarkdownToHtml(unittest.TestCase):
         result = markdown_to_html(markdown)
         self.assertTrue("<pre><code>code block" in result)
 
+    def test_code_block_link(self):
+        """Test code blocks formatting containing a link"""
+        markdown = "```\ncode block with link: https://example.com/ \n```"
+        result = markdown_to_html(markdown)
+        self.assertEqual("<pre><code>code block with link: https://example.com/ ", result)

it currently produces this failure:

====================================================== FAILURES =======================================================
_______________________________________ TestMarkdownToHtml.test_code_block_link _______________________________________

self = <tests.test_markdown_to_html.TestMarkdownToHtml testMethod=test_code_block_link>

    def test_code_block_link(self):
        """Test code blocks formatting containing a link"""
        markdown = "```\ncode block with link: https://example.com/ \n```"
        result = markdown_to_html(markdown)
>       self.assertEqual("<pre><code>code block with link: https://example.com/ ", result)
E       AssertionError: '<pre[24 chars]ink: https://example.com/ ' != '<pre[24 chars]ink: <a href="https://example.com/" rel="nofoll[61 chars]e>\n'
E       - <pre><code>code block with link: https://example.com/ 
E       + <pre><code>code block with link: <a href="https://example.com/" rel="nofollow ugc" target="_blank">https://example.com/</a> 
E       + </code></pre>
E       +

tests/test_markdown_to_html.py:44: AssertionError

HTH, and thanks for writing free software!

[-] rimu@piefed.social 6 points 4 days ago

That does help very much, thank you!

I've committed a fix.

[-] cypherpunks@lemmy.ml 4 points 5 days ago

oops, i read my test closer and realized it will never pass as-is due to being cribbed from another test that was using in instead of assertEqual (and the expected string not containing the closing tags) but I trust it conveys what i mean to

this post was submitted on 31 Jul 2025
1160 points (99.2% liked)

Science Memes

16097 readers
2740 users here now

Welcome to c/science_memes @ Mander.xyz!

A place for majestic STEMLORD peacocking, as well as memes about the realities of working in a lab.



Rules

  1. Don't throw mud. Behave like an intellectual and remember the human.
  2. Keep it rooted (on topic).
  3. No spam.
  4. Infographics welcome, get schooled.

This is a science community. We use the Dawkins definition of meme.



Research Committee

Other Mander Communities

Science and Research

Biology and Life Sciences

Physical Sciences

Humanities and Social Sciences

Practical and Applied Sciences

Memes

Miscellaneous

founded 2 years ago
MODERATORS