MarkdownAttributedString icon indicating copy to clipboard operation
MarkdownAttributedString copied to clipboard

-[NSAttributedString markdownRepresentation] doesn't escape Markdown characters.

Open simonward opened this issue 5 years ago • 2 comments

See attached unit tests.

NSAttributedString+Markdown_Tests.m.txt

simonward avatar May 11 '20 16:05 simonward

This is a good test, but it's not exhaustive.

The code currently doesn't escape literals because the need to do so is contextual. You want to escape them when they occur in plain text, but you don't when they're not (e.g. a URL). I need solve that problem first - and it's subtly difficult one.

If someone enters the plain text my_variable_name = 1; is the intent to make "variable" italic? Will changing the text to my\_variable\_name = 1; be a welcome change? I'm still grappling with that...

chockenberry avatar Jun 07 '20 20:06 chockenberry

I've added ESCAPE_ALL_LITERALS to convert all literals in rich text (including punctuation!). You'll probably find this irritating. Not only is text harder to read, it breaks many of the tests.

For example, the text above becomes:

I've added ESCAPE\_ALL\_LITERALS to convert all literals in rich text \(including punctuation\!\)\. You'll probably find this irritating\. Not only is text harder to read, it breaks many of the tests\.

chockenberry avatar Jun 14 '20 21:06 chockenberry