Skip to content

Commit f70d23c

Browse files
committed
parsedown 1.2
1 parent d8f2bb2 commit f70d23c

File tree

4 files changed

+38
-70
lines changed

4 files changed

+38
-70
lines changed

ParsedownExtra.php

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function __construct()
2828
array_unshift($this->DefinitionTypes['['], 'Footnote');
2929

3030
# identify footnote markers before before links
31-
array_unshift($this->SpanTypes['['], 'FootnoteMarker');
31+
array_unshift($this->InlineTypes['['], 'FootnoteMarker');
3232
}
3333

3434
#
@@ -61,9 +61,9 @@ function text($text)
6161
#
6262
# Atx
6363

64-
protected function identifyAtx($Line)
64+
protected function blockHeader($Line)
6565
{
66-
$Block = parent::identifyAtx($Line);
66+
$Block = parent::blockHeader($Line);
6767

6868
if (preg_match('/[ #]*'.$this->attributesPattern.'[ ]*$/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE))
6969
{
@@ -80,7 +80,7 @@ protected function identifyAtx($Line)
8080
#
8181
# Definition List
8282

83-
protected function identifyDefinitionList($Line, $Block)
83+
protected function blockDefinitionList($Line, $Block)
8484
{
8585
if (isset($Block['type']))
8686
{
@@ -115,7 +115,7 @@ protected function identifyDefinitionList($Line, $Block)
115115
return $Block;
116116
}
117117

118-
protected function addToDefinitionList($Line, array $Block)
118+
protected function blockDefinitionListContinue($Line, array $Block)
119119
{
120120
if ($Line['text'][0] === ':')
121121
{
@@ -143,9 +143,9 @@ protected function addToDefinitionList($Line, array $Block)
143143
#
144144
# Setext
145145

146-
protected function identifySetext($Line, array $Block = null)
146+
protected function blockSetextHeader($Line, array $Block = null)
147147
{
148-
$Block = parent::identifySetext($Line, $Block);
148+
$Block = parent::blockSetextHeader($Line, $Block);
149149

150150
if (preg_match('/[ ]*'.$this->attributesPattern.'[ ]*$/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE))
151151
{
@@ -162,64 +162,16 @@ protected function identifySetext($Line, array $Block = null)
162162
#
163163
# Markup
164164

165-
protected function completeMarkup($Block)
165+
protected function blockMarkupComplete($Block)
166166
{
167-
$DOMDocument = new DOMDocument;
168-
169-
$DOMDocument->loadXML($Block['element'], LIBXML_NOERROR | LIBXML_NOWARNING);
170-
171-
if ($DOMDocument->documentElement === null)
172-
{
173-
return $Block;
174-
}
175-
176-
$result = $DOMDocument->documentElement->getAttribute('markdown');
177-
178-
if ($result !== '1')
167+
if ( ! isset($Block['element']['attributes']['markdown']) or $Block['element']['attributes']['markdown'] !== '1')
179168
{
180169
return $Block;
181170
}
182171

183-
$DOMDocument->documentElement->removeAttribute('markdown');
184-
185-
$index = 0;
186-
$nestedElements = array();
187-
188-
$markdown = '';
189-
190-
foreach ($DOMDocument->documentElement->childNodes as $Node)
191-
{
192-
if ($Node instanceof DOMText)
193-
{
194-
$markdown .= $Node->nodeValue;
195-
}
196-
elseif ($Node instanceof DOMNode)
197-
{
198-
$nestedElements []= $DOMDocument->saveXML($Node);
199-
200-
# replace nested elements with placeholders
201-
$markdown .= '\x1A'.$index ++.'/';
202-
}
203-
else
204-
{
205-
continue;
206-
}
207-
}
208-
209-
foreach ($nestedElements as $index => $nestedElement)
210-
{
211-
$markdown = str_replace('\x1A'.$index.'/', $nestedElement, $markdown);
212-
}
213-
214-
$text = $this->text($markdown);
215-
216-
# because we don't want markup to get encoded
217-
$DOMDocument->documentElement->nodeValue = "\n".'placeholder'."\n";
218-
219-
$markup = $DOMDocument->saveXML($DOMDocument->documentElement);
220-
$markup = str_replace('placeholder', $text, $markup);
172+
unset($Block['element']['attributes']['markdown']);
221173

222-
$Block['element'] = $markup;
174+
$Block['element']['text'] = "\n".$this->text($Block['element']['text'])."\n";
223175

224176
return $Block;
225177
}
@@ -231,7 +183,7 @@ protected function completeMarkup($Block)
231183
#
232184
# Abbreviation
233185

234-
protected function identifyAbbreviation($Line)
186+
protected function definitionAbbreviation($Line)
235187
{
236188
if (preg_match('/^\*\[(.+?)\]:[ ]*(.+?)[ ]*$/', $Line['text'], $matches))
237189
{
@@ -247,7 +199,7 @@ protected function identifyAbbreviation($Line)
247199
#
248200
# Footnote
249201

250-
protected function identifyFootnote($Line)
202+
protected function definitionFootnote($Line)
251203
{
252204
if (preg_match('/^\[\^(.+?)\]:[ ]?(.+)$/', $Line['text'], $matches))
253205
{
@@ -265,15 +217,15 @@ protected function identifyFootnote($Line)
265217
}
266218

267219
#
268-
# Spans
220+
# Inline Elements
269221
#
270222

271223
#
272224
# Footnote Marker
273225

274-
protected function identifyFootnoteMarker($Excerpt)
226+
protected function inlineFootnoteMarker($excerpt)
275227
{
276-
if (preg_match('/^\[\^(.+?)\]/', $Excerpt['text'], $matches))
228+
if (preg_match('/^\[\^(.+?)\]/', $excerpt, $matches))
277229
{
278230
$name = $matches[1];
279231

@@ -312,11 +264,11 @@ protected function identifyFootnoteMarker($Excerpt)
312264
#
313265
# Link
314266

315-
protected function identifyLink($Excerpt)
267+
protected function inlineLink($excerpt)
316268
{
317-
$Span = parent::identifyLink($Excerpt);
269+
$Span = parent::inlineLink($excerpt);
318270

319-
$remainder = substr($Excerpt['text'], $Span['extent']);
271+
$remainder = substr($excerpt, $Span['extent']);
320272

321273
if (preg_match('/^[ ]*'.$this->attributesPattern.'/', $remainder, $matches))
322274
{
@@ -331,9 +283,9 @@ protected function identifyLink($Excerpt)
331283
#
332284
# ~
333285

334-
protected function readPlainText($text)
286+
protected function unmarkedText($text)
335287
{
336-
$text = parent::readPlainText($text);
288+
$text = parent::unmarkedText($text);
337289

338290
if (isset($this->Definitions['Abbreviation']))
339291
{

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"erusev/parsedown": "~1.1"
16+
"erusev/parsedown": "~1.2"
1717
},
1818
"autoload": {
1919
"psr-0": {"ParsedownExtra": ""}

test/data/markdown_inside_markup.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@
44
<div>
55
This is block-level markup. No *markdown* here.
66
</div>
7+
</div>
8+
<hr />
9+
<div>
10+
<p><em>markdown</em></p>
11+
<div>
12+
<p><em>markdown</em></p>
13+
</div>
714
</div>

test/data/markdown_inside_markup.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ This is another paragraph. It contains <em>inline markup</em>.
66
<div>
77
This is block-level markup. No *markdown* here.
88
</div>
9+
</div>
10+
11+
---
12+
13+
<div markdown="1">
14+
*markdown*
15+
<div markdown="1">
16+
_markdown_
17+
</div>
918
</div>

0 commit comments

Comments
 (0)