gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.44k stars 298 forks source link

Word-Wrapping Issue #304

Open gerrylu1 opened 6 months ago

gerrylu1 commented 6 months ago

Thank you for contributing to MarkdownUI!

Before you submit an issue, please complete the report with all the relevant details for your bug and go through every item in the checklist.

Describe the bug As the title suggests, this is a word-wrapping issue.

Checklist

Steps to reproduce Please refer to the code here:

import SwiftUI
import MarkdownUI

struct MarkdownTestView: View {
    private var screenWidth: CGFloat {
        UIScreen.main.bounds.width
    }

    private var markdownText = "This shipment has been been delivered."

    var body: some View {
        VStack(spacing: 8) {
            HStack(alignment: .bottom, spacing: 8) {
                markdownMessageView
            }

            HStack {
                markdownMessageView
            }

            ZStack {
                HStack{
                    Spacer()
                }
                Markdown{
                    """
                    ## Using a Markdown Content Builder
                    Use Markdown strings or an expressive domain-specific language
                    to build the content.

                    This shipment has been been delivered.
                    """
                    Heading(.level2) {
                      "Try MarkdownUI"
                    }
                    Paragraph {
                      Strong("MarkdownUI")
                      " is a native Markdown renderer for SwiftUI"
                      " compatible with the "
                      InlineLink(
                        "GitHub Flavored Markdown Spec",
                        destination: URL(string: "https://github.github.com/gfm/")!
                      )
                      "."
                    }
                }
            }
            .padding(12)
            .background(
                RoundedRectangle(cornerRadius: 12, style: .continuous)
                    .foregroundColor(Color.secondary.opacity(0.2))
            )

        }
        .padding(.trailing, screenWidth * 0.2)
    }

    private var markdownMessageView: some View {
        HStack {
            Markdown {
                markdownText
            }
            .multilineTextAlignment(.leading)
            .padding(12)
            .background(Color.red)

            Spacer()
        }
        .background(
            RoundedRectangle(cornerRadius: 12, style: .continuous)
                .foregroundColor(Color.secondary.opacity(0.2))
        )
    }
}

Expected behavior The repeated word "been" should have stayed in the line above since there was still space for the word.

Screenshots If applicable, add screenshots to help explain your problem. simulator_screenshot_6942D5AE-7905-4F82-B269-A618949FC987

Version information