gonzalezreal / swift-markdown-ui

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

mulitiple line space is not equal, influence by paragraphSeparator #42

Closed oblank closed 2 years ago

oblank commented 3 years ago

screenshot

just like the screenshot

and the markedown text is:

#"""
        作者:[@jedz](https://www.v2ex.com/u/jedz),节点:[#程序员](https://www.v2ex.com/go/programmer) ,31回复,发布时间:2021-04-13 18:54:26

        日经问题:笔记软件的选择。。。

        用了好多年 OneNote,不过碍于以下几个问题现在想弃坑了:

        1. 字体问题,下英文字体动不动变成 calibri,很不爽。(用了 [OneFont]( [https://lxf.me/116](https://lxf.me/116)) 基本解决问题)

        2. 对插入代码的支持很差,不支持高亮,而且有时复制出来时会有奇怪的字符,导致粘贴后不能直接运行。

        3. 如果在页面中创建了多个框,则不能自适应宽度,然后移动端上就要拖来拖去才能看。

        4. 无本地文件( UWP 和 Mac 版)。

        然后最近试用了一周 Notion,总体感觉还不错,目前遇到两个问题比较影响体验(也可能是我不会用,求指点
"""#

I found the static let paragraphSeparator = "\u{2029}" caused this bug, if I set it to empty by static let paragraphSeparator = "", it looks ok

but loose the paragraph's line height between

gonzalezreal commented 3 years ago

🤔 That doesn't make much sense, as paragraphSeparator is used to separate the paragraphs, not the lines inside a paragraph.

I will have a look, nevertheless. Thanks for reporting!

oblank commented 3 years ago

🤔 That doesn't make much sense, as paragraphSeparator is used to separate the paragraphs, not the lines inside a paragraph.

I will have a look, nevertheless. Thanks for reporting!

It's confused,and if only english words, it seems there is no bug.

Thanks

gonzalezreal commented 3 years ago

I did a bit of research and it is related to paragraph styles, rather than the paragraph separator. That is, if there are paragraphs in the resulting attributed strings, then you get the weird differences in line spacing. I still have no clue on how to fix this one.

oblank commented 3 years ago

I did a bit of research and it is related to paragraph styles, rather than the paragraph separator. That is, if there are paragraphs in the resulting attributed strings, then you get the weird differences in line spacing. I still have no clue on how to fix this one.

get.

Thanks for your works.

gonzalezreal commented 3 years ago

To me, it looks like an iOS-only issue. Here is a screenshot of the Dingus example running in macOS:

Screenshot 2021-04-16 at 09 14 39

I see a consistent line spacing that only differs a little when the line has mixed Latin and Chinese characters, which is expected.

oblank commented 3 years ago

finaly, I found this https://stackoverflow.com/questions/6367681/line-spacing-in-multi-language-layout-with-core-text

looks like it's not a bug, but a typesetting systems problem. and after some research I 'fix' it with some codes below

paragraphStyle.lineSpacing  = 0.25 * font.pointSize
paragraphStyle.maximumLineHeight = font.lineHeight;
paragraphStyle.minimumLineHeight = font.lineHeight;

looks better.

screenshot

gonzalezreal commented 3 years ago

Yeah, that makes sense as a workaround. But the default values in the paragraph style should work properly as well.

gonzalezreal commented 2 years ago

Hi @oblank, I have been testing this with MarkdownUI 1.0.0 (which comes with a new renderer), and I can't reproduce it. It displays the markdown you provided correctly in iOS 14, iOS 14.5, and iOS 15.0.

Screenshot 2022-01-17 at 07 59 36