[openstreetmap/openstreetmap-website] Add dir="auto" to Markdown content for bidi (PR #5840)
Nitai Sasson
notifications at github.com
Thu Mar 27 23:20:25 UTC 2025
NeatNit left a comment (openstreetmap/openstreetmap-website#5840)
> This is a version that modifies the document, consisting of replaced `document` method, assuming we don't need to add `dir` on inline elements:
>
> ```ruby
> def document
> return @document if @document
>
> @document = Kramdown::Document.new(self)
>
> add_dir = lambda do |element|
> target_types = %w[p header pre codeblock ul ol table dl math]
> element.attr["dir"] ||= "auto" if target_types.include?(element.type == :html_element ? element.value : element.type.to_s)
> element.children.each(&add_dir)
> end
> add_dir.call(@document.root)
>
> @document
> end
> ```
Thank you, I want to use this method instead of mine. Just a couple of questions:
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)
And, is `element.type == :html_element` supposed to catch elements written as HTML within the Markdown source? In which case I think we should not add `dir="auto"` - if the user crafts their own HTML for whatever reason, we shouldn't change their work.
----
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:
- [ ] Modify document upon creation instead of deriving a converter (i.e. what I replied to just now)
- [ ] Make `linkify` add `dir="ltr"` to links - this would also affect changeset comments and the like
- [ ] Made triple sure that links made with `<URL>` markdown syntax actually get `dir="auto"` - 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 `%D7%90` or whatever.
I'll make these changes as soon as I can, next week. If any more feedbacks comes up I'll handle it too.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5840#issuecomment-2759773367
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/5840/c2759773367 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250327/8f4c4ddb/attachment.htm>
More information about the rails-dev
mailing list