Get the "raw" of the user selection (no Markdown)

AI-generated summary

NateDhaliwal is looking for a way to retrieve the raw, unparsed text that a user highlights when quoting, rather than the Markdown-converted text. They mention that quoteState.buffer provides the Markdown text, but they need the original text before conversion. NateDhaliwal suggests a workaround involving converting the raw post to Markdown and extracting the section from the original text, but notes the potential issues with character changes during conversion. Moin suggests looking at how fast edit and copy quote handle text selection. NateDhaliwal demonstrates that copying a quote converts bullet points to asterisks, even if the original used plus signs. sam explains that retrieving the original text is challenging due to the lossy process of converting HTML to Markdown and the lack of support for reverse mapping in markdown.it. NateDhaliwal acknowledges the difficulty of the task.

I understand that quoteState.buffer gets the Markdown text that the user highlights when quoting, and is one of the things passed into the quote-share-buttons-before plugin outlet (accessed by this.args.data.quoteState.buffer). How do I get the raw, unparsed text that the user is highlighting, before it got converted to Markdown? Is it possible to “de-Markdown” the post? Is this possible at all?

File:

Thanks.

Test:

  • this bullet point isn’t a star, it’s a plus

A workaround that I can think of is to convert the raw post to Markdown (how, I’m not sure), look at the start and end index of the selection in the converted text, than use that to extract the section from the original text. The issue would be that I’d need to assume no characters change, i.e. Markdown replaces characters 1:1. Surely there’s a better way :thinking:?

Have you taken a look at how fast edit and copy quote handle this? What happens to the text you select there?

In this case, copying the quote converts the bullet point to a * in the quote, when I actually used +. I’m looking for a way to get the plus instead of the asterisk.

Yeah this is VERY tough, probably difficulty level 20.

When you get stuff from the selection we are getting straight HTML

<ul>
<li>some text</li> 
</ul>

Nothing here about * vs +

To add complication if you just select a couple of items from a long list you get:

<li>some text</li>
<li>some other text</li>

This does not even give you ul vs ol

What we do for quoting is go

HTML → Markdown

This is a lossy process and also bug prone process. We have a bunch of workarounds to clean up HTML prior to conversion.

Changing to:

HTML → Original Markdown, would require a reverse map of HTML row/column → markdown. This is not supported at the moment in markdown.it.

Oof, that would be quite a difficult task then. Oh well, but thanks for your explanation!