#-- # Copyright (C) 2006 Andrea Censi # # This file is part of Maruku. # # Maruku is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Maruku is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Maruku; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #++ require 'set' module MaRuKu; module In; module Markdown; module SpanLevelParser include MaRuKu::Helpers EscapedCharInText = Set.new [?\\,?`,?*,?_,?{,?},?[,?],?(,?),?#,?.,?!,?|,?:,?+,?-,?>] EscapedCharInQuotes = Set.new [?\\,?`,?*,?_,?{,?},?[,?],?(,?),?#,?.,?!,?|,?:,?+,?-,?>,?',?"] EscapedCharInInlineCode = [?\\,?`] def parse_lines_as_span(lines, parent=nil) parse_span_better lines.join("\n"), parent end def parse_span_better(string, parent=nil) if not string.kind_of? String then error "Passed #{string.class}." end st = (string + "") st.freeze src = CharSource.new(st, parent) read_span(src, EscapedCharInText, [nil]) end # This is the main loop for reading span elements # # It's long, but not *complex* or difficult to understand. # # def read_span(src, escaped, exit_on_chars, exit_on_strings=nil) con = SpanContext.new c = d = nil while true c = src.cur_char # This is only an optimization which cuts 50% of the time used. # (but you can't use a-zA-z in exit_on_chars) if c && ((c>=?a && c<=?z) || ((c>=?A && c<=?Z))) con.cur_string << src.shift_char next end break if exit_on_chars && exit_on_chars.include?(c) break if exit_on_strings && exit_on_strings.any? {|x| src.cur_chars_are x} # check if there are extensions if check_span_extensions(src, con) next end case c = src.cur_char when ?\ # it's space (32) if src.cur_chars_are " \n" src.ignore_chars(3) con.push_element md_br() next else src.ignore_char con.push_space end when ?\n, ?\t src.ignore_char con.push_space when ?` read_inline_code(src,con) when ?< # It could be: # 1) HTML "
> case d = src.next_char when ?<; # guillemettes src.ignore_chars(2) con.push_char ?< con.push_char ?< when ?!; if src.cur_chars_are '