Skip to content

Commit

Permalink
Better tests, merged gamut properties on the parser (inherited from t…
Browse files Browse the repository at this point in the history
…he extended extra parser)
  • Loading branch information
Alexandre committed Feb 7, 2011
1 parent f0beb76 commit 42a1bf3
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 49 deletions.
83 changes: 34 additions & 49 deletions markdown.php
Expand Up @@ -81,7 +81,7 @@ class ElephantMarkdown {
protected $nested_url_parenthesis_re;

# Table of hash values for escaped characters:
protected $escape_chars = '\`*_{}[]()>#+-.!';
protected $escape_chars = '\`*_{}[]()>#+-.!:|';
protected $escape_chars_re;

# Change to ">" for HTML output.
Expand All @@ -104,9 +104,6 @@ public function __construct() {
#
# Constructor function. Initialize the parser object.
#
# Add extra escapable characters before parent constructor
# initialize the table.
$this->escape_chars .= ':|';

if ($this->el_local_domain === null) {
if (isset($_SERVER['SERVER_NAME'])) {
Expand All @@ -116,24 +113,6 @@ public function __construct() {
}
}

# Insert extra document, block, and span transformations.
# Parent constructor will do the sorting.
$this->document_gamut += array(
"doFencedCodeBlocks" => 5,
"stripFootnotes" => 15,
"stripAbbreviations" => 25,
"appendFootnotes" => 50,
);
$this->block_gamut += array(
"doFencedCodeBlocks" => 5,
"doTables" => 15,
"doDefLists" => 45,
);
$this->span_gamut += array(
"doFootnotes" => 5,
"doAbbreviations" => 70,
);

$this->prepareItalicsAndBold();

$this->nested_brackets_re =
Expand Down Expand Up @@ -205,10 +184,12 @@ public function transform($text) {
}

protected $document_gamut = array(
# Strip link definitions, store in hashes.
"stripLinkDefinitions" => 20,

"runBasicBlockGamut" => 30,
"doFencedCodeBlocks" => 5,
"stripFootnotes" => 15,
"stripLinkDefinitions" => 20,
"stripAbbreviations" => 25,
"runBasicBlockGamut" => 30,
"appendFootnotes" => 50
);


Expand Down Expand Up @@ -291,12 +272,14 @@ public function hashBlock($text) {
# These are all the transformations that form block-level
# tags like paragraphs, headers, and list items.
#
"doHeaders" => 10,
"doHorizontalRules" => 20,

"doLists" => 40,
"doCodeBlocks" => 50,
"doBlockQuotes" => 60,
"doFencedCodeBlocks" => 5,
"doHeaders" => 10,
"doTables" => 15,
"doHorizontalRules" => 20,
"doLists" => 40,
"doDefLists" => 45,
"doCodeBlocks" => 50,
"doBlockQuotes" => 60,
);

public function runBlockGamut($text) {
Expand Down Expand Up @@ -353,23 +336,25 @@ public function doHorizontalRules($text) {
# These are all the transformations that occur *within* block-level
# tags like paragraphs, headers, and list items.
#
# Process character escapes, code spans, and inline HTML
# in one shot.
"parseSpan" => -30,

# Process anchor and image tags. Images must come first,
# because ![foo][f] looks like an anchor.
"doImages" => 10,
"doAnchors" => 20,

# Make links out of things like `<http://example.com/>`
# Must come after doAnchors, because you can use < and >
# delimiters in inline links like [this](<url>).
"doAutoLinks" => 30,
"encodeAmpsAndAngles" => 40,

"doItalicsAndBold" => 50,
"doHardBreaks" => 60,
# Process character escapes, code spans, and inline HTML
# in one shot.
"parseSpan" => -30,
"doFootnotes" => 5,

# Process anchor and image tags. Images must come first,
# because ![foo][f] looks like an anchor.
"doImages" => 10,
"doAnchors" => 20,

# Make links out of things like `<http://example.com/>`
# Must come after doAnchors, because you can use < and >
# delimiters in inline links like [this](<url>).
"doAutoLinks" => 30,
"encodeAmpsAndAngles" => 40,

"doItalicsAndBold" => 50,
"doHardBreaks" => 60,
"doAbbreviations" => 70,
);

public function runSpanGamut($text) {
Expand Down
109 changes: 109 additions & 0 deletions tests/markdowntest.php
Expand Up @@ -27,4 +27,113 @@ public function testH2Setext()
));
}

public function testH1Atx()
{
$this->assertEquals(
"<h1>Teste Atx</h1>\n", Markdown("# Teste Atx")
);
$this->assertEquals(
"<h1>Teste Atx</h1>\n", Markdown("# Teste Atx #")
);
}

public function testH2Atx()
{
$this->assertEquals(
"<h2>Outro Teste</h2>\n", Markdown("## Outro Teste")
);
$this->assertEquals(
"<h2>Outro Teste</h2>\n", Markdown("## Outro Teste ##")
);
}

public function testH3Atx()
{
$this->assertEquals(
"<h3>Outro Teste</h3>\n", Markdown("### Outro Teste")
);
$this->assertEquals(
"<h3>Outro Teste</h3>\n", Markdown("### Outro Teste ###")
);
}

public function testH4Atx()
{
$this->assertEquals(
"<h4>Outro Teste</h4>\n", Markdown("#### Outro Teste")
);
$this->assertEquals(
"<h4>Outro Teste</h4>\n", Markdown("#### Outro Teste ####")
);
}

public function testH5Atx()
{
$this->assertEquals(
"<h5>Outro Teste</h5>\n", Markdown("##### Outro Teste")
);
$this->assertEquals(
"<h5>Outro Teste</h5>\n", Markdown("##### Outro Teste #####")
);
}

public function testH6Atx()
{
$this->assertEquals(
"<h6>Outro Teste</h6>\n", Markdown("###### Outro Teste")
);
$this->assertEquals(
"<h6>Outro Teste</h6>\n", Markdown("###### Outro Teste ######")
);
}

public function testHAtxCloseMismatch()
{
$this->assertEquals(
"<h6>Outro Teste</h6>\n", Markdown("###### Outro Teste ##")
);
}

public function testSimpleBlockquotes()
{
$this->assertEquals(<<<HTML
<blockquote>
<p>This
is
awesome</p>
</blockquote>
HTML
,
Markdown(
<<<MD
>This
>is
>awesome
MD
));
}

public function testLazyBlockquotes()
{
$this->assertEquals(<<<HTML
<blockquote>
<p>This is very awesome
lazy paragraphs</p>
<p>These too</p>
</blockquote>
HTML
,
Markdown(
<<<MD
>This is very awesome
lazy paragraphs
>These too
MD
));
}

}

0 comments on commit 42a1bf3

Please sign in to comment.