Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CentralNic
parsedown
Commits
85ad014f
Commit
85ad014f
authored
Dec 06, 2013
by
Emanuil Rusev
Browse files
parse code span after recursive types to resolve #44
parent
22336a1b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Parsedown.php
View file @
85ad014f
...
...
@@ -629,38 +629,7 @@ class Parsedown
$index
=
0
;
# code span
if
(
strpos
(
$text
,
'`'
)
!==
FALSE
and
preg_match_all
(
'/`(.+?)`/'
,
$text
,
$matches
,
PREG_SET_ORDER
))
{
foreach
(
$matches
as
$matches
)
{
$element_text
=
$matches
[
1
];
$element_text
=
htmlspecialchars
(
$element_text
,
ENT_NOQUOTES
,
'UTF-8'
);
# decodes escape sequences
$this
->
escape_sequence_map
and
strpos
(
$element_text
,
"
\x1A
"
)
!==
FALSE
and
$element_text
=
strtr
(
$element_text
,
$this
->
escape_sequence_map
);
# composes element
$element
=
'<code>'
.
$element_text
.
'</code>'
;
# encodes element
$code
=
"
\x1A
"
.
'$'
.
$index
;
$text
=
str_replace
(
$matches
[
0
],
$code
,
$text
);
$map
[
$code
]
=
$element
;
$index
++
;
}
}
# inline link or image
# inline link or image (recursive)
if
(
strpos
(
$text
,
']('
)
!==
FALSE
and
preg_match_all
(
'/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/'
,
$text
,
$matches
,
PREG_SET_ORDER
))
# inline
{
...
...
@@ -693,7 +662,7 @@ class Parsedown
}
}
# reference link or image
# reference link or image
(recursive)
if
(
$this
->
reference_map
and
strpos
(
$text
,
'['
)
!==
FALSE
and
preg_match_all
(
'/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms'
,
$text
,
$matches
,
PREG_SET_ORDER
))
{
...
...
@@ -735,6 +704,37 @@ class Parsedown
}
}
# code span
if
(
strpos
(
$text
,
'`'
)
!==
FALSE
and
preg_match_all
(
'/`(.+?)`/'
,
$text
,
$matches
,
PREG_SET_ORDER
))
{
foreach
(
$matches
as
$matches
)
{
$element_text
=
$matches
[
1
];
$element_text
=
htmlspecialchars
(
$element_text
,
ENT_NOQUOTES
,
'UTF-8'
);
# decodes escape sequences
$this
->
escape_sequence_map
and
strpos
(
$element_text
,
"
\x1A
"
)
!==
FALSE
and
$element_text
=
strtr
(
$element_text
,
$this
->
escape_sequence_map
);
# composes element
$element
=
'<code>'
.
$element_text
.
'</code>'
;
# encodes element
$code
=
"
\x1A
"
.
'$'
.
$index
;
$text
=
str_replace
(
$matches
[
0
],
$code
,
$text
);
$map
[
$code
]
=
$element
;
$index
++
;
}
}
# automatic link
if
(
strpos
(
$text
,
'://'
)
!==
FALSE
)
...
...
tests/data/inline_link.html
View file @
85ad014f
<p><a
href=
"http://example.com"
>
link
</a></p>
<p><a
href=
"http://example.com"
><code>
link
</code></a></p>
<p><a
href=
"http://example.com"
><img
alt=
"MD Logo"
src=
"http://parsedown.org/md.png"
></a></p>
\ No newline at end of file
tests/data/inline_link.md
View file @
85ad014f
[
link
](
http://example.com
)
[
`link`
](
http://example.com
)
[

](http://example.com)
\ No newline at end of file
tests/data/text_reference.html
View file @
85ad014f
...
...
@@ -3,4 +3,5 @@
<p>
[one][404] with no definition
</p>
<p><a
href=
"http://example.com"
>
multiline
one
</a>
defined on 2 lines
</p>
<p><a
href=
"http://example.com"
>
one
</a>
with an upper case label
</p>
\ No newline at end of file
<p><a
href=
"http://example.com"
>
one
</a>
with an upper case label
</p>
<p><a
href=
"http://example.com"
><code>
link
</code></a></p>
\ No newline at end of file
tests/data/text_reference.md
View file @
85ad014f
...
...
@@ -13,4 +13,6 @@ one][website] defined on 2 lines
[
one
][
label
]
with an upper case label
[
LABEL
]:
http://example.com
\ No newline at end of file
[
LABEL
]:
http://example.com
[
`link`
][
website
]
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment