Improve formatting of quotes

I feel that Discourse's default quoting behavior is a bit inadequate for this forum; in particular, it tends to drop or garble quoted text (for background and previous discussion, see my response to @xwu's comment). For example, quoting text with links silently drops the link attribute, and code formatting disappears. More seriously, HTML entities appear in some cases. Here are some examples:


We should discuss this on the Swift Forums.



unsafeBitCast(_:to:) can be dangerous. Use it wisely.



I think I have the solution to a unified random number generation API:

func getRandomNumber() -> Int {
	return 4 // chosen by fair dice roll. guaranteed to be random.
}

I'm not sure if we can improve over this.



^ In that last one, there's an "->" in the actual thing. At least it renders nicely!

1 Like

I agree this is a problem. It seems the site is trying to do quoting purely based on the rendered html of the comment, rather than its original markdown.

However, because a user can *edit* their own posts, we know the server at least stores the original markdown. So it is certainly *possible* to implement a quoting behavior wherein the server returns either the original markdown alone, or the html augmented with the markdown which generated each element.

My understanding is that the “difficult part” of quoting is to figure out exactly where the selected text begins and ends in the markdown, since the selection happens in rendered html. However if the html were augmented with the markdown on a per-tag basis, this would be much more easily solved.

I'd be happy to lose this convenience, in favour of quoting the entire post as markdown and editing as necessary.

2 Likes

Even aside from that, it should be fairly straightforward to traverse the html within the selection to bring in the matched tags, and if there are any unmatched tags then locate the matching ones outside the selection and bring them in as well. I’m not sure why this isn’t already being done.

The problem is that you're allowed to quote only a certain part of a post by selecting it and embedding it which makes it difficult to reuse the saved Markdown source of the original post.

The solution could be this: when you select something and make a quote out of it, Discourse should take the HTML for what was selected, convert it to Markdown format, and then put that in the quote. The generated Markdown from the HTML can't be exactly the same as the original one that created the HTML, but it's irrelevant in this case because it will produce the same HTML result.

Reverse markdown filters are already a thing. So the hard part would be to traverse the HTML DOM, and from that generate HTML which will allow you to generate some plausible Markdown for those elements, which could then feed the editor in Discourse.

@sam.saffron, FYI

Not only are they are thing, they are a thing here when you enable the enable rich text paste, this has been long discussed on meta:

https://meta.discourse.org/t/quoted-replies-dont-keep-original-formatting/655

We are discussing on meta in the above topic what we think we can do to improve things.

2 Likes

Sometimes, I get the raw-code version of a message, then copy & paste whatever parts of its Markdown-ed code I need.

You do it by replacing the “/t/title-of-post” part of the URL with “/raw”. For example: https://forums.swift.org/t/improve-formatting-of-quotes/10868 with https://forums.swift.org/raw/10868.

4 Likes