<span style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">
  <blockquote>
<p dir="auto">This is a version that modifies the document, consisting of replaced <code class="notranslate">document</code> method, assuming we don't need to add <code class="notranslate">dir</code> on inline elements:</p>
<div class="highlight highlight-source-ruby" dir="auto"><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">document</span>
      <span class="pl-k">return</span> <span class="pl-c1">@document</span> <span class="pl-k">if</span> <span class="pl-c1">@document</span>

      <span class="pl-c1">@document</span> <span class="pl-c1">=</span> <span class="pl-v">Kramdown</span>::<span class="pl-v">Document</span><span class="pl-kos">.</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">)</span>

      <span class="pl-s1">add_dir</span> <span class="pl-c1">=</span> <span class="pl-en">lambda</span> <span class="pl-k">do</span> |<span class="pl-s1">element</span>|
        <span class="pl-s1">target_types</span> <span class="pl-c1">=</span> <span class="pl-kos">%w[</span><span class="pl-s">p</span> <span class="pl-s">header</span> <span class="pl-s">pre</span> <span class="pl-s">codeblock</span> <span class="pl-s">ul</span> <span class="pl-s">ol</span> <span class="pl-s">table</span> <span class="pl-s">dl</span> <span class="pl-s">math</span><span class="pl-kos">]</span>
        <span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">attr</span><span class="pl-kos">[</span><span class="pl-s">"dir"</span><span class="pl-kos">]</span> ||= <span class="pl-s">"auto"</span> <span class="pl-k">if</span> <span class="pl-s1">target_types</span><span class="pl-kos">.</span><span class="pl-en">include?</span><span class="pl-kos">(</span><span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">type</span> == <span class="pl-pds">:html_element</span> ? <span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">value</span> : <span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">type</span><span class="pl-kos">.</span><span class="pl-en">to_s</span><span class="pl-kos">)</span>
        <span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">children</span><span class="pl-kos">.</span><span class="pl-en">each</span><span class="pl-kos">(</span>&<span class="pl-s1">add_dir</span><span class="pl-kos">)</span>
      <span class="pl-k">end</span>
      <span class="pl-s1">add_dir</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-c1">@document</span><span class="pl-kos">.</span><span class="pl-en">root</span><span class="pl-kos">)</span>

      <span class="pl-c1">@document</span>
    <span class="pl-k">end</span></pre></div>
</blockquote>
<p dir="auto">Thank you, I want to use this method instead of mine. Just a couple of questions:</p>
<p dir="auto">Is it good practice to use a lambda like that? Wouldn't it be better to define a function normally and call that? (I'm a Ruby newbie, but this seems a bit strange to me)</p>
<p dir="auto">And, is <code class="notranslate">element.type == :html_element</code> supposed to catch elements written as HTML within the Markdown source? In which case I think we should not add <code class="notranslate">dir="auto"</code> - if the user crafts their own HTML for whatever reason, we shouldn't change their work.</p>
<hr>
<p dir="auto">I will not be able to make modifications to the code for the next few days (until Tuesday or Wednesday, most likely), but I'd like to do this:</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Modify document upon creation instead of deriving a converter (i.e. what I replied to just now)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Make <code class="notranslate">linkify</code> add <code class="notranslate">dir="ltr"</code> to links - this would also affect changeset comments and the like</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Made triple sure that links made with <code class="notranslate"><URL></code> markdown syntax actually get <code class="notranslate">dir="auto"</code> - I did not test this enough and it likely fails in some cases. Namely when the URL contains Unicode characters and they get replaced by <code class="notranslate">%D7%90</code> or whatever.</li>
</ul>
<p dir="auto">I'll make these changes as soon as I can, next week. If any more feedbacks comes up I'll handle it too.</p><p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5840#issuecomment-2759773367">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLKKMSQ4BIXZICENKFT2WR2STAVCNFSM6AAAAABZTMJBMKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONJZG43TGMZWG4">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLM2TC2A7QSJ5YJLVH32WR2STA5CNFSM6AAAAABZTMJBMKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTVEP3GLO.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/5840/c2759773367</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
</span>


<div style="display: flex; flex-wrap: wrap; white-space: pre-wrap; align-items: center; "><img alt="NeatNit" height="20" width="20" style="border-radius:50%; margin-right: 4px;" decoding="async" src="https://avatars.githubusercontent.com/u/2400026?s=20&v=4" /><strong>NeatNit</strong> left a comment <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5840#issuecomment-2759773367">(openstreetmap/openstreetmap-website#5840)</a></div>
<blockquote>
<p dir="auto">This is a version that modifies the document, consisting of replaced <code class="notranslate">document</code> method, assuming we don't need to add <code class="notranslate">dir</code> on inline elements:</p>
<div class="highlight highlight-source-ruby" dir="auto"><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">document</span>
      <span class="pl-k">return</span> <span class="pl-c1">@document</span> <span class="pl-k">if</span> <span class="pl-c1">@document</span>

      <span class="pl-c1">@document</span> <span class="pl-c1">=</span> <span class="pl-v">Kramdown</span>::<span class="pl-v">Document</span><span class="pl-kos">.</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">)</span>

      <span class="pl-s1">add_dir</span> <span class="pl-c1">=</span> <span class="pl-en">lambda</span> <span class="pl-k">do</span> |<span class="pl-s1">element</span>|
        <span class="pl-s1">target_types</span> <span class="pl-c1">=</span> <span class="pl-kos">%w[</span><span class="pl-s">p</span> <span class="pl-s">header</span> <span class="pl-s">pre</span> <span class="pl-s">codeblock</span> <span class="pl-s">ul</span> <span class="pl-s">ol</span> <span class="pl-s">table</span> <span class="pl-s">dl</span> <span class="pl-s">math</span><span class="pl-kos">]</span>
        <span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">attr</span><span class="pl-kos">[</span><span class="pl-s">"dir"</span><span class="pl-kos">]</span> ||= <span class="pl-s">"auto"</span> <span class="pl-k">if</span> <span class="pl-s1">target_types</span><span class="pl-kos">.</span><span class="pl-en">include?</span><span class="pl-kos">(</span><span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">type</span> == <span class="pl-pds">:html_element</span> ? <span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">value</span> : <span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">type</span><span class="pl-kos">.</span><span class="pl-en">to_s</span><span class="pl-kos">)</span>
        <span class="pl-s1">element</span><span class="pl-kos">.</span><span class="pl-en">children</span><span class="pl-kos">.</span><span class="pl-en">each</span><span class="pl-kos">(</span>&<span class="pl-s1">add_dir</span><span class="pl-kos">)</span>
      <span class="pl-k">end</span>
      <span class="pl-s1">add_dir</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-c1">@document</span><span class="pl-kos">.</span><span class="pl-en">root</span><span class="pl-kos">)</span>

      <span class="pl-c1">@document</span>
    <span class="pl-k">end</span></pre></div>
</blockquote>
<p dir="auto">Thank you, I want to use this method instead of mine. Just a couple of questions:</p>
<p dir="auto">Is it good practice to use a lambda like that? Wouldn't it be better to define a function normally and call that? (I'm a Ruby newbie, but this seems a bit strange to me)</p>
<p dir="auto">And, is <code class="notranslate">element.type == :html_element</code> supposed to catch elements written as HTML within the Markdown source? In which case I think we should not add <code class="notranslate">dir="auto"</code> - if the user crafts their own HTML for whatever reason, we shouldn't change their work.</p>
<hr>
<p dir="auto">I will not be able to make modifications to the code for the next few days (until Tuesday or Wednesday, most likely), but I'd like to do this:</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Modify document upon creation instead of deriving a converter (i.e. what I replied to just now)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Make <code class="notranslate">linkify</code> add <code class="notranslate">dir="ltr"</code> to links - this would also affect changeset comments and the like</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Made triple sure that links made with <code class="notranslate"><URL></code> markdown syntax actually get <code class="notranslate">dir="auto"</code> - I did not test this enough and it likely fails in some cases. Namely when the URL contains Unicode characters and they get replaced by <code class="notranslate">%D7%90</code> or whatever.</li>
</ul>
<p dir="auto">I'll make these changes as soon as I can, next week. If any more feedbacks comes up I'll handle it too.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5840#issuecomment-2759773367">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLKKMSQ4BIXZICENKFT2WR2STAVCNFSM6AAAAABZTMJBMKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONJZG43TGMZWG4">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLM2TC2A7QSJ5YJLVH32WR2STA5CNFSM6AAAAABZTMJBMKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTVEP3GLO.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/5840/c2759773367</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>

<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/5840#issuecomment-2759773367",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/5840#issuecomment-2759773367",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>