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
67b51794
Commit
67b51794
authored
Nov 17, 2013
by
Emanuil Rusev
Browse files
implement fenced code block to resolve #2
parent
a9d62327
Changes
3
Hide whitespace changes
Inline
Side-by-side
Parsedown.php
View file @
67b51794
...
...
@@ -113,23 +113,50 @@ class Parsedown
#
# fenced elements
if
(
$element
[
'type'
]
===
'markup'
and
!
isset
(
$element
[
'closed'
])
)
switch
(
$element
[
'type'
])
{
if
(
preg_match
(
'{<'
.
$element
[
'subtype'
]
.
'>$}'
,
$line
))
# opening tag
{
$element
[
'depth'
]
++
;
}
case
'fenced_code_block'
:
if
(
preg_match
(
'{</'
.
$element
[
'subtype'
]
.
'>$}'
,
$line
))
# closing tag
{
$element
[
'depth'
]
>
0
?
$element
[
'depth'
]
--
:
$element
[
'closed'
]
=
true
;
}
if
(
!
isset
(
$element
[
'closed'
]))
{
if
(
preg_match
(
'/^[ ]*'
.
$element
[
'fence'
][
0
]
.
'{3,}[ ]*$/'
,
$line
))
{
$element
[
'closed'
]
=
true
;
}
else
{
$element
[
'text'
]
!==
''
and
$element
[
'text'
]
.
=
"
\n
"
;
$element
[
'text'
]
.
=
$line
;
}
continue
2
;
}
$element
[
'text'
]
.
=
"
\n
"
.
$line
;
break
;
continue
;
case
'markup'
:
if
(
!
isset
(
$element
[
'closed'
]))
{
if
(
preg_match
(
'{<'
.
$element
[
'subtype'
]
.
'>$}'
,
$line
))
# opening tag
{
$element
[
'depth'
]
++
;
}
if
(
preg_match
(
'{</'
.
$element
[
'subtype'
]
.
'>$}'
,
$line
))
# closing tag
{
$element
[
'depth'
]
>
0
?
$element
[
'depth'
]
--
:
$element
[
'closed'
]
=
true
;
}
$element
[
'text'
]
.
=
"
\n
"
.
$line
;
continue
2
;
}
break
;
}
# *
...
...
@@ -213,7 +240,7 @@ class Parsedown
# ~
if
(
$line
[
0
]
>=
'a'
or
$line
[
0
]
>=
'A'
and
$line
[
0
]
<=
'Z'
)
if
(
$line
[
0
]
>=
'a'
and
$line
[
0
]
!==
'~'
or
$line
[
0
]
>=
'A'
and
$line
[
0
]
<=
'Z'
)
{
goto
paragraph
;
}
...
...
@@ -242,7 +269,7 @@ class Parsedown
if
(
preg_match
(
'/^[ ]{4}(.*)/'
,
$line
,
$matches
))
{
if
(
$element
[
'type'
]
===
'code'
)
if
(
$element
[
'type'
]
===
'code
_block
'
)
{
if
(
isset
(
$element
[
'interrupted'
]))
{
...
...
@@ -258,7 +285,7 @@ class Parsedown
$elements
[]
=
$element
;
$element
=
array
(
'type'
=>
'code'
,
'type'
=>
'code
_block
'
,
'text'
=>
$matches
[
1
],
);
}
...
...
@@ -394,6 +421,28 @@ class Parsedown
break
;
case
'`'
:
case
'~'
:
# fenced code block
if
(
preg_match
(
'/^([`]{3,}|[~]{3,})[ ]*(\S+)?[ ]*$/'
,
$deindented_line
,
$matches
))
{
$elements
[]
=
$element
;
$element
=
array
(
'type'
=>
'fenced_code_block'
,
'text'
=>
''
,
'fence'
=>
$matches
[
1
],
);
isset
(
$matches
[
2
])
and
$element
[
'language'
]
=
$matches
[
2
];
continue
2
;
}
break
;
case
'*'
:
case
'+'
:
case
'-'
:
...
...
@@ -527,7 +576,8 @@ class Parsedown
break
;
case
'code'
:
case
'code_block'
:
case
'fenced_code_block'
:
$text
=
htmlentities
(
$element
[
'text'
],
ENT_NOQUOTES
);
...
...
tests/data/fenced_code_block.html
0 → 100644
View file @
67b51794
<pre><code>
<
?php
$message = 'fenced code block';
echo $message;
</code></pre>
<pre><code>
tilde
</code></pre>
\ No newline at end of file
tests/data/fenced_code_block.md
0 → 100644
View file @
67b51794
```
<?php
$message
=
'fenced code block'
;
echo
$message
;
```
~~~
tilde
~~~
\ 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