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

Help: Set Default Font #168

Closed
cliftonlabrum opened this issue Jul 26, 2019 · 6 comments
Closed

Help: Set Default Font #168

cliftonlabrum opened this issue Jul 26, 2019 · 6 comments

Comments

@cliftonlabrum
Copy link

I've been searching through the documentation and the issues, and I don't see a clear way to set the default font for the entire NSAttributedString. If you apply the font as an attribute after Down renders the string, it will overwrite all the other attributes.

Is there a way to set a default font and then have Down render the rest of the string as it should (bold, italic, etc.?

I see the Styler option, but I don't see any documentation on how to use it.

Thanks!

@iwasrobbed
Copy link
Collaborator

Does this work for you?

https://github.com/iwasrobbed/Down#parsing-api

// NSAttributedString representation of the rendered HTML;
// by default, uses a stylesheet that matches NSAttributedString's default font,
// but you can override this by passing in your own, using the 'stylesheet:' parameter.

@cliftonlabrum
Copy link
Author

That's interesting. What kind of String does the stylesheet parameter take?

Does it use raw CSS properties like:

down.toAttributedString(stylesheet:"font-family: 'Avenir'")

Or does it take a full CSS file in the form of a String like:

let style = "body{ font-family: 'Avenir'; }"
down.toAttributedString(stylesheet: style)

Thanks!

@freshking
Copy link

Something like this (taken from DownAttributedStringRenderable.swift):

let style = "* {font-family: Helvetica } code, pre { font-family: Menlo }"
down.toAttributedString(stylesheet: style)

@cliftonlabrum
Copy link
Author

Ah, okay. Makes sense. Thank you!

@iwasrobbed
Copy link
Collaborator

FYI: this is further possible via the default Styler via #177

@nselvapandian
Copy link

let defaultStylesheet = "* {font-family: SFProDisplay-Semibold; font-size: 15px}"

Is this the correct format to set system font? Can someone guide me?

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

4 participants