--- jien_parser.rb.orig Wed Sep 8 17:53:29 2004 +++ jien_parser.rb Wed Sep 8 17:56:47 2004 @@ -71,15 +71,18 @@ s.each do |line| case line when /^(\!{1,5})(.+)$/ + @preword = ' ' print $1 @cur_stack.push( {:e => :heading_open, :lv => $1.size} ) inline( $2 ) @cur_stack.push( {:e => :heading_close, :lv => $1.size} ) puts when /^----/ + @preword = ' ' puts $& @cur_stack.push( {:e => :horizontal_rule} ) when /^(\*{1,3})(.+)$/ + @preword = ' ' print $1 @cur_stack.push( {:e => :unordered_list, :lv => $1.size} ) @cur_stack.push( {:e => :listitem_open} ) @@ -87,6 +90,7 @@ @cur_stack.push( {:e => :listitem_close} ) puts when /^(\#{1,3})(.+)$/ + @preword = ' ' print $1 @cur_stack.push( {:e => :ordered_list, :lv => $1.size} ) @cur_stack.push( {:e => :listitem_open} ) @@ -94,11 +98,13 @@ @cur_stack.push( {:e => :listitem_close} ) puts when /^""(.*)$/ + @preword = ' ' if @stack.empty? || @stack.last.empty? || @stack.last.last[:e] != :blockquote || @stack.last.last[:s] == '' s = $1 print '""' puts norm(s) @cur_stack.push( {:e => :blockquote, :s => s} ) when /^:(.+)$/ + @preword = ' ' print ':' @cur_stack.push( {:e => :definition_list} ) @cur_stack.push( {:e => :definition_term_open} ) @@ -120,14 +126,17 @@ @cur_stack.push( {:e => :definition_desc_close} ) puts when /^$/ + @preword = ' ' puts @cur_stack.push( {:e => :empty} ) when /^\s(.*)/m + @preword = ' ' s = $1 print ' ' puts norm(s) @cur_stack.push( {:e => :pre, :s => s} ) when /^#{TABLE}/ + @preword = ' ' @cur_stack.push( {:e => :table} ) @cur_stack.push( {:e => :table_row_open} ) $1.split( /\|\|/ ).each do |s| @@ -139,11 +148,11 @@ @cur_stack.push( {:e => :table_row_close} ) puts else + @preword = ' ' inline( line ) end @stack << normalize_line( @cur_stack ).dup @cur_stack.clear - @preword = ' ' end normalize( @stack.flatten ) end @@ -190,7 +199,6 @@ when REF_RE str = $' matched = $1 - print "[[#{matched}]]" if /\A(?:(.+)\|)?(.+)\z/ =~ matched s = $1 href = $2 @@ -208,8 +216,19 @@ end h[:s] = s || href unless h.key?(:s) @cur_stack.push( h ) + /^(.)/ =~ h[:s] + word = $1 + if word != ' ' && ![' ','、','。'].include?(@preword) && + word.size != @preword.size + print ' ' + end + print "[[#{matched}]]" + /(.)$/ =~ h[:s] + @preword = $1 + else + print "[[#{matched}]]" + @preword = ' ' end - @preword = ' ' when URL_RE href = $& str = $' @@ -417,19 +436,29 @@ def norm(s) ret = '' s.scan(/./m) do |word| - if ![' ',"\n"].include?(word) && - ![' ','、','。'].include?(@preword) && - word.size != @preword.size - ret<<' ' - end + if word == "\n" then ret< 1 case word - when ',' - word = '、' - when '.' - word = '。' + when ','; word = '、' + when '.'; word = '。' + when '('; word = '(' + when ')'; word = ')' + when '0'; word = '0' + when '1'; word = '1' + when '2'; word = '2' + when '3'; word = '3' + when '4'; word = '4' + when '5'; word = '5' + when '6'; word = '6' + when '7'; word = '7' + when '8'; word = '8' + when '9'; word = '9' end end + if word != ' ' && ![' ','、','。'].include?(@preword) && + word.size != @preword.size + ret<<' ' + end ret<