Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plain-text-renderer? #8

Open
andrewplummer opened this issue Dec 3, 2019 · 1 comment
Open

plain-text-renderer? #8

andrewplummer opened this issue Dec 3, 2019 · 1 comment

Comments

@andrewplummer
Copy link

andrewplummer commented Dec 3, 2019

Apologies for asking this here but I couldn't find any other information online... is there contentful sanctioned swift equivalent for the npm plain-text-render here? https://www.npmjs.com/package/@contentful/rich-text-plain-text-renderer

Thank you

@basememara
Copy link

The library was overkill for rich text, I guess because of linked entries. I believe linked entries should be made into a separate library and the rich text to NSAttributedString conversion should be made available in the core Contentful Swift SDK.

We ended up trying something like this without this library:

extension Array where Element == Node {
    
    /// Converts the rich text type to plain string.
    func string() -> String {
        reduce(into: "") { result, next in
            switch next {
            case let object as Text:
                result += object.value
            case let object as Paragraph:
                result += object.content.string()
            default:
                break
            }
        }
    }
}

This can be used like the following when you have a rich text property:
object.body.content.string()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants