daltoniam/bumblebee

How to manage default attributes?

Opened this issue · 4 comments

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?

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))
 }

}

Sorry, same as #1

Oups, closed by mistake.

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