Merge pull request #674 from ArthurHoaro/parsedown-composer
Use Composer for Parsedown and fix an issue with links
This commit is contained in:
commit
761b4e2837
7 changed files with 69 additions and 1540 deletions
4
COPYING
4
COPYING
|
@ -72,10 +72,6 @@ Files: plugins/wallabag/wallabag.png
|
||||||
License: MIT License (http://opensource.org/licenses/MIT)
|
License: MIT License (http://opensource.org/licenses/MIT)
|
||||||
Copyright: (C) 2015 Nicolas Lœuillet - https://github.com/wallabag/wallabag
|
Copyright: (C) 2015 Nicolas Lœuillet - https://github.com/wallabag/wallabag
|
||||||
|
|
||||||
Files: plugins/markdown/Parsedown.php
|
|
||||||
License: MIT License (http://opensource.org/licenses/MIT)
|
|
||||||
Copyright: (C) 2015 Emanuil Rusev - https://github.com/erusev/parsedown
|
|
||||||
|
|
||||||
----------------------------------------------------
|
----------------------------------------------------
|
||||||
ZLIB/LIBPNG LICENSE
|
ZLIB/LIBPNG LICENSE
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
"keywords": ["bookmark", "link", "share", "web"],
|
"keywords": ["bookmark", "link", "share", "web"],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.4",
|
"php": ">=5.3.4",
|
||||||
"shaarli/netscape-bookmark-parser": "1.*"
|
"shaarli/netscape-bookmark-parser": "1.*",
|
||||||
|
"erusev/parsedown": "1.6"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpmd/phpmd" : "@stable",
|
"phpmd/phpmd" : "@stable",
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,8 +6,6 @@
|
||||||
* Shaare's descriptions are parsed with Markdown.
|
* Shaare's descriptions are parsed with Markdown.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'Parsedown.php';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this tag is used on a shaare, the description won't be processed by Parsedown.
|
* If this tag is used on a shaare, the description won't be processed by Parsedown.
|
||||||
*/
|
*/
|
||||||
|
@ -157,8 +155,9 @@ function reverse_text2clickable($description)
|
||||||
$lineCount = 0;
|
$lineCount = 0;
|
||||||
|
|
||||||
foreach ($descriptionLines as $descriptionLine) {
|
foreach ($descriptionLines as $descriptionLine) {
|
||||||
// Detect line of code
|
// Detect line of code: starting with 4 spaces,
|
||||||
$codeLineOn = preg_match('/^ /', $descriptionLine) > 0;
|
// except lists which can start with +/*/- or `2.` after spaces.
|
||||||
|
$codeLineOn = preg_match('/^ +(?=[^\+\*\-])(?=(?!\d\.).)/', $descriptionLine) > 0;
|
||||||
// Detect and toggle block of code
|
// Detect and toggle block of code
|
||||||
if (!$codeBlockOn) {
|
if (!$codeBlockOn) {
|
||||||
$codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
|
$codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
|
||||||
|
@ -175,10 +174,10 @@ function reverse_text2clickable($description)
|
||||||
$descriptionLine
|
$descriptionLine
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reverse hashtag links if we're in a code block.
|
// Reverse all links in code blocks, only non hashtag elsewhere.
|
||||||
$hashtagFilter = ($codeBlockOn || $codeLineOn) ? $hashtagTitle : '';
|
$hashtagFilter = (!$codeBlockOn && !$codeLineOn) ? '(?!'. $hashtagTitle .')': '(?:'. $hashtagTitle .')?';
|
||||||
$descriptionLine = preg_replace(
|
$descriptionLine = preg_replace(
|
||||||
'!<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>!m',
|
'#<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>#m',
|
||||||
'$1',
|
'$1',
|
||||||
$descriptionLine
|
$descriptionLine
|
||||||
);
|
);
|
||||||
|
|
|
@ -151,4 +151,17 @@ function testNoMarkdownTag()
|
||||||
$data = hook_markdown_render_daily($data);
|
$data = hook_markdown_render_daily($data);
|
||||||
$this->assertEquals($str, $data['cols'][0][0]['formatedDescription']);
|
$this->assertEquals($str, $data['cols'][0][0]['formatedDescription']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test hashtag links processed with markdown.
|
||||||
|
*/
|
||||||
|
function testMarkdownHashtagLinks()
|
||||||
|
{
|
||||||
|
$md = file_get_contents('tests/plugins/resources/markdown.md');
|
||||||
|
$md = format_description($md);
|
||||||
|
$html = file_get_contents('tests/plugins/resources/markdown.html');
|
||||||
|
|
||||||
|
$data = process_markdown($md);
|
||||||
|
$this->assertEquals($html, $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
24
tests/plugins/resources/markdown.html
Normal file
24
tests/plugins/resources/markdown.html
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<div class="markdown"><ul>
|
||||||
|
<li>test:
|
||||||
|
<ul>
|
||||||
|
<li><a href="http://link.tld">zero</a></li>
|
||||||
|
<li><a href="http://link.tld">two</a></li>
|
||||||
|
<li><a href="http://link.tld">three</a></li>
|
||||||
|
</ul></li>
|
||||||
|
</ul>
|
||||||
|
<ol>
|
||||||
|
<li><a href="http://link.tld">zero</a>
|
||||||
|
<ol>
|
||||||
|
<li><a href="http://link.tld">two</a></li>
|
||||||
|
<li><a href="http://link.tld">three</a></li>
|
||||||
|
<li><a href="http://link.tld">four</a></li>
|
||||||
|
<li>foo <a href="?addtag=foobar" title="Hashtag foobar">#foobar</a></li>
|
||||||
|
</ol></li>
|
||||||
|
</ol>
|
||||||
|
<p><a href="?addtag=foobar" title="Hashtag foobar">#foobar</a> foo <code>lol #foo</code> <a href="?addtag=bar" title="Hashtag bar">#bar</a></p>
|
||||||
|
<p>fsdfs <a href="http://link.tld">http://link.tld</a> <a href="?addtag=foobar" title="Hashtag foobar">#foobar</a> <code>http://link.tld</code></p>
|
||||||
|
<pre><code>http://link.tld #foobar
|
||||||
|
next #foo</code></pre>
|
||||||
|
<p>Block:</p>
|
||||||
|
<pre><code>lorem ipsum #foobar http://link.tld
|
||||||
|
#foobar http://link.tld</code></pre></div>
|
24
tests/plugins/resources/markdown.md
Normal file
24
tests/plugins/resources/markdown.md
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
* test:
|
||||||
|
* [zero](http://link.tld)
|
||||||
|
+ [two](http://link.tld)
|
||||||
|
- [three](http://link.tld)
|
||||||
|
|
||||||
|
1. [zero](http://link.tld)
|
||||||
|
2. [two](http://link.tld)
|
||||||
|
3. [three](http://link.tld)
|
||||||
|
4. [four](http://link.tld)
|
||||||
|
5. foo #foobar
|
||||||
|
|
||||||
|
#foobar foo `lol #foo` #bar
|
||||||
|
|
||||||
|
fsdfs http://link.tld #foobar `http://link.tld`
|
||||||
|
|
||||||
|
http://link.tld #foobar
|
||||||
|
next #foo
|
||||||
|
|
||||||
|
Block:
|
||||||
|
|
||||||
|
```
|
||||||
|
lorem ipsum #foobar http://link.tld
|
||||||
|
#foobar http://link.tld
|
||||||
|
```
|
Loading…
Reference in a new issue