You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+149Lines changed: 149 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,3 +99,152 @@ Retain operations have a Number `retain` key defined representing the number of
99
99
{ retain:5, attributes: { bold: null } }
100
100
```
101
101
102
+
## HTML Formatting
103
+
104
+
Rich-text deltas may be formatted as HTML by calling `delta.to_html`. The rendered markup will be generated based on formatting rules configured for the `RichText` module.
105
+
106
+
### Inline formats
107
+
108
+
Inline formatting rules are used to build tags for the flow of content elements.
Each newline (`"\n"`) character denotes a block separation, at which time the inline flow will be wrapped in a block tag specified by `html_default_block_format`. An inline element's block wrapper maybe customized with the `block_format` setting, or omitted with the `omit_block` setting. For soft or visible line breaks such as `br` or `hr` tags, you may assign them inline formats to render them as content flow.
Block tags are wrapped around a flow of elements whenever a newline is encountered (unless it has an inline format). Block formats should always apply to newline (`"\n"`) inserts.
Block tags may define a `parent` tag, or an array of parents. When a block has a parent, its full parent tree is constructed and/or merged with a compatible node tree that preceeds it.
200
+
201
+
### Formatting lambdas
202
+
203
+
Use `tag` and `apply` lambdas to customize tag structures.
A `tag` lambda is called once when an element is created. The tag lambda returns a customized node structure, or nil to render nothing. An `apply` lambda is called for each formatting rule applied to an element. An apply lambda does not return a value.
245
+
246
+
**Both `tag` and `apply` receive the same arguments:**
247
+
248
+
-`el`: the [Nokogiri::XML::Node](https://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Node) instance being rendered. For `tag` lambdas, this will be a new `span`.
249
+
-`op`: the `RichText::Op` instance being rendered. You may references its `attributes` and `value`.
250
+
-`ctx`: an optional context object passed via `delta.to_html(context: obj)`. Providing a render context allows data to be shared across all formatting functions.
0 commit comments