Class: ProseMirror::Mark

Inherits:
Object
  • Object
show all
Defined in:
lib/prose_mirror/mark.rb

Overview

Represents a mark in a ProseMirror document Marks can be applied to nodes to indicate formatting or other attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, attrs = {}) ⇒ Mark

Create a new Mark

Parameters:

  • type (String)

    The mark type name (e.g., “strong”, “em”, “link”)

  • attrs (Hash) (defaults to: {})

    Mark attributes



10
11
12
13
# File 'lib/prose_mirror/mark.rb', line 10

def initialize(type, attrs = {})
  @type = OpenStruct.new(name: type)
  @attrs = attrs
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



5
6
7
# File 'lib/prose_mirror/mark.rb', line 5

def attrs
  @attrs
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/prose_mirror/mark.rb', line 5

def type
  @type
end

Instance Method Details

#eq(other) ⇒ Boolean

Check if this mark is equal to another mark Two marks are equal if they have the same type name

Parameters:

  • other (Mark)

    The other mark to compare with

Returns:

  • (Boolean)

    true if the marks are equal, false otherwise



19
20
21
# File 'lib/prose_mirror/mark.rb', line 19

def eq(other)
  @type.name == other.type.name
end

#is_in_set(mark_array) ⇒ Boolean

Check if this mark is in the given set of marks

Parameters:

  • mark_array (Array<Mark>)

    The array of marks to check against

Returns:

  • (Boolean)

    true if the mark is in the set, false otherwise



26
27
28
# File 'lib/prose_mirror/mark.rb', line 26

def is_in_set(mark_array)
  mark_array.any? { |m| eq(m) }
end