Trek::Contentable
Utilities for rich text stored as ProseMirror JSON in a content column — the format produced by Trek's content editor.
Methods
| Method | Returns |
|---|---|
parsed_content | the content as a hash (parsing JSON strings if needed) |
formatted_content | safe HTML, rendered through the ProseMirror pipeline |
content_text | plain text extracted from all text nodes |
prosemirror_content? | whether content is a valid ProseMirror document |
Usage
ruby
class Page < ApplicationRecord
include Trek::Contentable
end
page.formatted_content # => "<p>Hello <strong>world</strong></p>"
page.content_text # => "Hello world"Requirements
- A
contentjsonb column - Used by Page, PageVersion and Fragment