gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.26k stars 267 forks source link

Spacing issues with lists #50

Closed antonjazz closed 2 years ago

antonjazz commented 3 years ago

I notice that when I have nested lists, I get extra spacing when end I end a sublist. Here's an example of markdown and the MarkDownUI rendering below it, using all standard settings:

MarkDownUI SubList

Also, I would love to be able to separate all list items slightly (vertically) from each other without increasing the spacing within a multi-line item… but can't figure out how to do that. Any ideas? Thanks!

gonzalezreal commented 3 years ago

This is definitely a bug. Thanks for reporting, I will look into it.

antonjazz commented 3 years ago

Thank you! 🙏 And, while you're thinking about it, if you have any ideas about that last comment too (adding a little touch of vertical space between list items) that'd be fantastic! Here's an example (all lines have more spacing except within the wrap-around line). It's subtle but I find that it helps readability a lot: LooserSpacing

gonzalezreal commented 3 years ago

Thank you! 🙏 And, while you're thinking about it, if you have any ideas about that last comment too (adding a little touch of vertical space between list items) that'd be fantastic! Here's an example (all lines have more spacing except within the wrap-around line). It's subtle but I find that it helps readability a lot: LooserSpacing

According to the CommonMark Lists Spec:

A list is loose if any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight.

MarkdownUI does its best to respect that. So if you write:

1. item one

2. item two
   - sublist
   - sublist

You will have loose spacing in the outer list.

Likewise, to have loose spacing in both the inner and outer lists, you could write:

1. item one

2. item two
   - sublist

   - sublist

Is that what you're looking for?

antonjazz commented 3 years ago

Thanks, Guille! That would work, with these two qualifiers:

  1. I'd want to set the extra spacing for loose to something very small such as 1.0 or 2.0.
  2. I would then make every list a loose list.

(2) is just a minor inconvenience, but I was concerned that achieving (1) would also reduce the spacing between all (non-list) paragraphs to the same small value. Is that correct? So I was hoping that there might be some way I could use MarkdownStyle to modify the line spacing in normal (tight) lists to make it slightly larger between list items without changing the line spacing within a single, multi-line list item. I couldn't find a way to do that.

gonzalezreal commented 3 years ago

Currently you can't achieve the kind of spacing customization you are asking. This will require rewriting some parts of the attributed string renderer.

It's true that the current styling feature is not very flexible. I will consider having better styling support in future releases.

antonjazz commented 3 years ago

Thanks for the response, Guille! I wish I were good enough with such things to help you with it and submit a pull request instead of an "issue"! Slowly getting there, I hope. :)

gonzalezreal commented 2 years ago

Hi @antonjazz, This issue has been fixed in MarkdownUI 1.0.0

antonjazz commented 2 years ago

Thank you for all the great hard work you've been putting in, @gonzalezreal !!

shawn-frank commented 1 month ago

Hello @gonzalezreal - I was wondering if we can set a custom spacing between list items ?

Let's say I have markdown like this:

Can I set the custom spacing between the list items ?

I tried doing:

someSwiftUIView
            .markdownBlockStyle(\.list) { configuration in
                configuration.label
                    .relativeLineSpacing(.em(45))

and

someSwiftUIView
.markdownBlockStyle(\.list) { configuration in
                configuration.label
                    .lineSpacing(45)

Neither of these have any impact.

gonzalezreal commented 1 month ago

Answered in #320