Class: Prosereflect::ListItem
- Defined in:
- lib/prosereflect/list_item.rb
Overview
ListItem class represents a list item in ProseMirror.
Constant Summary collapse
- PM_TYPE =
'list_item'
Class Method Summary collapse
Instance Method Summary collapse
- #add_content(content) ⇒ Object
-
#add_hard_break(marks = nil) ⇒ Object
Add a hard break to the last paragraph, or create a new one if none exists.
- #add_paragraph(text = nil) ⇒ Object
-
#add_text(text, marks = nil) ⇒ Object
Add text to the last paragraph, or create a new one if none exists.
-
#initialize(attributes = {}) ⇒ ListItem
constructor
A new instance of ListItem.
-
#text_content ⇒ Object
Get plain text content from all nodes.
Methods inherited from Node
#add_child, #find_all, #find_children, #find_first, #marks, #marks=, #parse_content, #process_attrs_data, #raw_marks, #to_h, #to_yaml
Constructor Details
#initialize(attributes = {}) ⇒ ListItem
Returns a new instance of ListItem.
22 23 24 25 |
# File 'lib/prosereflect/list_item.rb', line 22 def initialize(attributes = {}) attributes[:content] ||= [] super end |
Class Method Details
.create(attrs = nil) ⇒ Object
27 28 29 |
# File 'lib/prosereflect/list_item.rb', line 27 def self.create(attrs = nil) new(attrs: attrs) end |
Instance Method Details
#add_content(content) ⇒ Object
38 39 40 |
# File 'lib/prosereflect/list_item.rb', line 38 def add_content(content) add_child(content) end |
#add_hard_break(marks = nil) ⇒ Object
Add a hard break to the last paragraph, or create a new one if none exists
51 52 53 54 55 56 |
# File 'lib/prosereflect/list_item.rb', line 51 def add_hard_break(marks = nil) last_paragraph = content&.last last_paragraph = add_paragraph if !last_paragraph || !last_paragraph.is_a?(Paragraph) last_paragraph.add_hard_break(marks) self end |
#add_paragraph(text = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/prosereflect/list_item.rb', line 31 def add_paragraph(text = nil) paragraph = Paragraph.new paragraph.add_text(text) if text add_child(paragraph) paragraph end |
#add_text(text, marks = nil) ⇒ Object
Add text to the last paragraph, or create a new one if none exists
43 44 45 46 47 48 |
# File 'lib/prosereflect/list_item.rb', line 43 def add_text(text, marks = nil) last_paragraph = content&.last last_paragraph = add_paragraph if !last_paragraph || !last_paragraph.is_a?(Paragraph) last_paragraph.add_text(text, marks) self end |
#text_content ⇒ Object
Get plain text content from all nodes
59 60 61 62 63 |
# File 'lib/prosereflect/list_item.rb', line 59 def text_content return '' unless content content.map { |node| node.respond_to?(:text_content) ? node.text_content : '' }.join("\n").strip end |