Quoting a forum post doesn't include style tags

If I highlight some text in a forum post and click the “quote” button, any style tags that have been applied to that text like or will not be copied into the quote in the new post.

I think that hardly anyone /expects/ that to work, hardly anyone even uses that feature, and it’s not easy to add this feature.

I would actually expect that to work (it works in other forums).
A test shows that highlighting and quoting removes the style, but pressing “Reply” doesn’t.

Right. “Reply” quotes the whole post. The server just pulls the raw post content from the database.

Highlight and “Quote” copies a quote of an excerpt of the post to the “quick reply” section. It does this client-side, in JS. The client doesn’t even /have/ the raw BBcode that is interpreted into that HTML. Doing it server side doesn’t work either, because of the excerpting. There are ways to do it, but none of them are worth it for me to implement. If you disagree, feel free to implement it :slight_smile:

Hardly anyone uses the quote feature? I’m not sure that’s true, it seems to be used pretty regularly on the forums.

I tried meddling with it for an hour or two.

The current behavior uses a built-in JavaScript function that’s easy to use.
The behavior we want might be achieved on the client side, but it requires a more complicated set of instructions that split the text into its different components according to the style and then reconstructs the text by “gluing” all those parts together.
It’s not a trivial solution, and the result might break easily, so I agree with @dcollins that the effort required isn’t worth the (probably shaky) end result.

So… I took another shot at this, and here’s something that mostly works (mostly = assumes you’re not using an old version of IE or another unsupported browser).

In the copyQ function, I propose replacing txt = document.getSelection() with:

var contents = document.getSelection().getRangeAt(0).cloneContents()
contents["childNodes"].forEach(function(element){
    switch(element.localName){
        case "strong": txt += "[b]" + element.textContent + "[/b]"; break;
        case "em": txt += "[i]" + element.textContent + "[/i]"; break;
        case "u": txt += "[u]" + element.textContent + "[/u]"; break;
        case "strike": txt += "[s]" + element.textContent + "[/s]"; break;
        default: txt += element.textContent; break;
    }
})

@dcollins