مشكلة في عرض Markdown مع صورة محاطة بـ HTML

Related to Thumbnail generation & markdown rendering issue

When discourse downloads and replaces an image HTML with its markdown syntax – in our context, this results as:

[...]<a href="<link_here>" target="_blank">![|150x150](upload://l0iarnA6SPVAyJN5l7pnQxZnPvE.jpeg)</a>[...]

Discourse is unable to render the image

Image

image

To fix the issue, you need at least an empty line above:

[...]<a href="<link_here>" target="_blank">

![|150x150](upload://l0iarnA6SPVAyJN5l7pnQxZnPvE.jpeg)</a>[...]
Image

image

Would it be possible to allow rendering markdown image surrounded by HTML, please?

@david

5 إعجابات

Let’s try this on meta. I am hotlinking this image inside a link:

<a href="https://discourse.org"><img src="..."/></a>

Let’s see what happens when the image is pulled…

3 إعجابات

@Arkshine that seemed to work ok - it’s rendering <a href="https://discourse.org">![](upload://6zqK52dO23i1JsYH2oyMU12U2ro.jpeg)</a> successfully.

Can you share a little more of the HTML structure surrounding the link?

إعجابَين (2)
Unformatted
<div data-wp><a href="https://www.mooki.co.il/gaming/hbilvt-giiming-mwtlmvt/mvwb-giiming-khvl-sparkfox-wvlhn-giiming-mqcvei-lumi-whvr-2" target="_blank">![](upload://vAPxoqZB2QvWCrX4kbbzSO5BYYb.png)</a><div><div data-buy><a href="https://www.mooki.co.il/gaming/hbilvt-giiming-mwtlmvt/mvwb-giiming-khvl-sparkfox-wvlhn-giiming-mqcvei-lumi-whvr-2" target="_blank">קנייה</a><span data-clipboard-text="GLA679" data-coupon>GLA679</span><i></i></div><div data-price>₪679 <span data-old-price>₪1378</span></div></div></div><hr /><p><small>&nbsp;פורסם ב:&nbsp;<a href="https://zuzu.deals/%d7%91%d7%9c%d7%a2%d7%93%d7%99-%d7%95%d7%91%d7%9e%d7%97%d7%99%d7%a8-%d7%97%d7%98%d7%99%d7%a4%d7%94-%d7%9e%d7%95%d7%a9%d7%91-%d7%92%d7%99%d7%99%d7%9e%d7%99%d7%a0%d7%92-%d7%90%d7%93%d7%95%d7%9d-spark/"></a></small></p><br><p>![](upload://npQfkOhEIdPiFymVdtVyKmwRShL.png)</p>
<p style="text-align: center;">בין אם אתם גיימרים ובין אם אתם פשוט עובדים ויושבים כל היום והגב כבר זועק לכיסא טוב יותר, הנה לכם עוד מבצע בלעדי במחיר חטיפה!<br />
כיסא גיימינג מפנק, אוזניות גיימינג ומשלוח מהיר בחינם, עם אחריות יבואן רשמי &#8211; רק ב679₪!!!</p>
<p style="text-align: center;">השתמשו בקופה בקופון הבלעדי &#8211; <strong>GLA679</strong></p>
<div> ![](upload://3c2tvGxZnMqoIn2fVfHA02wocm.jpeg)</div>
<div>
<h3 style="text-align: center;">מושב גיימינג מקצועי SPARKFOX GC60P</h3>
</div>
<div>מושב גיימינג בעל עיצוב מיוחד למשחקי מחשב לנוחות מקסימאלית למשתמש</div>
<div>
<ul>
<li>מושב בעל משענת גב גבוהה</li>
<li>נוחות המקסימאלית למשך זמן משחק ארוך</li>
<li>זוג כריות לתמיכה בצוואר ובגב התחתון</li>
<li>סוג חומר: ספוג יצוק</li>
<li>סוג מסגרת: מתכת</li>
<li>חומר: עור עם סיבי פחם</li>
<li>משענות ידיים: מתכווננות מעלה / מטה</li>
<li>סוג מנגנון: פרפר</li>
<li>סוג הרמה: הידראולית Class4</li>
<li>טווח משענת גב: 90°-180°</li>
<li>סוג בסיס: ניילון</li>
<li>חומר גלגל: ניילון</li>
<li>יכולת נשיאה: עד 150 ק”ג</li>
<li>אחריות: שנה</li>
</ul>
<div><strong>מידות</strong></div>
<div>
<ul>
<li>רוחב: 67 ס&quot;מ</li>
<li>עומק: 67 ס&quot;מ</li>
<li>גובה משתנה: 124-132 ס&quot;מ</li>
</ul>
<h3></h3>
<p>![](upload://7t26ZtW6tL3vobWYqbpCbRftvpV.jpeg)</p>
<h3 style="text-align: center;">אוזניות גיימינג SPARKFOX K1</h3>
<div>אוזניות גיימינג בעיצוב מיוחד לנוחות מקסימלית לשמע ודיבור וביטול רעשי רקע</div>
<div>
<ul>
<li>ניתנות לשימוש ברוב הקונסולות הקיימות בשוק</li>
<li>שמע וניהול שיחות בטלפונים ובמחשבים ניידים</li>
<li>ווסת עוצמת השמע הינו בכבל של האוזנייה- לגישה נוחה</li>
<li>שמע מעולה ממנהלי התקנים גדולים של 50 מ&quot;מ</li>
<li>בקרי עוצמת הקול וההשתקה</li>
<li>כוסות אוזניים מרופדות גדולות לנוחות מרבית</li>
<li>קשת האוזנייה מתכווננת להתאמה מושלמת לראשכם</li>
<li>מתחבר ישירות ליציאת בקרי 3.5 מ&quot;מ</li>
</ul>
</div>
<div>מצורף מתאם מיוחד לחיבור האוזניות למחשב נייח ע&quot;י מפצל 3.5 מ&quot;מ ל 2 יציאות 3.5 מ&quot;מ</div>
</div>
</div>
<p>&nbsp;</p>
<div data-custom-html=""></div>
Formatted
<div data-wp>
    <a href="https://www.mooki.co.il/gaming/hbilvt-giiming-mwtlmvt/mvwb-giiming-khvl-sparkfox-wvlhn-giiming-mqcvei-lumi-whvr-2" target="_blank">![](upload://vAPxoqZB2QvWCrX4kbbzSO5BYYb.png)</a>
    <div>
        <div data-buy>
            <a href="https://www.mooki.co.il/gaming/hbilvt-giiming-mwtlmvt/mvwb-giiming-khvl-sparkfox-wvlhn-giiming-mqcvei-lumi-whvr-2" target="_blank">קנייה</a
            ><span data-clipboard-text="GLA679" data-coupon>GLA679</span><i></i>
        </div>
        <div data-price>₪679 <span data-old-price>₪1378</span></div>
    </div>
</div>
<hr />
<p>
    <small
        >&nbsp;פורסם ב:&nbsp;<a href="https://zuzu.deals/%d7%91%d7%9c%d7%a2%d7%93%d7%99-%d7%95%d7%91%d7%9e%d7%97%d7%99%d7%a8-%d7%97%d7%98%d7%99%d7%a4%d7%94-%d7%9e%d7%95%d7%a9%d7%91-%d7%92%d7%99%d7%99%d7%9e%d7%99%d7%a0%d7%92-%d7%90%d7%93%d7%95%d7%9d-spark/"></a
    ></small>
</p>
<br />
<p>![](upload://npQfkOhEIdPiFymVdtVyKmwRShL.png)</p>
<p style="text-align: center;">
    בין אם אתם גיימרים ובין אם אתם פשוט עובדים ויושבים כל היום והגב כבר זועק לכיסא טוב יותר, הנה לכם עוד מבצע בלעדי במחיר חטיפה!<br />
    כיסא גיימינג מפנק, אוזניות גיימינג ומשלוח מהיר בחינם, עם אחריות יבואן רשמי &#8211; רק ב679₪!!!
</p>
<p style="text-align: center;">השתמשו בקופה בקופון הבלעדי &#8211; <strong>GLA679</strong></p>
<div>![](upload://3c2tvGxZnMqoIn2fVfHA02wocm.jpeg)</div>
<div>
    <h3 style="text-align: center;">מושב גיימינג מקצועי SPARKFOX GC60P</h3>
</div>
<div>מושב גיימינג בעל עיצוב מיוחד למשחקי מחשב לנוחות מקסימאלית למשתמש</div>
<div>
    <ul>
        <li>מושב בעל משענת גב גבוהה</li>
        <li>נוחות המקסימאלית למשך זמן משחק ארוך</li>
        <li>זוג כריות לתמיכה בצוואר ובגב התחתון</li>
        <li>סוג חומר: ספוג יצוק</li>
        <li>סוג מסגרת: מתכת</li>
        <li>חומר: עור עם סיבי פחם</li>
        <li>משענות ידיים: מתכווננות מעלה / מטה</li>
        <li>סוג מנגנון: פרפר</li>
        <li>סוג הרמה: הידראולית Class4</li>
        <li>טווח משענת גב: 90°-180°</li>
        <li>סוג בסיס: ניילון</li>
        <li>חומר גלגל: ניילון</li>
        <li>יכולת נשיאה: עד 150 ק”ג</li>
        <li>אחריות: שנה</li>
    </ul>
    <div><strong>מידות</strong></div>
    <div>
        <ul>
            <li>רוחב: 67 ס&quot;מ</li>
            <li>עומק: 67 ס&quot;מ</li>
            <li>גובה משתנה: 124-132 ס&quot;מ</li>
        </ul>
        <h3></h3>
        <p>![](upload://7t26ZtW6tL3vobWYqbpCbRftvpV.jpeg)</p>
        <h3 style="text-align: center;">אוזניות גיימינג SPARKFOX K1</h3>
        <div>אוזניות גיימינג בעיצוב מיוחד לנוחות מקסימלית לשמע ודיבור וביטול רעשי רקע</div>
        <div>
            <ul>
                <li>ניתנות לשימוש ברוב הקונסולות הקיימות בשוק</li>
                <li>שמע וניהול שיחות בטלפונים ובמחשבים ניידים</li>
                <li>ווסת עוצמת השמע הינו בכבל של האוזנייה- לגישה נוחה</li>
                <li>שמע מעולה ממנהלי התקנים גדולים של 50 מ&quot;מ</li>
                <li>בקרי עוצמת הקול וההשתקה</li>
                <li>כוסות אוזניים מרופדות גדולות לנוחות מרבית</li>
                <li>קשת האוזנייה מתכווננת להתאמה מושלמת לראשכם</li>
                <li>מתחבר ישירות ליציאת בקרי 3.5 מ&quot;מ</li>
            </ul>
        </div>
        <div>מצורף מתאם מיוחד לחיבור האוזניות למחשב נייח ע&quot;י מפצל 3.5 מ&quot;מ ל 2 יציאות 3.5 מ&quot;מ</div>
    </div>
</div>
<p>&nbsp;</p>
<div data-custom-html=""></div>
Screenshot of composer

إعجاب واحد (1)

This is the same issue as is brought up here: Images not publishing to Discourse in WP 5.3

3 إعجابات

Aha! @simon will upgrading the wordpress plugin fix old posts? Or only new posts?

3 إعجابات

The fix only applies to posts that are published with the WordPress Block editor. It will fix old posts if the “Update Discourse Topic” button is clicked on WordPress. It will need to be done manually for each post unless someone writes a script to loop through old posts.

4 إعجابات

Let’s try this HTML:

<p><img src="..."/></p>

![](upload://6zqK52dO23i1JsYH2oyMU12U2ro.jpeg)

4 إعجابات

I think this should be fixed in Discourse as well, just in case posts are made by a non-wordpress integration. To summarise:

  1. I posted <p><img src="..."/></p>. This is perfectly valid HTML

  2. pull_hotlinked_images fetched the image, and replaced the markup with <p>![](upload://6zqK52dO23i1JsYH2oyMU12U2ro.jpeg)</p>

  3. This does not render

So there are two possible fixes here. Either:

  • We fix InlineUploads so that it adds a blank line in the markup. This renders fine:
    <p>
    
    ![](upload://6zqK52dO23i1JsYH2oyMU12U2ro.jpeg)
    </p>
    

OR

@sam do you know if there’s a deliberate reason that markdown images won’t render on the same line as a <p>?

3 إعجابات

This is part of the CommonMark spec

**test**

<p>**test**</p>

Absolutely do not want to deviate from the spec here. I guess we fix pull hotlink images to allow for this by injecting 2 newlines for cases like this. I think it is rather rare though and sort of self inflicted.

5 إعجابات

I don’t think it’s that rare, especially when Discourse is associated to popular tools such as WP-Discourse or any tools which uses the API.

Please consider to add a blank line. It does not seems that would be a breaking change and fairly easy to implement. :pray:

3 إعجابات

@Arkshine we have been discussing this a lot internally. The key thing for us is to maintain the integrity of the content, so the newline solution will probably not happen.

But we will definitely be doing something - having the pull_hotlinked_images job destroy the images is not acceptable. Hope to have a solution soon :eyes:

5 إعجابات

A workaround for this issue is to prevent Discourse from downloading the remote images. This can be done by adding the image domain to the disabled image download domains site setting. It is also possible to prevent Discourse from downloading all remote images by disabling the download remote images to local site setting. See Fix broken images for posts created by the WP Discourse and RSS plugins for details.

4 إعجابات

In our case, we can’t because we’re using the official topic thumbnail component which requires a local image. We solved the issue by adding newlines before any <img> in the content before topic being created with WP-Discourse. Not a solution for everyone but it works for us. A bit sad Discourse doesn’t support this legal usage.

But yes, if you are not tightened to a plugin/component and/or can’t fix the content before topic is created, this is for sure a reasonable workaround.

إعجابَين (2)

We are still planning to fix the issue. Unfortunately it is a problem quite deep in our markdown rendering system which is complex to fix. But we will get to it - sorry it is taking so long!

5 إعجابات

أود فقط إضافة ملاحظة هنا بأن المشكلة تؤثر أيضًا على المنشورات التي تحتوي على صور تم إنشاؤها عبر إضافة Discourse RSS.

6 إعجابات

نعتذر عن تعدد المنشورات في هذا الموضوع، لكن المشكلة تؤثر أيضًا على الصور في المنشورات التي يتم إنشاؤها عبر إضافة Zendesk لدينا عند تفعيل إعداد “مزامنة التعليقات من Zendesk”. تكمن الصعوبة في هذه الحالة في أنه لا يمكن معرفة مصدر الصور مسبقًا، وبالتالي لن تعمل حيلة إضافة مصدر الصورة إلى إعداد “نطاقات تحميل الصور المعطلة”.

هل توجد طريقة لمنع تحميل الصور البعيدة إلى الجهاز المحلي إذا كانت وسم الصورة محاطة بوسوم HTML؟

إعجاب واحد (1)

أخشى أن هذا غير ممكن على الإطلاق؛ فإذا قمنا بمثل هذا الإجراء، فسنتيح لأطراف ثالثة تتبع الاستخدام في المنتدى عن طريق حقن صورة تتبع. إن ميزة تحميل الصور البعيدة هي جزء من نظام الأمان.

بدلاً من ذلك، أعتقد أننا بحاجة إلى نظام “أذكى” يعمل بطريقة مشابهة للطريقة التي بنى بها @tgxworld خرائط الصور الخاصة بنا قبل بضع سنوات، نظام يعمل بشكل عكسي من HTML ويضمن استقرار التغيير من خلال إعادة الطهي. تغيير معقد للأسف.

4 إعجابات

هذه المشكلة قد ظهرت مرة أخرى

فقط أفكر بصوت عالٍ هنا، لكنني أتساءل عما إذا كان بإمكاننا تجاوز هذه المشكلة الصعبة (أي تحويل HTML إلى Markdown). للتذكير (لمساعدة التفكير في هذا الأمر)

  1. يدعم Discourse استيراد HTML لإنشاء محتوى المنشورات (مثل HTML من WP Discourse).

  2. في بعض السياقات، يتوقع المستخدم الحفاظ على سلامة HTML الأصلي تمامًا.

  3. تشمل “السلامة” هنا جانبين على الأقل:

    1. كيفية عرض المحتوى، مثل فواصل الأسطر
    2. مكان استضافة الوسائط، مثل تنزيل الصور محليًا لتجنب الصور التالفة، أو ربما لأسباب تتعلق بالأمان
  4. قد يؤدي تحويل HTML إلى Markdown إلى مشاكل من النوع الأول من السلامة، ومع ذلك فهو ضروري حاليًا لضمان النوع الثاني من السلامة.

لذا، ربما تكون إحدى الطرق لمعالجة هذه المشكلة لبعض المنشورات المستوردة هي تخزين HTML المستورد مباشرة كمحتوى منشور مطبوخ، ودعم مهمة pull_hotlinked_images لتنزيل الصور في مثل هذا المحتوى دون تحويل img إلى Markdown.

نعم، وببساطة أكثر، ربما يدعم الكود تنزيل الصور المرتبطة مباشرة دون الحاجة إلى تحويل img إلى Markdown. بالنسبة لمثل هذه المنشورات، يمكنك استبدال عنوان الصورة المنزلة في المحتوى المطبوخ بدلاً من النص الخام.

3 إعجابات

المشكلة هي كيف ستقوم بتحرير المنشورات بهذه العلامة. سيكون المحرر في وضع HTML الخام، وستكون شريط الأدوات بأكمله معطّلًا، وما إلى ذلك.

إعجاب واحد (1)