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
ddc5b7e2
Commit
ddc5b7e2
authored
Nov 22, 2013
by
Emanuil Rusev
Browse files
implement URL auto-linking
parent
5a563008
Changes
3
Hide whitespace changes
Inline
Side-by-side
Parsedown.php
View file @
ddc5b7e2
...
...
@@ -733,29 +733,35 @@ class Parsedown
}
}
# automatic link
if
(
strpos
(
$text
,
'<'
)
!==
FALSE
and
preg_match_all
(
'/<((https?|ftp|dict):[^\^\s]+?)>/i'
,
$text
,
$matches
,
PREG_SET_ORDER
))
if
(
strpos
(
$text
,
'://'
)
!==
FALSE
)
{
foreach
(
$matches
as
$matches
)
switch
(
TRUE
)
{
$url
=
$matches
[
1
];
case
preg_match_all
(
'{<(https?:[/]{2}[^\s]+)>}i'
,
$text
,
$matches
,
PREG_SET_ORDER
)
:
case
preg_match_all
(
'{\b(https?:[/]{2}[^\s]+)\b}i'
,
$text
,
$matches
,
PREG_SET_ORDER
)
:
strpos
(
$url
,
'&'
)
!==
FALSE
and
$url
=
preg_replace
(
'/&(?!#?\w+;)/'
,
'&'
,
$url
);
foreach
(
$matches
as
$matches
)
{
$url
=
$matches
[
1
];
$element
=
'<a href=":href">:text</a>'
;
$element
=
str_replace
(
':text'
,
$url
,
$element
);
$element
=
str_replace
(
':href'
,
$url
,
$element
);
strpos
(
$url
,
'&'
)
!==
FALSE
and
$url
=
preg_replace
(
'/&(?!#?\w+;)/'
,
'&'
,
$url
);
# ~
$element
=
'<a href=":href">:text</a>'
;
$element
=
str_replace
(
':text'
,
$url
,
$element
);
$element
=
str_replace
(
':href'
,
$url
,
$element
);
$code
=
"
\x1A
"
.
'$'
.
$index
;
# ~
$text
=
str_replace
(
$matches
[
0
],
$code
,
$text
)
;
$code
=
"
\x1A
"
.
'$'
.
$index
;
$map
[
$code
]
=
$element
;
$text
=
str_replace
(
$matches
[
0
],
$code
,
$text
)
;
$index
++
;
$map
[
$code
]
=
$element
;
$index
++
;
}
break
;
}
}
...
...
tests/data/url_autolinking.html
0 → 100644
View file @
ddc5b7e2
<p>
Here's an autolink
<a
href=
"http://example.com"
>
http://example.com
</a>
.
</p>
\ No newline at end of file
tests/data/url_autolinking.md
0 → 100644
View file @
ddc5b7e2
Here's an autolink http://example.com.
\ 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