swift-markdownkit icon indicating copy to clipboard operation
swift-markdownkit copied to clipboard

Parsing/generating errors

Open AlvaroBro opened this issue 1 year ago • 5 comments

Hi @objecthub !

First, thanks for this awesome library, I've started using it as I want to have enriched messages in my instant messaging app.

I've been trying several options, but none has been optimal. For example I need tables support, and yours is the only one I've found that provides this.

But testing it, I've found several cases where the result is not correct. I'm am currently debugging and I'm able to provide, for example:

  • input text
  • generated html
  • generated attributed text (and it's visualisation in a UITextView)

If you could help me solving these cases it would be great! I think I will test you library to extreme cases as I plan to create complicated messages.

So, should I go ahead and start providing examples???

Thank you!

AlvaroBro avatar Oct 14 '24 15:10 AlvaroBro

Thanks for your message, @AlvaroBro ! If you found issues with the table support in MarkdownKit, then I definitely want to fix them. If you have some examples where the results are not as expected, then it would be great if you could share them.

objecthub avatar Oct 14 '24 15:10 objecthub

Ok! In fact, for the moment all the problems I've had were not in tables but in other elements. I still have not started testing tables but for a very basic case. Ok then, I'll start posting cases here :)

AlvaroBro avatar Oct 14 '24 15:10 AlvaroBro

Please let me know if you need any more details!

Nested lists

Nested unordered list.

Problem: always adds an empty extra list item

Input text

- Manzana
	- Banana

I get the same result if I use 2 spaces instead of tab.

I use ExtendedMarkdownParser, which I extended as shown in you example to support underlined and strike-through text.

Debug info

Input text and parser's result:

Captura de pantalla 2024-10-14 a las 19 08 35

Generated HTML body:

Captura de pantalla 2024-10-14 a las 18 59 24

Generated attributed string:

Captura de pantalla 2024-10-14 a las 19 06 17

Which looks like this in a TextView:

Simulator Screenshot - iPhone 15 - 2024-10-14 at 19 06 29

AlvaroBro avatar Oct 14 '24 17:10 AlvaroBro

Hi, I’m facing the same issue. Is there any update or workaround available? Thanks!

iphone201988 avatar Mar 19 '25 08:03 iphone201988

The issue here is that Apple's HTML to NSAttributedString conversion has many bugs. In particular, nested lists are not supported well. I now implemented a small workaround via commit 941f6985a5815968e98f9bdeabadc771e1bcda55 that generates nested lists that don't look so broken. But the spacing is still off and I don't see how to fix that in general. I also added a new option to AttributedStringGenerator called tightLists which might produce better output for some use cases.

objecthub avatar Mar 27 '25 23:03 objecthub