[openstreetmap/openstreetmap-website] Auto-linkify markdown text (Issue #7122)

Pablo Brasero notifications at github.com
Tue Jun 2 09:59:58 UTC 2026


pablobm left a comment (openstreetmap/openstreetmap-website#7122)

Idea: perhaps we can use a stream HTML parser, avoiding the linkification when we are inside an inappropriate element. Something like this:

```
UNLINKABLE_ELEMENTS = ["pre", "code", "a"]

unlinkable_elements_stack = []

parser = StreamingParser.new(html) do |events|
  events.on_opening_element do |element|
    unlinkable_elements_stag.push(element.tag_name) if UNLINKABLE_ELEMENTS.include?(element.tag_name)
  end
  
  events.on_closing_element do |element|
    element.text = linkify(text) if inappropriate_elements_stack.empty?
    
    unlinkable_elements_stag.pop if UNLINKABLE_ELEMENTS.include?(element.tag_name)
  end
end

parser.run
```

I'm totally making up the API above. Nokogiri has something like it, but I don't remember the detail now. LibXML probably has it too.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/7122#issuecomment-4601262150
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/issues/7122/4601262150 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260602/fb1ab772/attachment.htm>


More information about the rails-dev mailing list