You are here: Home > Latest news from Darcs > Imports changes from Mediacloth revisions r130-131

Revision 20080618153059-9043f-69d29b...

Imports changes from Mediacloth revisions r130-131

Added support for a markup edge cases, like an empty nowiki. Also changed to always pick up attributes for nowiki, math, and pre.

vendor/mediacloth-trunk/lib/mediacloth/mediawikilexer.rb
vendor/mediacloth-trunk/test/lexer.rb

Changes to mediawikilexer.rb

296
        if ((c = scanner.get_byte) == '>' or (c == '/' and scanner.get_byte == '>'))
        if ((c = scanner.get_byte) == '>' or (c == '/' and scanner.get_byte == '>'))
296
297
          # Found an XHTML start or empty tag
          # Found an XHTML start or empty tag
297
298
          if tag_name == 'nowiki'
          if tag_name == 'nowiki'
298
299
            @lexer_table.push(@nowiki_lexer_table)
            @lexer_table.push(@nowiki_lexer_table) unless c == '/'
299
300
          elsif tag_name == 'math'
 
301
            @lexer_table.push(@math_lexer_table)
 
302
            start_span(:TAG, tag_name)
 
303
          elsif tag_name == 'pre'
 
304
            @lexer_table.push(@pre_lexer_table)
 
305
            start_span(:TAG, tag_name)
 
306
          else
          else
300
 
            if tag_name == 'pre'
301
 
              table = @pre_lexer_table
302
 
            elsif tag_name == 'math'
303
 
              table = @math_lexer_table
304
 
            else
305
 
              table = @markup_lexer_table
306
 
            end
307
307
            start_span(:TAG, tag_name)
            start_span(:TAG, tag_name)
308
308
            attrs.collect do
            attrs.collect do |(name, value)| 
309
309
              |(name, value)| 
 
310
              append_to_tokens([:ATTR_NAME, name])
              append_to_tokens([:ATTR_NAME, name])
310
311
              append_to_tokens([:ATTR_VALUE, value]) if value
              append_to_tokens([:ATTR_VALUE, value]) if value
311
312
            end
            end
312
313
            if c == '/'
            if c == '/'
313
314
              end_span(:TAG, tag_name)
              end_span(:TAG, tag_name)
314
315
            else
            else
315
316
              @lexer_table.push(@markup_lexer_table)
              @lexer_table.push(table)
316
317
            end
            end
317
318
          end
          end
318
319
          @cursor += scanner.pos
          @cursor += scanner.pos
319
247 more lines
567
  end
  end
567
568
    
    
568
569
  def match_left_angle_in_pre
  def match_left_angle_in_pre
569
570
    if @text[@cursor, 7] == '</pre>'
    if @text[@cursor, 6] == '</pre>'
570
571
      end_span(:TAG, 'pre')
      end_span(:TAG, 'pre')
571
572
      @cursor += 7
      @cursor += 6
572
573
      @lexer_table.pop
      @lexer_table.pop
573
574
    else
    else
574
575
      match_text
      match_text
575

Changes to lexer.rb

335
      lex("text<nowiki>''italic''</nowiki>text"))
      lex("text<nowiki>''italic''</nowiki>text"))
335
336
    assert_equal([[:PARA_START, ""], [:TEXT, "<u>uuu</u>"], [:PARA_END, ""], [false, false]],
    assert_equal([[:PARA_START, ""], [:TEXT, "<u>uuu</u>"], [:PARA_END, ""], [false, false]],
336
337
      lex("<nowiki><u>uuu</u></nowiki>"))
      lex("<nowiki><u>uuu</u></nowiki>"))
337
 
    assert_equal([[:PARA_START, ""], [:TEXT, "texttext"], [:PARA_END, ""], [false, false]],
338
 
      lex("text<nowiki/>text"))
339
338
  end
  end
340
339
  
  
341
340
  def test_math
  def test_math
342
341
    assert_equal([[:PARA_START, ""], [:TAG_START, "math"], [:TEXT, "1 == 1 == 1"], [:TAG_END, "math"],
    assert_equal([[:PARA_START, ""], [:TAG_START, "math"], [:TEXT, "1 == 1 == 1"], [:TAG_END, "math"],
343
342
        [:PARA_END, ""], [false, false]],
        [:PARA_END, ""], [false, false]],
344
343
      lex("<math>1 == 1 == 1</math>"))
      lex("<math>1 == 1 == 1</math>"))
345
 
    assert_equal([[:PARA_START, ""], [:TAG_START, "math"], [:TEXT, "1 == 1"], [:TAG_END, "math"],
346
 
        [:TEXT, "xxx"], [:TAG_START, "math"], [:TEXT, "1 == 1"], [:TAG_END, "math"],
347
 
        [:PARA_END, ""], [false, false]],
348
 
      lex("<math>1 == 1</math>xxx<math>1 == 1</math>"))
349
 
    assert_equal([[:PARA_START, ""], [:TAG_START, "math"], [:TAG_END, "math"], [:PARA_END, ""], [false, false]],
350
 
      lex("<math/>"))
351
344
  end
  end
352
345
  
  
353
346
  def test_pre
  def test_pre
354
347
    assert_equal([[:PARA_START, ""], [:TAG_START, "pre"], [:TEXT, "1 == 1 == 1"], [:TAG_END, "pre"],
    assert_equal([[:PARA_START, ""], [:TAG_START, "pre"], [:ATTR_NAME, "name"], [:ATTR_VALUE, "code"],
355
348
        [:PARA_END, ""], [false, false]],
        [:TEXT, "1 == 1 == 1"], [:TAG_END, "pre"], [:PARA_END, ""], [false, false]],
356
349
      lex("<pre>1 == 1 == 1</pre>"))
      lex("<pre name='code'>1 == 1 == 1</pre>"))
357
 
    assert_equal([[:PARA_START, ""], [:TAG_START, "pre"], [:TAG_END, "pre"], [:PARA_END, ""], [false, false]],
358
 
      lex("<pre/>"))
359
 
    assert_equal([[:PARA_START, ""], [:TAG_START, "pre"], [:TEXT, "1 == 1"], [:TAG_END, "pre"], [:TEXT, "\nxxx\n"],
360
 
        [:TAG_START, "pre"], [:TEXT, "1 == 1"], [:TAG_END, "pre"], [:PARA_END, ""], [false, false]],
361
 
      lex("<pre>1 == 1</pre>\nxxx\n<pre>1 == 1</pre>"))
362
350
  end
  end
363
351
  
  
364
352
  def test_variable
  def test_variable
365