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/[email protected]>
_______________________________________________
rails-dev mailing list
[email protected]
https://lists.openstreetmap.org/listinfo/rails-dev

Reply via email to