This is a link to a response I made on the Elinks users list (A desolate, tumbleweed inhabited place). It's something I'd noticed on certain websites in Elinks, but I never figured out why until this email gave me another concrete case to compare against the one I already knew about.

I realised that if text was occurring in <pre> elements then that would cause ELinks not to wrap it. So my hacky fix was to use Lua to change the <pre> elements to something else.

function additional_pre_format_html_hook (url, html)
    --Fix non-wrapping pages. For now, just this one
    if string.find(url, "://antirez.") then
        --Change <pre> to <div> this is very hacky and prone to failure
        html = string.gsub (html, '<pre(.-)</pre>', '<div%1</div>')
        --But since we only want to do this for pre not followed by code, change any divs followed by code back to pre
        html = string.gsub (html, '<div(.-<code.-</code>.-)</div>', '<pre%1</pre>')
        return html
    end
end

Since I have an existing pre_format_html_hook I use for Pinboard I initially had to include the above code within that. However, I then found out you can redefine lua functions (hence why the above is called additional_pre_format_html_hook). When I originally wrote this post (and I swear I had this working) I used the following code:

do
    local existing_pre_format_html_hook = pre_format_html_hook
    pre_format_html_hook = function(url, html) existing_pre_format_html_hook(url, html) additional_pre_format_html_hook(url, html) end
end

But then this redefining technique stopped working (or I was mad and it never worked in the first place?) and so I've had to amend it like follows (which adds in a bit of duplication since I already have these or similar if statements in each pre_format_html_hook):

do
    local existing_pre_format_html_hook = pre_format_html_hook
    pre_format_html_hook = function (url, html)
        if string.find(url, "://m.pinboard") then
            return existing_pre_format_html_hook (url, html)
        elseif string.find(url, "://antirez.") then
            return additional_pre_format_html_hook (url, html)
        end
    end
end

The only downside of all this is that it didn't fully fix the original posters problem, but at least it did mine.


[EDIT: 2015-08-15] Fix this terrible post. I had the wrong link in for "found out you can redefine lua functions". Also, the Lua code for the additional_pre_format_html_hook was wrong. Not sure how I managed to make such a mess of this post. Also, for reasons I cannot figure out, the redfefining of lua functions is not working for me right now even though I definitely had this working at one point. I can't figure out what I've broken. When I do figure it out I'll update here again.

[EDIT: 2015-08-16] Add redefining code that actually works. For sure, this time.