johnxnguyen / Down

Blazing fast Markdown / CommonMark rendering in Swift, built upon cmark.
Other
2.24k stars 319 forks source link

Punctuation gets placed at the start of the line #283

Closed ndemie closed 2 years ago

ndemie commented 2 years ago

I'm running in to an issue where punctuation gets placed at the start of a line for some paragraphs. The source text in our database seems correct and after parsing to an attributed string the string also seems correct. There must be something in the styling that causes this however I'm unable to find anything weird.

Input text: Wat gaan wij tijdens de training doen?

The printed attributed string properties:

Wat gaan we tijdens de training doen?
{
    NSColor = "UIExtendedSRGBColorSpace 0.227451 0.227451 0.235294 1";
    NSFont = "<UICTFont: 0x7f86031d2400> font-family: \"SFProText-Regular\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ''";
}
{
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ''";
}‏‏‎ ‎{
    NSColor = "UIExtendedSRGBColorSpace 0.227451 0.227451 0.235294 1";
    NSFont = "<UICTFont: 0x7f86031d2400> font-family: \"SFProText-Regular\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ''";
}
{
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ''";
}•  {
    NSColor = "UIExtendedSRGBColorSpace 0.227451 0.227451 0.235294 1";
    NSFont = "<UICTFont: 0x7f86031d2400> font-family: \"SFProText-Regular\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 12.4531, TailIndent 0, FirstLineHeadIndent -2.43164, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    \"14.8848N\"\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ''";
}

Is there something that I'm missing that's causing this?

ndemie commented 2 years ago

Forcing a baseWritingDirection of NSWritingDirection.init(rawValue: 0) on the NSMutableParagraphStyle() assigned to the StaticParagraphStyleCollection properties fixes this.

However I'm unsure where the "-1" comes from that's being printed. This might be a bug in the library