If nothing is pasted into an AJAX page or something else, this is probably due to poorly formed html. If there is something in the source outside the <head> , <body> or <html> source, Gokogiri wraps the highlighted markup in a separate <html> . Then, since there are two opening and closing <html> tags, html.ts will be executed twice. The solution is to catch the incoming page before we tell Gokogiri what to do with it, and fix the broken html, making sure everything is wrapped with a <body> .
In the /main.ts scripts in the project folder after
match($content_type) { with(/html/) {
add this which removes the </body> and </html> tags and adds them to the end:
# wrap markup that is outside the body so tritium doesn't get applied twice replace(/\<\/body\>/,"") replace(/\<\/html\>/,"") append("</body> </html>")
This should ensure that there is only one opening of the closing <html> tag that is passed to Gokogiri and that html.ts is run only once, as we want!
The reason the source probably looks good in Chrome is because when the Tritium code manipulates the page, it moves things from both <html> tags to the first, and when Chrome receives the page, it will erase the second, empty <html> .
source share