Down icon indicating copy to clipboard operation
Down copied to clipboard

Newlines ("\n") get lost and replaced with a whitespace

Open ndemie opened this issue 3 years ago • 14 comments

Please help prevent duplicate issues before submitting a new one:

  • [X] I've searched other open/closed issues for duplicates before opening up this new issue.

Report

Newlines seem to get lost when creating an attributed string using DownStyler and get replaced with a whitespace

What did you do?

let string = "Test\nTest"
let down = Down(markdownString: string)
do {
    let attributedString = try down.toAttributedString(styler: DownStyler(configuration: .testConfiguration)
    print(attributedString.string)
}

"Test Test"

What did you expect to happen?

print(attributedString.string)

"Test\nTest"

Before this we used a stylesheet which didn't cause this issue. I've tried replacing newlines by double newlines but that renders two newlines causing too much spacing.

ndemie avatar Aug 04 '21 09:08 ndemie

Hi @ndemie , so there is a specific option to use to treat these "soft breaks" (what you're getting) as "hard breaks" (what you want). By default, all single newlines are considered soft breaks. You want to pass in this option to the parser, so something like:

let attributedString = try down.toAttributedString(.hardBreaks, styler: DownStyler(configuration: .testConfiguration)

Let me know how it goes.

johnxnguyen avatar Aug 04 '21 11:08 johnxnguyen

That fixes it, thanks!

ndemie avatar Aug 04 '21 12:08 ndemie

Multiple breaks still seem to get lost though.

Test\nTest\n\nTest gets rendered as

Test
Test
Test

while I would expect

Test
Test

Test

Any solution for this @johnxnguyen?

ndemie avatar Aug 10 '21 12:08 ndemie

Also, unrelated (so let me know if you want this in a seperate issue), but none of the custom glyph's seem to get rendered for me e.g. codeBlockBackground, quoteStripe and thematicBreak. Any clue where the issue could be?

ndemie avatar Aug 10 '21 13:08 ndemie

@ndemie those custom attributes require the use of the DownLayoutManager, which understands what they are and is capable of drawing them in the text view. In short, you need to insert an instance of this object in your text field stack. Check out the implementation of DownTextView, or open a new issue and we can discuss it in more detail there.

johnxnguyen avatar Aug 10 '21 14:08 johnxnguyen

@ndemie regarding the line break issue, I'll need to try it out myself and do some debugging, not sure if it's an issue with the parsing or the styling. I have a bit of a backlog of things to do for this repo so I won't be able to jump on this immediately. Feel free to come back and remind me if there's no activity here.

johnxnguyen avatar Aug 10 '21 14:08 johnxnguyen

Multiple breaks isn't working for me either with the solution.

Is the fix still in the backlog?

applypost avatar Nov 23 '21 22:11 applypost

Any update on this @johnxnguyen?

ndemie avatar Apr 28 '22 07:04 ndemie

Hi @johnxnguyen, it's been a while. I was wondering if you had the chance to take a look at this yet?

ndemie avatar Sep 02 '22 08:09 ndemie

Do you still have time to fix this issue? @johnxnguyen

SilenceLove avatar Apr 28 '23 09:04 SilenceLove

I have encountered the same problem, and this problem has a great impact on me. Do you have time to solve it? Thanks very much!

YBJust avatar Mar 28 '24 10:03 YBJust