Post

Replies

Boosts

Views

Activity

Reply to WebView
Your HTML is static / hardcoded right? Put all the HTML into a single variable (get rid of the empty markdown string) Call parser.html() on that variable. Pass the return value from parser.html() into loadHTMLString() Do all of steps 1 - 3 directly inside of the updateUIView() function. I'm not sure why you havethe ParseContent class. Just get rid of it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’23
Reply to WebView
Something like this... import SwiftUI import WebKit struct HardCodedWebView: UIViewRepresentable { let markdown: String func makeUIView(context: Context) -> WKWebView { return WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { let htmlStart = "<HTML><HEAD></HEAD><BODY style=\"padding: 140px; font-size: 120px; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Open Sans,Helvetica Neue,sans-serif\">" let htmlEnd = "</BODY></HTML>" let html = htmlStart + markdown + htmlEnd uiView.loadHTMLString(html, baseURL: nil) } } struct HardCodedWebView_Previews: PreviewProvider { static var previews: some View { let markdownExample = "**random markdown text**" HardCodedWebView(markdown: markdownExample) } } FYI a regular Text() will render markdown directly.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’23