<commit_before><p align="center" >
<img src="https://raw.githubusercontent.com/malcommac/SwiftRichString/master/SRRLogo.png" width=450px alt="SwiftRichString" title="SwiftRichString">
</p>

[![Platform](https://img.shields.io/cocoapods/p/SwiftRichString.svg?style=flat)](http://cocoadocs.org/docsets/SwiftRichString) [![Version](https://img.shields.io/cocoapods/v/SwiftRichString.svg?style=flat)](http://cocoadocs.org/docsets/SwiftRichString) 
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Twitter](https://img.shields.io/badge/twitter-@danielemargutti-blue.svg?style=flat)](http://twitter.com/danielemargutti)


SwiftRichString is a lightweight library which allows to create and manipulate attributed strings easily both in iOS, macOS, tvOS and even watchOS.
It provides convenient way to store styles you can reuse in your app's UI elements, allows complex tag-based strings rendering and also includes integration with Interface Builder.

## Main Features

|  	| Features Highlights 	|
|---	|---------------------------------------------------------------------------------	|
| 🦄 	| Easy styling with declarative syntax	|
| 🏞 	| Attach local and remote images inside text 	|
| 🧬 	| Fast & high customizable XML/HTML tagged string rendering 	|
| 🌟 	| Apply text transforms within styles	|
| 📐 	| Native support for iOS 11 Dynamic Type	|
| ⏱ 	| Compact code base with no external dependencies. 	|
| 🐦 	| Fully made in Swift 5 from Swift ❥ lovers 	|

### Easy Styling

```swift
let style = Style {
	$0.font = SystemFonts.AmericanTypewriter.font(size: 25) // just pass a string, one of the SystemFonts or an UIFont
	$0.color = "#0433FF" // you can use UIColor or HEX string!
	$0.underline = (.patternDot, UIColor.red)
	$0.alignment = .center
}
let attributedText = "Hello World!".set(style: style) // et voilà!
```

### 3. Complex XML/HTML based rendering
SwiftRichString allows you to render complex strings by parsing text's tags: each style will be identified by an unique name (used inside the tag) and you can create a `StyleGroup` which allows you to encapsulate all of them and reuse as you need (clearly you can register it globally).

```swift
// Create your own styles

let normal = Style {
	$0.font = SystemFonts.Helvetica_Light.font(size: 15)
}
		
let bold = Style {
	$0.font = SystemFonts.Helvetica_Bold.font(size: 20)
	$0.color = UIColor.red
	$0.backColor = UIColor.yellow
}
		
let italic = normal.byAdding {
	$0.traitVariants = .italic
}

let myGroup = StyleGroup(base: normal, ["bold": bold, "italic": italic])
let str = "Hello <bold>Daniele!</bold>. You're ready to <italic>play with us!</italic>"
self.label?.attributedText = str.set(style: myGroup)
```

That's the result!

<img src="Documentation_Assests/image_2.png" alt="" style="width: 150px;"/>

--

## Documentation

- [Introduction to `Style`, `StyleGroup` & `StyleRegEx`](#stylestylegroup)
	- [Introduction](#introduction)
	- [String & Attributed String concatenation](#concatenation)
	- [Apply styles to `String` & `Attributed String`](#manualstyling)
	- [Fonts & Colors in `Style`](#fontscolors)
	- [Derivating a `Style`](#derivatingstyle)
	- [Support Dynamic Type](#dynamictype)
	- [Render XML tagged strings](#customizexmlstrings)
	- [Customize XML rendering: react to tag's attributes and unknown tags](#xmlstrings)
	- [Custom text transforms](#texttransforms)
	- [Local & Remote Images inside text](#images)
- [The `StyleManager`](#stylemanager)
	- [Register globally available styles](#globalregister)
	- [Defer style creation on demand](#defer)
- [Assign style using Interface Builder](#ib)
- [All properties of `Style`](#props)

Other info:

- [Requirements](#requirements)
- [Installation](#installation)
- [Contributing](#contributing)
- [Copyright](#copyright)
<commit_msg>Updated documentation<commit_after><p align="center" >
<img src="https://raw.githubusercontent.com/malcommac/SwiftRichString/master/SRRLogo.png" width=450px alt="SwiftRichString" title="SwiftRichString">
</p>

[![Platform](https://img.shields.io/cocoapods/p/SwiftRichString.svg?style=flat)](http://cocoadocs.org/docsets/SwiftRichString) [![Version](https://img.shields.io/cocoapods/v/SwiftRichString.svg?style=flat)](http://cocoadocs.org/docsets/SwiftRichString) 
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Twitter](https://img.shields.io/badge/twitter-@danielemargutti-blue.svg?style=flat)](http://twitter.com/danielemargutti)


SwiftRichString is a lightweight library which allows to create and manipulate attributed strings easily both in iOS, macOS, tvOS and even watchOS.
It provides convenient way to store styles you can reuse in your app's UI elements, allows complex tag-based strings rendering and also includes integration with Interface Builder.

## Main Features

|  	| Features Highlights 	|
|---	|---------------------------------------------------------------------------------	|
| 🦄 	| Easy styling with declarative syntax	|
| 🏞 	| Attach local and remote images inside text 	|
| 🧬 	| Fast & high customizable XML/HTML tagged string rendering 	|
| 🌟 	| Apply text transforms within styles	|
| 📐 	| Native support for iOS 11 Dynamic Type	|
| ⏱ 	| Compact code base with no external dependencies. 	|
| 🐦 	| Fully made in Swift 5 from Swift ❥ lovers 	|

### Easy Styling

```swift
let style = Style {
	$0.font = SystemFonts.AmericanTypewriter.font(size: 25) // just pass a string, one of the SystemFonts or an UIFont
	$0.color = "#0433FF" // you can use UIColor or HEX string!
	$0.underline = (.patternDot, UIColor.red)
	$0.alignment = .center
}
let attributedText = "Hello World!".set(style: style) // et voilà!
```

### XML/HTML tag based rendering
SwiftRichString allows you to render complex strings by parsing text's tags: each style will be identified by an unique name (used inside the tag) and you can create a `StyleGroup` which allows you to encapsulate all of them and reuse as you need (clearly you can register it globally).

```swift
// Create your own styles

let normal = Style {
	$0.font = SystemFonts.Helvetica_Light.font(size: 15)
}
		
let bold = Style {
	$0.font = SystemFonts.Helvetica_Bold.font(size: 20)
	$0.color = UIColor.red
	$0.backColor = UIColor.yellow
}
		
let italic = normal.byAdding {
	$0.traitVariants = .italic
}

let myGroup = StyleGroup(base: normal, ["bold": bold, "italic": italic])
let str = "Hello <bold>Daniele!</bold>. You're ready to <italic>play with us!</italic>"
self.label?.attributedText = str.set(style: myGroup)
```

That's the result!

<img src="Documentation_Assests/image_2.png" alt="" style="width: 70px;"/>

--

## Documentation

- [Introduction to `Style`, `StyleGroup` & `StyleRegEx`](#stylestylegroup)
	- [Introduction](#introduction)
	- [String & Attributed String concatenation](#concatenation)
	- [Apply styles to `String` & `Attributed String`](#manualstyling)
	- [Fonts & Colors in `Style`](#fontscolors)
	- [Derivating a `Style`](#derivatingstyle)
	- [Support Dynamic Type](#dynamictype)
	- [Render XML tagged strings](#customizexmlstrings)
	- [Customize XML rendering: react to tag's attributes and unknown tags](#xmlstrings)
	- [Custom text transforms](#texttransforms)
	- [Local & Remote Images inside text](#images)
- [The `StyleManager`](#stylemanager)
	- [Register globally available styles](#globalregister)
	- [Defer style creation on demand](#defer)
- [Assign style using Interface Builder](#ib)
- [All properties of `Style`](#props)

Other info:

- [Requirements](#requirements)
- [Installation](#installation)
- [Contributing](#contributing)
- [Copyright](#copyright)

{'fraction_non_alphanumeric': 0.15373637778930982, 'fraction_numerical': 0.008303061754021795, 'mean_word_length': 4.413623595505618, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1804399', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2413, 'n_words': 690}