Sha256: f95a97da7506d6d4ba21a7d3fdbe027c80a35a250c70cd03074060a4387267bf

Contents?: true

Size: 927 Bytes

Versions: 1

Compression:

Stored size: 927 Bytes

Contents

Editor.Parsers.push class
  rule: /^((~{3,})([a-z]+)?$)(.+)?(~{3,}$)?/mi

  constructor: (node) ->
    @nodes = [node]
    @tildeCount = 0

  isMatched: =>
    @match = @rule.exec(@nodes[0].textContent)
    if @match? && @match[0]?
      @tildeCount = @match[2].length
      @collectSiblingsUntilMatched(@tildeCount, @nodes[0])

  collectSiblingsUntilMatched: (count, node) =>
    node = node.nextSibling
    while node
      @nodes.push node
      nextNode = node.nextSibling
      node.remove()

      match = @rule.exec(node.textContent)

      if match? && match[2]? && match[2].length == count
        break

      node = nextNode


  render: =>
    pre = "<pre>".toHTML()
    code = "<code>".toHTML()
    if @match[3]?
      code.classList.add("language-#{@match[3]}")
    texts = @nodes.map (n) -> n.textContent
    code.textContent = texts.join("\n")
    Prism.highlightElement(code)
    pre.appendChild(code)
    pre

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ecrire-0.20.0 lib/ecrire/app/assets/javascripts/admin/editor/parsers/code.coffee