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.
على أي حال، أنا أختلف: أعتقد أنه في الحالة العامة لـ [text](URL) (نسميها (2أ))، يجب إعادة كتابة عنوان URL للرابط بنفس الطريقة التي تتم بها (1). (أتفق على أن السلوك الحالي لإعادة كتابة النص وليس عنوان URL معطل تمامًا.) أتخذ القرار بين كتابة (1) و (2أ) بناءً على ما إذا كنت أعتقد أنه من المفيد أو المشتت للقارئ رؤية عنوان URL، وليس بناءً على أي نية حول ما إذا كان الرابط يجب أن يشير إلى إصدار التعليمات البرمجية وقت الكتابة أو وقت القراءة. بالطبع، أنا على دراية بمشكلة الرابط الدائم، لذا أقوم بإنشاء رابط دائم بنفسي كلما أردت ذلك. ولكن بشكل عام، إذا قرر مسؤول Discourse تمكين روبوت الرابط الدائم، فمن المفترض أن يكون ذلك لأنه يعتقد أن معظم مستخدميه ليسوا على دراية بخطر أن الروابط المستندة إلى أسماء الفروع يمكن أن تتلف، ولا أعتقد أن استخدام صيغة رابط Markdown هو إشارة كبيرة إلى أن مستخدمًا معينًا على دراية بالمشكلة ولكنه يريد إلغاء الاشتراك في إعادة كتابة هذا الرابط المحدد.
لكنني أعتقد أننا نتكهن هنا. كمستخدم متقدم، لا يهمني كثيرًا ما هو الإعداد الافتراضي طالما يمكنني تجاوزه حسب الحاجة.
نعم، بالضبط. حاليًا لا توجد طريقة لتجاوزه. كتابة [url](url) (نص الرابط وعنوان URL متطابقان تمامًا) ستكون بالتأكيد طريقة للإشارة إلى الروبوت بأنه لا ينبغي إعادة كتابة هذا الرابط، لأنه لا يوجد سبب آخر لكتابته بهذه الطريقة.
هناك سبب إذا كنت تريد أن تعطي الرابط عنوانًا خاصًا به بدلاً من استنتاجه من عنوان URL المستهدف، أي [title](url). إعطاء الرابط عنوانًا لن يشير إلى أي تفضيل لإعادة كتابة عنوان URL، لذلك أتفق مع @mattmccutchen على أن 1 و 2 يجب أن يتصرفا بشكل متسق لإعادة كتابة عنوان URL.
قد تكون هناك حجة مفادها أن العنوان الذي يطابق عنوان URL بالضبط هو مؤشر على أنه لا ينبغي إعادة كتابته، ولكن ماذا لو أراد المستخدم تقديم عنوان ويريد ألا تتم إعادة كتابة عنوان URL؟ يجب أن تكون هناك طريقة أخرى لتحديد ذلك.
شيء يتبادر إلى الذهن هو لاحقة عنوان مشابهة لتغيير حجم الصورة المضمنة، على الرغم من أنني لست متأكدًا من كيفية اكتشاف المستخدم لذلك.
يمكن تغيير حجم الصورة المضمنة بهذا الشكل: 
لذلك يمكن (يفترض) جعل المكون الإضافي discourse-github يبحث عن شيء كهذا: [title|github-no-rewrite](url)
آه، لم يكن واضحًا لي أن (2) الخاص بك يشير فقط إلى الحالة الخاصة حيث يكون النص وعنوان URL متماثلين. كان بياني للحالة العامة حيث قد لا يكون النص وعنوان URL متماثلين؛ دعنا نسمي ذلك (2أ) الآن.
في الحالة (2)، أتفق على أنه من الغريب إعادة كتابة عنوان URL وليس النص، مما يتركهما غير متناسقين، ولكن يبدو لي أنه يمكن للمرء أن يجادل بنفس القدر بأنه إذا أردنا تجنب عدم الاتساق، فإن أفضل طريقة للقيام بذلك هي إعادة كتابة كل من عنوان URL والنص بدلاً من عدم إعادة كتابة أي منهما. لذلك لا أجد الحجة لمعاملة (2) كخيار استبعاد مقنعة. نظرًا لأنه يجب أن يكون لدينا خيار استبعاد يعمل لـ (2أ)، فسأكون أميل إلى السماح للمستخدمين باستخدام نفس خيار الاستبعاد لـ (2) وعدم تعقيد التصميم. (أعتقد أن هذه قد تكون فكرة سيمون مانينغ أيضًا؟)
لست متأكدًا مما إذا كنت أتبع هذا بشكل صحيح (أو ما إذا كان ذلك ممكنًا)، ولكن هل يمكنك استخدام الهروب من المسافة كما في Inline PDF Previews - #45 by Johani لذا فإن [ text]( url) لن يعيد كتابة النص أو الرابط، وسيتم تغيير أي شيء آخر تلقائيًا؟
ليس اختبارًا صالحًا لأن إعادة كتابة روابط GitHub الدائمة معطلة تمامًا في هذه النسخة من Discourse. (أتساءل عما يقوله ذلك عن هذه الميزة إذا تم تعطيلها في النسخة “الرسمية” )