About a year ago, I made a post on GitHub’s Discourse instance that included a bunch of URLs of the form “https://github.com/OWNER/REPO/tree/BRANCH/path” in order to discuss how GitHub.com processes such URLs. My post promptly received a system-generated edit with the message “Github link was replaced by a permanent link”, which appears to be coming from the discourse-github plugin. While replacing the branch name with a permanent link to the current commit ID may be a useful feature in the common case of a post citing particular code, in the special case of discussing GitHub URL processing, the edit destroyed the meaning of my post. I was lucky enough to notice the bot edit right away, and after several rounds of fighting with the bot, I eventually found a workaround of adding a <span> tag to prevent the bot’s pattern from matching, like this:
But other authors might not notice the bot edit and might be left with a post that would confuse readers.
What is the best solution to avoid undesired GitHub permanent link edits to a particular post? In general, I feel like it’s wrong for bots to make automatic edits that risk ruining a post. It would be safer to (1) ask the author when a post is saved whether the links should be edited or (2) have the bot add a permanent link without removing the original link. (I seem to recall seeing some bots on other web sites, maybe Reddit, that add information without deleting the existing information.) If the Discourse maintainers consider those options too ugly or too much work to accommodate a rare use case, some other options might be to (3) show a notice after the post is saved with a link to information about how the author can avoid the edits if needed, either as (a) a dedicated banner in the UI or (b) just a line of text added by the bot to the end of the post.
I’m not sure what would be the most reasonable design for the author to opt out of the edits. The discourse-github plugin’s site-wide exclusion settings based on the link target don’t seem well-suited for this purpose. Perhaps my current workaround with the <span> tag is adequate. Even if no change is made to Discourse, I hope this post will make the workaround easier to discover for authors who do notice the problem.
Note: I previously raised this issue on GitHub’s forum because I assumed the “permanent link” bot was specific to GitHub’s instance, but a commenter there clued me in that it is a general Discourse feature, so I’m raising the issue here.
I think this is a good feature, because people often paste links to master and these almost always grow outdated over time. Still, it should be possible to intentionally paste a link to a branch as there are many valid reasons to do this. Also generally this feature seems a bit broken, it rewrites things it shouldn’t and doesn’t parse things that it probably should.
Here are some examples that could be used as test cases to fix it:
URL enclosed in backquotes. This is not a link and should not be rewritten, but it is: https://github.com/ClassicPress/subdomain-static/blob/master/forums-enhancements.js
URL in a triple-backquoted code block. This is not a link and should not be rewritten, but it is:
I think only (1) above should be rewritten. This would make the behavior more predictable, and only rewrite “plain” links. Links where a specific markdown structure has been used (can be thought of as a way to express a specific intention) should be left alone.
FWIW, non sono d’accordo: penso che nel (2)modifica: il caso generale di [testo](URL) (chiamiamolo (2a)), l’URL del link dovrebbe essere riscritto allo stesso modo di (1). (Concordo sul fatto che il comportamento attuale di riscrivere il testo e non l’URL sia completamente errato.) Prendo la decisione tra scrivere (1) e (2a) in base al fatto che ritenga utile o distraente che l’URL sia visibile al lettore, non in base a un’intenzione sul fatto che il link debba puntare alla versione del codice al momento della scrittura o al momento della lettura. Naturalmente, sono consapevole del problema dei link permanenti, quindi ne creo uno io stesso ogni volta che ne voglio uno. Ma più in generale, se un amministratore di Discourse decide di abilitare il bot dei link permanenti, presumibilmente è perché pensa che la maggior parte dei suoi utenti non sia consapevole del rischio che i link basati sul nome del branch possano decadere, e non penso che l’uso della sintassi dei link Markdown sia un segnale che un dato utente sia consapevole del problema ma voglia escludere che quel particolare link venga riscritto.
Ma penso che stiamo solo speculando. Come utente avanzato, non mi interessa molto quale sia l’impostazione predefinita, purché io possa sovrascriverla secondo necessità.
Sì, esattamente. Attualmente non c’è modo di sovrascriverla. Scrivere [url](url) (il testo del link e l’URL sono esattamente gli stessi) sarebbe sicuramente un modo per segnalare al bot che quel link non dovrebbe essere riscritto, perché non c’è nessun altro motivo per scriverlo in quel modo.
Ce n’è se vuoi dare al link un titolo personalizzato anziché farlo dedurre dall’URL di destinazione, ovvero [titolo](url). Dare un titolo al link non indicherebbe alcuna preferenza per la riscrittura dell’URL, quindi concordo con @mattmccutchen sul fatto che 1 e 2 dovrebbero comportarsi in modo coerente per la riscrittura dell’URL.
Potrebbe esserci un argomento a favore del titolo che corrisponde esattamente all’URL come indicazione che non dovrebbe essere riscritto, ma cosa succede se un utente vuole fornire un titolo e vuole che l’URL non venga riscritto? Deve esserci un altro metodo per specificarlo.
Qualcosa che mi viene in mente sarebbe un suffisso del titolo simile al ridimensionamento delle immagini incorporate, anche se non sono sicuro di come un utente lo scoprirebbe.
Un’immagine incorporata può essere ridimensionata in questo modo: 
Quindi il plugin discourse-github potrebbe (presumibilmente) essere fatto per cercare qualcosa di simile: [titolo|github-no-rewrite](url)
Ah, non mi era chiaro che il tuo (2) si riferisse solo al caso speciale in cui il testo e l’URL sono gli stessi. La mia affermazione era per il caso generale in cui il testo e l’URL potrebbero non essere gli stessi; chiamiamolo (2a) ora.
Nel caso (2), sono d’accordo che è strano riscrivere l’URL e non il testo, lasciandoli incoerenti, ma mi sembra che si potrebbe ugualmente sostenere che se vogliamo evitare l’incoerenza, il modo migliore per farlo è riscrivere sia l’URL che il testo piuttosto che nessuno dei due. Quindi non trovo convincente l’argomento per trattare (2) come un’esclusione. Dato che dovremmo avere un’esclusione che funzioni per (2a), sarei propenso a lasciare semplicemente che gli utenti utilizzino la stessa esclusione per (2) e non complicare il design. (Penso che questa possa essere stata anche un’idea di Simon Manning?)
Non sono sicuro di star seguendo correttamente (o se sia possibile), ma potresti usare l’escape dello spazio come in Inline PDF Previews - #45 by Johani? Quindi [ testo]( url) non riscriverebbe né il testo né l’url, e qualsiasi altra cosa verrebbe modificata automaticamente?
Non è un test valido perché la riscrittura dei permalink di GitHub è completamente disabilitata su questa istanza di Discourse. (Mi chiedo cosa dica questa funzionalità se è disabilitata sull’istanza “ufficiale” )