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

apply defaults to document #9

Closed
abumami opened this issue Apr 19, 2017 · 1 comment
Closed

apply defaults to document #9

abumami opened this issue Apr 19, 2017 · 1 comment
Assignees
Labels

Comments

@abumami
Copy link

abumami commented Apr 19, 2017

It would be nice if there was an easy way to apply defaults to the document. For example: define a document as default right-to-left, define a document with a default font (family, size, etc), define a document with a theme (background color, text color, etc).

All in all, a very nice project. I'm enjoying playing with it.

@malcommac
Copy link
Owner

You can define a default style; it's the Style.default constructor of the Style class.
In a sequence of styles it will be applied in first place.

Let me show to you an example:

let default_style = Style.default {
	$0.font = FontAttribute(.GillSans_Italic, size: 20)
}

let boldred_style = Style("mystyle") {
	$0.color = .red
	$0.font = FontAttribute(.AppleSDGothicNeo_Bold, size: 40)
}
		
let str = "Default style is applied in first place, <mystyle>other styles follows</mystyle>. It's cool!"
let rendered = try! MarkupString(source: str, styles: [default_style,boldred_style]).render()

Will produce this:
screen shot 2017-07-06 at 23 26 50

@malcommac malcommac self-assigned this Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants