Module: ProseMirror::Serializers

Defined in:
lib/prose_mirror/serializers/markdown_serializer.rb

Defined Under Namespace

Classes: MarkdownSerializer, MarkdownSerializerState

Constant Summary collapse

BLANK_MARK =

A blank mark used as a fallback

{open: "", close: "", mixable: true}.freeze

Class Method Summary collapse

Class Method Details

.backticks_for(node, side) ⇒ Object

Helper method for determining backticks for code marks



304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/prose_mirror/serializers/markdown_serializer.rb', line 304

def self.backticks_for(node, side)
  ticks = /`+/
  len = 0

  if node.is_text
    node.text.scan(ticks) { |m| len = [len, m.length].max }
  end

  result = (len > 0 && side > 0) ? " `" : "`"
  len.times { result += "`" }
  result += " " if len > 0 && side < 0

  result
end

.is_plain_url(link, parent, index) ⇒ Object

Determines if a link is a plain URL



320
321
322
323
324
325
326
327
# File 'lib/prose_mirror/serializers/markdown_serializer.rb', line 320

def self.is_plain_url(link, parent, index)
  return false if link.attrs[:title] || !/^\w+:/.match?(link.attrs[:href])

  content = parent.child(index)
  return false if !content.is_text || content.text != link.attrs[:href] || content.marks[content.marks.length - 1] != link

  index == parent.child_count - 1 || !link.is_in_set(parent.child(index + 1).marks)
end