GithubHelp home page GithubHelp logo

kiransarella / attributedstringstyledmarkdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from frankrausch/attributedstringstyledmarkdown

0.0 1.0 0.0 1.11 MB

AttributedString Markdown initializer with custom styling

License: MIT License

Swift 100.00%

attributedstringstyledmarkdown's Introduction

AttributedString Markdown initializer with custom styling

AttributedString in iOS 15 and macOS 12 comes with a Markdown initializer.


But:

  • There is no styling (not even bold or italic) when drawing the AttributedString in a custom view.
  • The AttributedString does have some styling applied when it’s assigned to a UILabel or to a UITextView, but they are noticeably different and weird things happen with the font sizes.
  • All line breaks that should separate the content blocks are missing.
  • The AttributedString colors don’t react to toggling between dark and light mode.

What’s going on?

There is not a lot of information about Markdown in AttributedString out there yet, but I think I was just holding it wrong:

The Markdown initializer merely adds semantic (not visual) markup to the AttributedString. Both UILabel and UITextView interpret these to a certain extent, while drawing a raw (NS)AttributedString doesn’t.

The Markdown initializer merely puts the Markdown parsing results as Presentation Intents into the AttributedString runs.

  • There are inlinePresentationIntents, e.g. .stronglyEmphasized for bold text.
  • There are presentationIntents for blocks like headlines (like .header(1) for a H1).

This sample project

This sample project shows how you can find these intents and replace them with actual AttributedString styling information like font weights and foreground colors.

I don’t know if there’s a more elegant way to solve this. Do let me know if you have a better solution!

AttributedString Markdown Light

AttributedString Markdown Dark


© 2021 Frank Rausch

attributedstringstyledmarkdown's People

Contributors

frankrausch avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.