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

How to manage default attributes? #13

Closed
ghost opened this issue Nov 5, 2015 · 4 comments
Closed

How to manage default attributes? #13

ghost opened this issue Nov 5, 2015 · 4 comments

Comments

@ghost
Copy link

ghost commented Nov 5, 2015

Current example transform raw text to NSAttributedString for few markdown patters:

  • emphasized text,*?*
  • important text, _*_
  • image pattern,![?](?)

But how to apply default formatting to overall text?

@ghost
Copy link
Author

ghost commented Nov 5, 2015

One solution is to add default attributes data as parameter to init then apply them first at the end before adding generated attributes by replacing setAttributes by addAttributes.

public func process(srcText: String, attrs:[String : AnyObject]) -> NSAttributedString {

...

 // we have our patterns, let's build a stylized string

 // 1. Apply default attributes
 let attributedText = NSMutableAttributedString(string:text, attributes:attrs)

 // 2. Add attributes brought by markdown
 for pattern in collect {
     attributedText.addAttributes(pattern.attrs!, range: NSMakeRange(pattern.start, pattern.length))
 }

}

@ghost
Copy link
Author

ghost commented Nov 5, 2015

Sorry, same as #1

@ghost ghost closed this as completed Nov 5, 2015
@ghost
Copy link
Author

ghost commented Nov 5, 2015

Oups, closed by mistake.

@ghost ghost reopened this Nov 5, 2015
daltoniam added a commit that referenced this issue Nov 6, 2015
@daltoniam
Copy link
Owner

1.0.1 released. See README:

let defaultAttrs = [NSFontAttributeName: UIFont.systemFontOfSize(18)] //default attributes to apply
let attrString = bee.process(rawText,attributes: defaultAttrs) //attributes can be omited if unneeded

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

1 participant