Compare commits
39 Commits
Author | SHA1 | Date |
---|---|---|
|
0cc7b0dd45 | 3 years ago |
|
c7dcd85cce | 3 years ago |
|
efa8516a67 | 3 years ago |
|
507e1e4d26 | 3 years ago |
|
e6ba398b14 | 3 years ago |
|
e37050c3f4 | 3 years ago |
|
496034258a | 3 years ago |
|
4e1e44a41b | 3 years ago |
|
b71dd1d440 | 3 years ago |
|
e841ca30ad | 3 years ago |
|
1aa376d6ec | 3 years ago |
|
9d407c3706 | 3 years ago |
|
6100cf0f6b | 3 years ago |
|
499b2b6fe4 | 3 years ago |
|
8408d735dc | 3 years ago |
|
d6f4545325 | 3 years ago |
|
39307e24e9 | 3 years ago |
|
08ea243729 | 3 years ago |
|
1bca2ac15c | 3 years ago |
|
d7e17e59df | 3 years ago |
|
289d68fa2f | 3 years ago |
|
abb2dbc690 | 3 years ago |
|
859e4801ab | 3 years ago |
|
35dbd30681 | 3 years ago |
|
aefa51e96c | 3 years ago |
|
b0cb237b22 | 3 years ago |
|
3fb2aa6a2d | 3 years ago |
|
559574b492 | 3 years ago |
|
86c895b971 | 3 years ago |
|
1457431f9e | 3 years ago |
|
850dd51029 | 3 years ago |
|
fc2c074e5b | 3 years ago |
|
cbba8bf4dd | 3 years ago |
|
3b4c24b02b | 3 years ago |
|
3ce53597a4 | 3 years ago |
|
34d502b090 | 3 years ago |
|
ec4169ea22 | 3 years ago |
|
edafdd15ea | 3 years ago |
|
0378f35b07 | 3 years ago |
21 changed files with 691 additions and 87 deletions
@ -0,0 +1,35 @@ |
||||
# Changelog |
||||
|
||||
## Version 1.2.0 |
||||
The *"annotation release"* |
||||
|
||||
### Added |
||||
* paragraph annotations *(now can set HTML ids and classes with `{.someClass, #someId}` syntax)* |
||||
* unit tests for annotation |
||||
* unit for headings *(`h1` to `h5`)* |
||||
|
||||
### Removed |
||||
* Testing code in `index.php` |
||||
|
||||
## Version 1.1.2 |
||||
No major changes introduced, getting ready for release |
||||
|
||||
### Changed |
||||
* added compatibility for `prism` code highlighting inside code blocks |
||||
|
||||
## Version 1.1.0 |
||||
No major changes introduced, getting ready for release |
||||
|
||||
### Added |
||||
* unit tests via `PHPUnit` |
||||
|
||||
### Changed |
||||
* Parser does not generate unnessecary empty paragraphs anymore |
||||
* Fix: parse does not get stuck on blockquotes that are not followed by an empty |
||||
line anymore |
||||
|
||||
### Removed |
||||
* "Monkey test" `.md` files in `tests` folder |
||||
|
||||
## Version 1.0.0 |
||||
Basic implementation |
@ -0,0 +1,18 @@ |
||||
Copyright (C) 2022, MikO <miko@massivedynamic.eu> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of |
||||
this software and associated documentation files (the "Software"), to deal in |
||||
the Software without restriction, including without limitation the rights to |
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||||
the Software, and to permit persons to whom the Software is furnished to do so, |
||||
subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,70 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
|
||||
final class AnnotationsTest extends TestCase { |
||||
public function testAnnotationsDoNotBreakHeadings() : void { |
||||
$source = " |
||||
# This is an H1 {.withAClass} |
||||
## This is an H2 {.withAClass} |
||||
### This is an H3 {.withAClass} |
||||
#### This is an H4 {.withAClass} |
||||
##### This is an H5 {.withAClass} |
||||
"; |
||||
$target = " |
||||
<h1>This is an H1</h1> |
||||
<h2>This is an H2</h2> |
||||
<h3>This is an H3</h3> |
||||
<h4>This is an H4</h4> |
||||
<h5>This is an H5</h5> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testAnnotationsDoNotBreakLists() : void { |
||||
$source = " |
||||
|
||||
* this is a list |
||||
* with annotations {#someID} |
||||
|
||||
1. this is an ordered list |
||||
1. with an annotation {.someClass} |
||||
|
||||
"; |
||||
$target = " |
||||
<ul> |
||||
<li>this is a list</li> |
||||
<li>with annotations</li> |
||||
</ul> |
||||
<ol> |
||||
<li> |
||||
this is an ordered list |
||||
<ol> |
||||
<li>with an annotation</li> |
||||
</ol> |
||||
</li> |
||||
</ol> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testAnnotationsDoNotBreakCodeblocks() : void { |
||||
$source = " |
||||
``` |
||||
this is a code block |
||||
``` {.someClass} |
||||
"; |
||||
$target = " |
||||
<pre> |
||||
<code>this is a code block</code> |
||||
</pre> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
|
||||
final class CodeBlocksTest extends TestCase { |
||||
public function testCodeblocksParseCorrectly() : void { |
||||
$source = " |
||||
``` |
||||
this is a code block |
||||
``` |
||||
"; |
||||
$target = " |
||||
<pre> |
||||
<code> |
||||
this is a code block |
||||
</code> |
||||
</pre> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testLanguageAnnotationParsesCorrectly() : void { |
||||
$source = " |
||||
```php |
||||
public function testLanguageAnnotationParsesCorrectly() : bool { |
||||
return true; |
||||
} |
||||
|
||||
``` |
||||
"; |
||||
$target = " |
||||
<pre data-lang=\"php\" class=\"language-php\"> |
||||
<code data-lang=\"php\" class=\"language-php\"> |
||||
public function testLanguageAnnotationParsesCorrectly() : bool { |
||||
return true; |
||||
} |
||||
</code> |
||||
</pre> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
|
||||
final class GenericBlocksTest extends TestCase { |
||||
public function testParagraphParsesCorrectly() : void { |
||||
$source = " |
||||
this is a paragraph |
||||
"; |
||||
$target = " |
||||
<p> |
||||
this is a paragraph |
||||
</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testBlockquotesParseCorrectly() : void { |
||||
$source = " |
||||
> this is |
||||
> |
||||
> a blockquote |
||||
|
||||
"; |
||||
$target = " |
||||
<blockquote> |
||||
this is <br><br> |
||||
a blockquote<br> |
||||
</blockquote> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testHorizontalRuleParsesCorrectly() : void { |
||||
$source = " |
||||
--- |
||||
"; |
||||
$target = "<hr>"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testParagraphAnnotations() : void { |
||||
$source = " |
||||
|
||||
this is an annotated paragraph {.classA, .classB} |
||||
|
||||
"; |
||||
$target = " |
||||
<p class=\"classA classB\"> |
||||
this is an annotated paragraph |
||||
</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
} |
@ -0,0 +1,65 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
|
||||
final class HeadingsTest extends TestCase { |
||||
public function testH1ParsesCorrectly() : void { |
||||
$source = " |
||||
# This is an H1 |
||||
"; |
||||
$target = " |
||||
<h1>This is an H1</h1> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testH2ParsesCorrectly() : void { |
||||
$source = " |
||||
## This is an H2 |
||||
"; |
||||
$target = " |
||||
<h2>This is an H2</h2> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testH3ParsesCorrectly() : void { |
||||
$source = " |
||||
### This is an H3 |
||||
"; |
||||
$target = " |
||||
<h3>This is an H3</h3> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testH4ParsesCorrectly() : void { |
||||
$source = " |
||||
#### This is an H4 |
||||
"; |
||||
$target = " |
||||
<h4>This is an H4</h4> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testH5ParsesCorrectly() : void { |
||||
$source = " |
||||
##### This is an H5 |
||||
"; |
||||
$target = " |
||||
<h5>This is an H5</h5> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
} |
@ -0,0 +1,84 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
|
||||
final class InlineElementsTest extends TestCase { |
||||
public function testBoldParsesCorrectly() : void { |
||||
$source = " |
||||
|
||||
Lorem **ipsum** dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor. |
||||
|
||||
"; |
||||
$target = " |
||||
<p>Lorem <b>ipsum</b> dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testItalicParsesCorrectly() : void { |
||||
$source = " |
||||
|
||||
Lorem **ipsum** dolor sit amet, *consetetur* sadipscing elitr, sed diam nonumy eirmod tempor. |
||||
|
||||
"; |
||||
$target = " |
||||
<p>Lorem <b>ipsum</b> dolor sit amet, <i>consetetur</i> sadipscing elitr, sed diam nonumy eirmod tempor.</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testCodeSnippetsParseCorrectly() : void { |
||||
$source = " |
||||
|
||||
Lorem **ipsum** dolor sit amet, *consetetur* sadipscing `elitr`, sed diam nonumy eirmod tempor. |
||||
|
||||
"; |
||||
$target = " |
||||
<p>Lorem <b>ipsum</b> dolor sit amet, <i>consetetur</i> sadipscing <code>elitr</code>, sed diam nonumy eirmod tempor.</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testImagesParseCorrectly() : void { |
||||
$source = " |
||||
 |
||||
Lorem ipsum dolor sit amet. |
||||
|
||||
"; |
||||
$target = " |
||||
<p> |
||||
<img alt=\"an image\" src=\"https://massivedynamic.eu/wp-content/themes/massivedynamic/logo_massive_dynamic.png\"> |
||||
Lorem ipsum dolor sit amet. |
||||
</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testLinksParseCorrectly() : void { |
||||
$source = " |
||||
|
||||
Lorem **ipsum** dolor sit amet, *consetetur* sadipscing `elitr`, [sed diam](https://massivedynamic.eu) nonumy eirmod tempor. |
||||
|
||||
"; |
||||
$target = " |
||||
<p> |
||||
Lorem <b>ipsum</b> dolor sit amet, <i>consetetur</i> sadipscing <code>elitr</code>, |
||||
<a href=\"https://massivedynamic.eu\"> |
||||
sed diam |
||||
</a> |
||||
nonumy eirmod tempor. |
||||
</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
|
||||
final class ListsTest extends TestCase { |
||||
public function testUnorderedListsParseCorrectly() : void { |
||||
$source = " |
||||
|
||||
* Listpoint A |
||||
* Listpoint B |
||||
* Subpoint B1 |
||||
* Subpoint B2 |
||||
* Listpoint C |
||||
|
||||
"; |
||||
$target = " |
||||
<ul> |
||||
<li> Listpoint A</li> |
||||
<li> |
||||
Listpoint B |
||||
<ul> |
||||
<li> Subpoint B1</li> |
||||
<li> Subpoint B2</li> |
||||
</ul> |
||||
</li> |
||||
<li> Listpoint C</li> |
||||
</ul> |
||||
"; |
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testOrderedListsParseCorrectly() : void { |
||||
$source = " |
||||
|
||||
1. Listpoint A |
||||
2. Listpoint B |
||||
1. Subpoint B1 |
||||
2. Subpoint B2 |
||||
3. Listpoint C |
||||
|
||||
"; |
||||
$target = " |
||||
<ol> |
||||
<li> Listpoint A</li> |
||||
<li> |
||||
Listpoint B |
||||
<ol> |
||||
<li> Subpoint B1</li> |
||||
<li> Subpoint B2</li> |
||||
</ol> |
||||
</li> |
||||
<li> Listpoint C</li> |
||||
</ol> |
||||
"; |
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
|
||||
final class ReferencesTest extends TestCase { |
||||
public function testSimpleReferencesAreResolvedCorrectly() : void { |
||||
$source = " |
||||
this text uses [a simple reference][1] |
||||
|
||||
[1]: https://massivedynamic.eu |
||||
"; |
||||
$target = " |
||||
<p> |
||||
this text uses <a href=\"https://massivedynamic.eu\">a simple reference</a> |
||||
</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
|
||||
public function testNamedReferencesAreResolvedCorrectly() : void { |
||||
$source = " |
||||
this text uses [a simple reference][REF] and does it [twice][REF] |
||||
|
||||
[REF]: https://massivedynamic.eu |
||||
"; |
||||
$target = " |
||||
<p> |
||||
this text uses <a href=\"https://massivedynamic.eu\">a simple reference</a> |
||||
and does it <a href=\"https://massivedynamic.eu\">twice</a> |
||||
</p> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
|
||||
final class TablesTest extends TestCase { |
||||
public function testTableParsesCorrectly() : void { |
||||
$source = " |
||||
| Product | Amount | Price | |
||||
|:--------|:------:|-------:| |
||||
| Part A | 5 | 20,00€ | |
||||
| Editor | 100 | 39,99€ | |
||||
|
||||
"; |
||||
$target = " |
||||
<table> |
||||
<tr> |
||||
<th style=\"text-align: left\">Product</th> |
||||
<th style=\"text-align: center\">Amount</th> |
||||
<th style=\"text-align: right\">Price</th> |
||||
</tr> |
||||
<tr> |
||||
<td style=\"text-align: left\">Part A</td> |
||||
<td style=\"text-align: center\">5</td> |
||||
<td style=\"text-align: right\">20,00€</td> |
||||
</tr> |
||||
<tr> |
||||
<td style=\"text-align: left\">Editor</td> |
||||
<td style=\"text-align: center\">100</td> |
||||
<td style=\"text-align: right\">39,99€</td> |
||||
</tr> |
||||
</table> |
||||
"; |
||||
|
||||
[$source, $result] = createTest($source, $target); |
||||
$this->assertEquals($source, $result); |
||||
} |
||||
} |
@ -1,19 +0,0 @@ |
||||
* point A |
||||
* point B |
||||
* sub A |
||||
* sub B |
||||
* sub sub A |
||||
* sub C |
||||
* sub D |
||||
* point C |
||||
* point D |
||||
* point E |
||||
* point F |
||||
|
||||
1. point 1 |
||||
2. sub 1 |
||||
1. sub sub 1 |
||||
1. sub sub 2 |
||||
3. sub 2 |
||||
3. point 2 |
||||
4. point 3 |
@ -1,2 +0,0 @@ |
||||
This is line one. |
||||
This is line two. |
@ -1,39 +0,0 @@ |
||||
# Heading 1 |
||||
#### lol **lol** |
||||
|
||||
* this **bold** and somewhat |
||||
* kind of *italic* thing |
||||
* is |
||||
* a |
||||
* list |
||||
|
||||
1. this is |
||||
2. an ordered |
||||
3. list |
||||
|
||||
Lorem **ipsum** dolor sit *amet*, `consetetur` sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. |
||||
|
||||
And we test: all [special chars][1] in random [text][hallo]. this [word][http://lol.de] is a link. |
||||
|
||||
### Testing an Image |
||||
**bold** at the beginning |
||||
|
||||
lol 1 bild  |
||||
|
||||
| Spalte 1 | Spalte 2 | Spalte 3 | |
||||
|:---------|-----:----|---------:| |
||||
| value a | value b | value c | |
||||
|
||||
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. {class: rot} |
||||
|
||||
``` |
||||
//this should be a codeblock |
||||
function helloWorld() : void { |
||||
echo "Hello World!"; |
||||
} |
||||
|
||||
helloWorld(); |
||||
``` |
||||
|
||||
[1]: https://these-are-references:0 |
||||
[hallo]: ulululu |
@ -0,0 +1,12 @@ |
||||
<?php declare(strict_types=1); |
||||
|
||||
use parkdown\Parkdown; |
||||
|
||||
function createTest(string $source, string $target) : array { |
||||
$strip = function(string $string) : string { |
||||
return trim(preg_replace("/\s+/", "", $string)); |
||||
}; |
||||
|
||||
$parkdown = new Parkdown($source); |
||||
return [$strip($target), $strip($parkdown->html())]; |
||||
} |
Loading…
Reference in new issue