gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.53k stars 318 forks source link

Issue with identifying the single line break "\n" and adding it to the end of previous line #352

Closed DeepakiOS1993 closed 2 weeks ago

DeepakiOS1993 commented 3 weeks ago

Hi Team , great work keep going!!!!

I am facing issue when trying to render the string from web which has single line breaks and multiple line breaks

Below is the Sample of string i Am trying to render

String to render

_`Example #1 - This is due to new markdown formatting/syntax because of the new iOS markdown library. Before MD Library Change You could bold the header of a paragraph and we were told not to put a space between the bold header and new paragraph (above or below the bold text), as the old markdown library added the space automatically.

Example #2 - To show the correct new iOS MD Syntax

After MD Library Change

If we don't put a space between the bold text, the paragraph below it, or above, it looks like the above example in your phone [iOS]. However, this example adds two spaces in the Android markdown view and is an issue they are working on now.`_

To Bring to Notice there is line break after first line.

ScreenShot

But the output which i could seen on screen is some thing similar to below Simulator Screenshot - iPhone 15 Pro - 2024-10-14 at 20 39 12

There should be line break before and after the bold text i.e Before MD Library Change But as we see the output only shows double link breaks which is before .

The String which i want to render is something similar to

"Example #1 - This is due to new markdown formatting/syntax because of the new iOS markdown library.\n**Before MD Library Change**\nYou could bold the header of a paragraph and we were told not to put a space between the bold header and new paragraph (above or below the bold text), as the old markdown library added the space automatically.\n\nExample #2 - To show the correct new iOS MD Syntax\n\n**After MD Library Change**\n\nIf we don\'t put a space between the bold text, the paragraph below it, or above, it looks like the above example in your phone [iOS]. However, this example adds two spaces in the Android markdown view and is an issue they are working on now."

Please support as using it in producation App, Note : Using as package Dependencies with SPM, And version of library 2.4.1

davidseek commented 2 weeks ago

+1

Also experiencing issues when rendering \n and \n\n. Some line-breaks work, others are breaking.

Raw text

Here are some restaurants near you:\n\n 1.  **FRED 06825**\n    - Address: 2439 Black Rock Turnpike, Fairfield, CT 06825\n    - Distance: 0.0 mi\n    - Rating: 4.5 (Yelp)\n    - Phone: +12036126597\n    - Hours: Mon & Fri 9AM-8PM, Tue-Thu 9AM-6PM, Sat 9AM-5PM\n\n2.  **Whoopi Thai Cuisine**\n    - Address: 2449 Black Rock Turnpike, Fairfield, CT 06825\n    - Distance: 0.0 mi\n    - Rating: 4.0 (Yelp)\n    - Phone: +12034294956\n    - Hours: Sun, Mon, Wed, Thu 11:30AM-9PM, Fri-Sat 11:30AM-9:30PM\n\n3.  **Duchess of Black Rock**\n    - Address: 2315 Black Rock Tpke, Fairfield, CT 06825\n    - Distance: 0.1 mi\n    - Rating: 2.0 (Yelp)\n    - Phone: +12033720449\n    - Hours: Open 24/7\n\n These are the closest restaurants to your location.  Would you like more information about any of these options or would you prefer to see more restaurants?

Broken nested lists

Screenshot 2024-10-16 at 11 14 03 AM
gonzalezreal commented 2 weeks ago

Hi there,

By default, Markdown considers single line breaks \n inside a paragraph as soft-breaks. For reference, see the specs.

Markdown renderers can choose to render a soft-break either as a space ` or as a newline\n. For instance, GitHub renders soft-breaks as spaces in Markdown files (ie.README.md`), but it uses newlines in comments.

MarkdownUI renders soft-breaks as spaces by default, but you can tweak this behavior thanks to a recent contribution. See #342 for more information.

gonzalezreal commented 2 weeks ago

The following test might help as well: https://github.com/gonzalezreal/swift-markdown-ui/blob/a9c7615fb50323069c2979c69263973aa1b24a8f/Tests/MarkdownUITests/MarkdownTests.swift#L325-L344