Imports changes from Mediacloth revision r125
This change do Mediacloth avoids generating an empty paragraph after each heading
| 117 | def parse_section(ast) | def parse_section(ast) | 117 |
|---|---|---|---|
| 118 | generator = TextGenerator.new | generator = TextGenerator.new | 118 |
| 119 | anchor = MediaWikiHTMLGenerator.anchor_for(generator.parse(ast).join(' ')) | anchor = MediaWikiHTMLGenerator.anchor_for(generator.parse(ast).join(' ')) | 119 |
| 120 | "<h#{ast.level}><a name='#{anchor}'></a>" + super(ast) + "</h#{ast.level}>" | "<h#{ast.level}><a name='#{anchor}'></a>" + super(ast) + "</h#{ast.level}>\n" | 120 |
| 121 | end | end | 121 |
| 122 | 122 | ||
| 123 | def parse_internal_link(ast) | def parse_internal_link(ast) | 123 |
| 335 | if @heading.length <= heading.length | if @heading.length <= heading.length | 335 |
|---|---|---|---|
| 336 | end_span(:SECTION, heading) | end_span(:SECTION, heading) | 336 |
| 337 | @lexer_table.pop | @lexer_table.pop | 337 |
if @text[@cursor, 2] == "\r\n" | 338 | ||
@cursor += 2 | 339 | ||
elsif @text[@cursor, 1] == "\n" | 340 | ||
@cursor += 1 | 341 | ||
end | 342 | ||
| 338 | else | else | 343 |
| 339 | @pending << heading | @pending << heading | 344 |
| 340 | end | end | 345 |
| 10 | 10 | ||
|---|---|---|---|
| 11 | </p><p>We can have headlines: | </p><p>We can have headlines: | 11 |
| 12 | 12 | ||
| 13 | </p><h1><a name='Headline1'></a> Headline1 </h1><h2><a name='Headline2'></a> Headline2 </h2><h3><a name='Headline3'></a> Headline3 </h3><h4><a name='Headline4'></a> Headline4 </h4><h5><a name='Headline5'></a> Headline5 </h5><h6><a name='Headline6'></a> Headline6 </h6><h7><a name='Headline7'></a> Headline7 </h7><p><br /> | </p><h1><a name='Headline1'></a> Headline1 </h1> | 13 |
| 14 | <h2><a name='Headline2'></a> Headline2 </h2> | 14 | |
| 15 | </p><p>Headlines may have formatting: | <h3><a name='Headline3'></a> Headline3 </h3> | 15 |
| 16 | <h4><a name='Headline4'></a> Headline4 </h4> | 16 | |
| 17 | </p><h1><a name='See_for_more_info'></a> See <a href="javascript:void(0)">Internal Link</a> for more info </h1><h2><a name='This_is_an_important_heading'></a> This is an <b>important</b> heading </h2><p><br /> | <h5><a name='Headline5'></a> Headline5 </h5> | 17 |
| 18 | <h6><a name='Headline6'></a> Headline6 </h6> | 18 | |
| 19 | </p><pre> This is a preformatted <b> </b> << <i> </i> text | <h7><a name='Headline7'></a> Headline7 </h7> | 19 |
<p> | 20 | ||
Headlines may have formatting: | 21 | ||
| 22 | |||
</p><h1><a name='See_for_more_info'></a> See <a href="javascript:void(0)">Internal Link</a> for more info </h1> | 23 | ||
<h2><a name='This_is_an_important_heading'></a> This is an <b>important</b> heading </h2> | 24 | ||
<pre> This is a preformatted <b> </b> << <i> </i> text | 25 | ||
| 20 | yes | yes | 26 |
| 21 | </pre><hr></hr><p> | </pre><hr></hr><p> | 27 |
| 22 | This is a text after the line. | This is a text after the line. | 28 |
| 23 | 29 | ||
| 24 | </p><ul><li>foo | </p><ul><li>foo | 30 |
| 25 | </li><li> foo2 | </li><li> foo2 | 31 |
| 26 | </li></ul><h2><a name='There_aren_t_any_closing_quotes_inside_this_headline_s_name'></a> There aren't any closing quotes inside this headline's name </h2> | </li></ul><h2><a name='There_aren_t_any_closing_quotes_inside_this_headline_s_name'></a> There aren't any closing quotes inside this headline's name </h2> | 32 |
| 1 | <h2><a name='Examples_of_XHTML_markup_and_escaping_of_XML_characters'></a>Examples of XHTML markup and escaping of XML characters</h2><p><br /> | <h2><a name='Examples_of_XHTML_markup_and_escaping_of_XML_characters'></a>Examples of XHTML markup and escaping of XML characters</h2> | 1 |
|---|---|---|---|
| 2 | <p> | 2 | |
| 3 | </p><p>Here is a <tt>code sample</tt>. | Here is a <tt>code sample</tt>. | 3 |
| 4 | 4 | ||
| 5 | </p><p>Another <tt class="code">code sample</tt>. | </p><p>Another <tt class="code">code sample</tt>. | 5 |
| 6 | 6 |
| 8 | </ul><li>2.2 <a href='#Sub_Headline_2b'> Sub Headline 2b </a></li> | </ul><li>2.2 <a href='#Sub_Headline_2b'> Sub Headline 2b </a></li> | 8 |
|---|---|---|---|
| 9 | </ul></ul><p><br /> | </ul></ul><p><br /> | 9 |
| 10 | 10 | ||
| 11 | </p><h1><a name='Headline1'></a> Headline1 </h1><h2><a name='Sub_Headline_1a'></a> Sub Headline 1a </h2><h2><a name='Sub_Headline_1b'></a> Sub Headline 1b </h2><h1><a name='Headline2'></a> Headline2 </h1><h2><a name='Sub_Headline_2a'></a> Sub Headline 2a </h2><h3><a name='Sub_Sub_Headline_2i'></a> Sub Sub Headline <i>2i</i> </h3><h3><a name='Sub_Sub_Headline_2ii'></a> Sub Sub Headline <b>2ii</b> </h3><h2><a name='Sub_Headline_2b'></a> Sub Headline 2b </h2> | </p><h1><a name='Headline1'></a> Headline1 </h1> | 11 |
<h2><a name='Sub_Headline_1a'></a> Sub Headline 1a </h2> | 12 | ||
<h2><a name='Sub_Headline_1b'></a> Sub Headline 1b </h2> | 13 | ||
<h1><a name='Headline2'></a> Headline2 </h1> | 14 | ||
<h2><a name='Sub_Headline_2a'></a> Sub Headline 2a </h2> | 15 | ||
<h3><a name='Sub_Sub_Headline_2i'></a> Sub Sub Headline <i>2i</i> </h3> | 16 | ||
<h3><a name='Sub_Sub_Headline_2ii'></a> Sub Sub Headline <b>2ii</b> </h3> | 17 | ||
<h2><a name='Sub_Headline_2b'></a> Sub Headline 2b </h2> | 18 |
| 25 | Test unclosed bold and italic formatting: | Test unclosed bold and italic formatting: | 25 |
|---|---|---|---|
| 26 | 26 | ||
| 27 | </p><p><i>Some italic and now </i>bold | </p><p><i>Some italic and now </i>bold | 27 |
| 28 | </p><h2><a name='Heading'></a>Heading</h2><p> | </p><h2><a name='Heading'></a>Heading</h2> | 28 |
| 29 | Text | <p>Text | 29 |
| 30 | 30 | ||
| 31 | </p><p><i>Some italic and now <b>bold | </p><p><i>Some italic and now <b>bold | 31 |
| 32 | </b></i></p><h2><a name='Heading'></a>Heading</h2><p> | </b></i></p><h2><a name='Heading'></a>Heading</h2> | 32 |
<p> | 33 | ||
| 33 | Text | Text | 34 |
| 34 | 35 | ||
| 35 | </p><p><i>Some italic and now <b>bold | </p><p><i>Some italic and now <b>bold | 36 |
| 36 | 37 | ||
| 37 | </b></i></p><h2><a name='Heading'></a>Heading</h2><p> | </b></i></p><h2><a name='Heading'></a>Heading</h2> | 38 |
| 38 | Text | <p><br /> | 39 |
| 40 | |||
</p><p>Text | 41 | ||
| 39 | 42 | ||
| 40 | </p><p><i>Some italic and now <b>bold | </p><p><i>Some italic and now <b>bold | 43 |
| 41 | </b></i></p><ul><li> one | </b></i></p><ul><li> one | 44 |
| 1 | <h3><a name='foo'></a> foo </h3> | <h3><a name='foo'></a> foo </h3> | 1 |
|---|
| 11 | 11 | ||
|---|---|---|---|
| 12 | </p><p>Text escaped in a heading: | </p><p>Text escaped in a heading: | 12 |
| 13 | 13 | ||
| 14 | </p><h2><a name='Heading_with____'></a>Heading with '''</h2> | </p><h2><a name='Heading_with____'></a>Heading with '''</h2> | 14 |
| 31 | 31 | ||
|---|---|---|---|
| 32 | ''Some italic and now '''bold | ''Some italic and now '''bold | 32 |
| 33 | ==Heading== | ==Heading== | 33 |
| 34 | |||
| 34 | Text | Text | 35 |
| 35 | 36 | ||
| 36 | 37 | ||
| 37 | ''Some italic and now '''bold | ''Some italic and now '''bold | 38 |
| 38 | 39 | ||
| 39 | ==Heading== | ==Heading== | 40 |
| 41 | |||
| 42 | |||
| 40 | Text | Text | 43 |
| 41 | 44 | ||
| 42 | 45 |
| 11 | PARA_ENDPARA_STARTTEXTWe can have headlines: | PARA_ENDPARA_STARTTEXTWe can have headlines: | 11 |
|---|---|---|---|
| 12 | 12 | ||
| 13 | PARA_ENDSECTION_START=TEXT Headline1 SECTION_END=SECTION_START==TEXT Headline2 SECTION_END==SECTION_START===TEXT Headline3 SECTION_END===SECTION_START====TEXT Headline4 SECTION_END====SECTION_START=====TEXT Headline5 SECTION_END=====SECTION_START======TEXT Headline6 SECTION_END======SECTION_START=======TEXT Headline7 SECTION_END=======PARA_STARTTEXT | PARA_ENDSECTION_START=TEXT Headline1 SECTION_END=SECTION_START==TEXT Headline2 SECTION_END==SECTION_START===TEXT Headline3 SECTION_END===SECTION_START====TEXT Headline4 SECTION_END====SECTION_START=====TEXT Headline5 SECTION_END=====SECTION_START======TEXT Headline6 SECTION_END======SECTION_START=======TEXT Headline7 SECTION_END=======PARA_STARTTEXT | 13 |
Headlines may have formatting: | 14 | ||
| 14 | 15 | ||
| 15 | PARA_ENDPARA_STARTTEXTHeadlines may have formatting: | PARA_ENDSECTION_START=TEXT See INTLINK_START[[TEXTInternal LinkINTLINK_END]]TEXT for more info SECTION_END=SECTION_START==TEXT This is an BOLD_START'''TEXTimportantBOLD_END'''TEXT heading SECTION_END==PRE_STARTTEXT This is a preformatted BOLD_START'''TEXT BOLD_END'''TEXT << ITALIC_START''TEXT ITALIC_END''TEXT text | 16 |
| 16 | |||
| 17 | PARA_ENDSECTION_START=TEXT See INTLINK_START[[TEXTInternal LinkINTLINK_END]]TEXT for more info SECTION_END=SECTION_START==TEXT This is an BOLD_START'''TEXTimportantBOLD_END'''TEXT heading SECTION_END==PARA_STARTTEXT | ||
| 18 | |||
| 19 | PARA_ENDPRE_STARTTEXT This is a preformatted BOLD_START'''TEXT BOLD_END'''TEXT << ITALIC_START''TEXT ITALIC_END''TEXT text | ||
| 20 | yes | yes | 17 |
| 21 | PRE_ENDHLINE----PARA_STARTTEXT | PRE_ENDHLINE----PARA_STARTTEXT | 18 |
| 22 | This is a text after the line. | This is a text after the line. | 19 |
| 1 | SECTION_START==TEXTExamples of XHTML markup and escaping of XML charactersSECTION_END==PARA_STARTTEXT | SECTION_START==TEXTExamples of XHTML markup and escaping of XML charactersSECTION_END==PARA_STARTTEXT | 1 |
|---|---|---|---|
| 2 | Here is a TAG_STARTttTEXTcode sampleTAG_ENDttTEXT. | 2 | |
| 3 | PARA_ENDPARA_STARTTEXTHere is a TAG_STARTttTEXTcode sampleTAG_ENDttTEXT. | ||
| 4 | 3 | ||
| 5 | PARA_ENDPARA_STARTTEXTAnother TAG_STARTttATTR_NAMEclassATTR_VALUEcodeTEXTcode sampleTAG_ENDttTEXT. | PARA_ENDPARA_STARTTEXTAnother TAG_STARTttATTR_NAMEclassATTR_VALUEcodeTEXTcode sampleTAG_ENDttTEXT. | 4 |
| 6 | 5 |
| 25 | Test unclosed bold and italic formatting: | Test unclosed bold and italic formatting: | 25 |
|---|---|---|---|
| 26 | 26 | ||
| 27 | PARA_ENDPARA_STARTITALIC_START''TEXTSome italic and now ITALIC_END''TEXTbold | PARA_ENDPARA_STARTITALIC_START''TEXTSome italic and now ITALIC_END''TEXTbold | 27 |
| 28 | PARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT | PARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXTText | 28 |
| 29 | Text | ||
| 30 | 29 | ||
| 31 | PARA_ENDPARA_STARTITALIC_START''TEXTSome italic and now BOLD_START'''TEXTbold | PARA_ENDPARA_STARTITALIC_START''TEXTSome italic and now BOLD_START'''TEXTbold | 30 |
| 32 | BOLD_ENDITALIC_ENDPARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT | BOLD_ENDITALIC_ENDPARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT | 31 |
| 2 more lines | |||
| 35 | PARA_ENDPARA_STARTITALIC_START''TEXTSome italic and now BOLD_START'''TEXTbold | PARA_ENDPARA_STARTITALIC_START''TEXTSome italic and now BOLD_START'''TEXTbold | 34 |
| 36 | 35 | ||
| 37 | BOLD_ENDITALIC_ENDPARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT | BOLD_ENDITALIC_ENDPARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT | 36 |
| 38 | Text | 37 | |
PARA_ENDPARA_STARTTEXTText | 38 | ||
| 39 | 39 | ||
| 40 | PARA_ENDPARA_STARTITALIC_START''TEXTSome italic and now BOLD_START'''TEXTbold | PARA_ENDPARA_STARTITALIC_START''TEXTSome italic and now BOLD_START'''TEXTbold | 40 |
| 41 | BOLD_ENDITALIC_ENDPARA_ENDUL_STARTLI_STARTTEXT one | BOLD_ENDITALIC_ENDPARA_ENDUL_STARTLI_STARTTEXT one | 41 |
| 63 | lex("text\r\n=heading=")) | lex("text\r\n=heading=")) | 63 |
|---|---|---|---|
| 64 | assert_equal( | assert_equal( | 64 |
| 65 | [[:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], | [[:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], | 65 |
| 66 | [:PARA_START, ""], [:TEXT, "\ntext"], [:PARA_END, ""], [false,false]], | [:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""], [false,false]], | 66 |
| 67 | lex("=heading=\ntext")) | lex("=heading=\ntext")) | 67 |
| 68 | assert_equal( | assert_equal( | 68 |
| 69 | [[:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], | [[:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], | 69 |
| 70 | [:PARA_START, ""], [:TEXT, "\r\ntext"], [:PARA_END, ""], [false,false]], | [:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""], [false,false]], | 70 |
| 71 | lex("=heading=\r\ntext")) | lex("=heading=\r\ntext")) | 71 |
| 72 | assert_equal( | assert_equal( | 72 |
| 73 | [[:PARA_START, ""], [:TEXT, "text\n\n"], [:PARA_END, ""], | [[:PARA_START, ""], [:TEXT, "text\n\n"], [:PARA_END, ""], | 73 |