How to get the text from an AttributedString initialized with markdown?

Josh Birdwell

Using AttributeString that is inited with markdown:

AttributedString(styledMarkdown: "# header")

How can I get just only the text header?

This fails XCTAssertEqual(attributedString, "header") because attributedString is

header {
    NSPresentationIntent = [header 1 (id 1)]
}
Larme

NSAttributedString (in UIIKit/TextKit has a string property.

You can go from NSAttributedString to AttributedString to do so:

let nsAttributedString = NSAttributedString(attributedString)
let stringWithoutTags = nsAttributedString.string

You can also use characters of AttributedString:

let stringWithoutTags = String(attributedString.characters)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

iOS 15 beta 4: AttributedString with Markdown not rendering in Text in SwiftUI?

How can I get the date format from an initialized Bootstrap datepicker?

GitHub Markdown: How can I get rid of text wrap?

how to get figure floated / surrounded by text etc. in R markdown?

How to center text with Markdown?

How to extract only text from Markdown files in Javascript

How to parse markdown text from JSON and appending it to a file without ruining the markdown formatting?

Converting text from jira to markdown

Gatsby + Markdown: How to get data from a specific markdown file into a single page?

How to get text from image

How to get text from entry

How to get a text from EditText?

How to get text from url

How to get a text from SearchView?

how to get a text string from

How to get a particular text from the text box

How to Get Text from Online File .text

How to get text from a KivyMD text field?

How to focus text field when initstate is initialized

Python : How to convert markdown formatted text to text

Get only the initialized content from a slice

Swift 4 attributedString get typing attributes

Is there a way to get colored text in Github Flavored Markdown?

Is there a way to get colored text in GitHubflavored Markdown?

Get all text between each markdown heading

How is it possible to Lerp from a non initialized value to an initialized value?

How to get argument which sent from the Navigator Push method in flutter before the state initialized?

How to make a link in R Markdown output to get a pdf or HTML with hyperlinks in text

Save HTML from clipboard as markdown text

TOP Ranking

HotTag

Archive