---
name: TXT2TAGS
tags:
#- selector : TXT2TAGS
#  begin : "<html>\n<body>\n"
#  end   : "</body>\n</html>\n"
#  filters:
#    - indent
- selector : markup.other.paragraph - markup.raw
  begin : "<p>\n"
  end   : "\n</p>\n"
  filters:
    - strip
    - indent
- selector : markup.heading.plain
  cbegin   : '"<h#{predecessor.text.size}>"'
  cend     : '"</h#{successor.text.size}>\n"'
  filters  :
    - strip
- selector : other.filler
  invisible: true
- selector : keyword.other  - markup.raw
  invisible: true
- selector : comment
  invisible: true
- selector : variable - markup.raw
  invisible: true
- selector : markup.other.email - markup.raw
  cbegin   : '"<a href=\"mailto:#{text}\">"'
  end      : </a>
- selector : markup.other.link - markup.raw
  cbegin   : '"<a href=\"#{text}\">"'
  end      : </a>
- selector : meta.link.complex markup.other.link - markup.raw
  invisible: true
- selector : meta.link.complex - markup.raw
  ccontent : |-
    "<a href='#{children[3].text}'>#{children[1].text}</a>"
- selector : markup.bold - markup.raw
  begin    : <b>
  end      : </b>
- selector : markup.italic - markup.raw
  begin    : <i>
  end      : </i>
- selector : markup.underline - markup.raw
  begin    : <u>
  end      : </u>
- selector : markup.raw.verbatim
  begin    : "<code>"
  end      : "</code>"
- selector : markup.raw.verbatim.line
  begin    : "<pre>\n"
  end      : "\n</pre>\n"
- selector : markup.raw.verbatim.block
  begin    : "<pre>\n"
  end      : "</pre>\n"
- selector : markup.quote.line - markup.raw
  cbegin   : |-
    @@quote_depth ||= []
    depth = predecessor.text.size
    if @@quote_depth.empty? 
       @@quote_depth << depth
       ("\t" * depth) + "<blockquote>\n"
    elsif depth > @@quote_depth.last
       @@quote_depth << depth
       "\n" + ("\t" * depth) + "<blockquote>\n"
    else
       ""
    end
  cend     : |-
    next_depth = successor.text.size
    if ! next_depth || successor.name != predecessor.name
       result = "\n"
       while ! @@quote_depth.empty?
         depth = @@quote_depth.pop
         result += ("\t" * depth) + "</blockquote>\n"
       end
       result
    elsif next_depth < @@quote_depth.last
       depth = @@quote_depth.pop
       "\n" + ("\t" * depth) + "</blockquote>\n"
    else
       ""
    end
  filters  :
    - strip
- selector : markup.list.unnumbered - markup.raw
  cbegin   : |-
    @@list_stack ||= []
    res = ""
    depth = predecessor.text.size
    if @@list_stack.empty? 
       res += (" " * depth) + "<ul>\n"
    elsif depth > @@list_stack.last
       res += "\n" + (" " * depth) + "<ul>\n"
    end
    @@list_stack << depth
    res += "\n" + (" " * depth) + "<li>\n"
  cend     : |-
    depth = predecessor.text.size
    res = ""
    if depth < @@list_stack.last
       res += "\n"
       while depth < @@list_stack.last
         res += (" " * @@list_stack.pop) + "</ul>\n"
       end
       res
    end
    res += "\n" + (" " * depth ) + "</li>\n"
    if successor.name != predecessor.name
       res = "\n"
       while ! @@list_stack.empty?
         depth = @@list_stack.pop
         res += (" " * depth) + "</ul>\n"
       end
    end
    res
  filters  :
    - strip
- selector : line.blank
  invisible: true
  begin    : <line.blank>
  end      : </line.blank>
- selector : markup.other.bar.thin - markup.raw
  begin    : <hr noshade size=1>
  nocontent: true
- selector : markup.other.bar.thick - markup.raw
  begin    : <hr noshade size=5>
  nocontent: true
- selector : markup.raw line.blank

