Compare commits

..

39 Commits

Author SHA1 Message Date
Michael Ochmann 0cc7b0dd45 added changelog for v1.2.0 3 years ago
Michael Ochmann c7dcd85cce cleaned up index.php 3 years ago
Michael Ochmann efa8516a67 fixed typos in readme 3 years ago
Michael Ochmann 507e1e4d26 added tests for headings 3 years ago
Michael Ochmann e6ba398b14 Merge pull request 'Paragraph annotations' (#2) from feature/paragraph-annotations into development 3 years ago
Michael Ochmann e37050c3f4 added tests to check for annotations breaking things 3 years ago
Michael Ochmann 496034258a fixed annoations breaking headings 3 years ago
Michael Ochmann 4e1e44a41b added braces to escapable characters 3 years ago
Michael Ochmann b71dd1d440 added annotation example to readme 3 years ago
Michael Ochmann e841ca30ad Merge branch 'development' into feature/paragraph-annotations 3 years ago
Michael Ochmann 1aa376d6ec fixed bug in parser where bold text on single line was parsed as list 3 years ago
Michael Ochmann 9d407c3706 now parsing `id` and `class` annotations on paragraphs 3 years ago
Michael Ochmann 6100cf0f6b added `LBRACE` and `RBRACE` tokens to lexer 3 years ago
Michael Ochmann 499b2b6fe4 fixed annotation test 3 years ago
Michael Ochmann 8408d735dc Merge branch 'development' into feature/paragraph-annotations 3 years ago
Michael Ochmann d6f4545325 added test for paragraph annotations 3 years ago
Michael Ochmann 39307e24e9 fixed test for codeblocks 3 years ago
Michael Ochmann 08ea243729 added usage example 3 years ago
Michael Ochmann 1bca2ac15c added changelog for new version 3 years ago
Michael Ochmann d7e17e59df bump version 3 years ago
Michael Ochmann 289d68fa2f added support for `prism` style code highlighting 3 years ago
Michael Ochmann abb2dbc690 making shure, php 8.1 or higher is required 3 years ago
Michael Ochmann 859e4801ab mentioning tests in readme 3 years ago
Michael Ochmann 35dbd30681 added changelog for 3 years ago
Michael Ochmann aefa51e96c added license 3 years ago
Michael Ochmann b0cb237b22 releasing version 1.0.0 3 years ago
Michael Ochmann 3fb2aa6a2d added full test suite for: 3 years ago
Michael Ochmann 559574b492 fixed endless loop when blockquote had not empty line after 3 years ago
Michael Ochmann 86c895b971 removed old monkey tests 3 years ago
Michael Ochmann 1457431f9e removed test strings from readme; added nesting to mentioning of nesting 3 years ago
Michael Ochmann 850dd51029 now using color option on `PHPUnit` 3 years ago
Michael Ochmann fc2c074e5b now checking if skipped empty node is actually a text node 3 years ago
Michael Ochmann cbba8bf4dd finished tests for inline elements 3 years ago
Michael Ochmann 3b4c24b02b added tests for inline elements 3 years ago
Michael Ochmann 3ce53597a4 added test for ordered lists (`<ol>`) 3 years ago
Michael Ochmann 34d502b090 added test for list elements 3 years ago
Michael Ochmann ec4169ea22 added helper functions which are injected into every test 3 years ago
Michael Ochmann edafdd15ea added `PHPUnit` as dev dependency 3 years ago
Michael Ochmann 0378f35b07 now preventing empty lines from gettin parsed into paragraphs 3 years ago
  1. 35
      CHANGELOG.md
  2. 18
      LICENSE.md
  3. 54
      README.md
  4. 9
      composer.json
  5. 16
      composer.lock
  6. 13
      index.php
  7. 8
      src/Lexer.php
  8. 79
      src/Parser.php
  9. 2
      src/Token.php
  10. 70
      tests/AnnotationsTest.php
  11. 46
      tests/CodeBlocksTest.php
  12. 63
      tests/GenericBlocksTest.php
  13. 65
      tests/HeadingsTest.php
  14. 84
      tests/InlineElementsTest.php
  15. 59
      tests/ListsTest.php
  16. 38
      tests/ReferencesTest.php
  17. 37
      tests/TablesTest.php
  18. 19
      tests/list.md
  19. 2
      tests/paragraph.md
  20. 39
      tests/test1.md
  21. 12
      tests/util.php

@ -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.

@ -13,10 +13,8 @@ Parkdown currently support the following block types:
* paragraphs
* block quotes
* lists *(like this one)*
* also nested
* also nested
* horizontal rules `---`
* lol
* bar
### Supported inline types
Parkdown currently support the following block types:
@ -35,11 +33,27 @@ Parkdown currently support the following block types:
### Paragraphs
```markdown
A simple paragraph can contain **bold text**, `inline codeblocks` and *italic text*. We can also link [with a direct url][https://google.com] *(i.e. to google)*
or via reference to [a later defined url][massivedynamic], i we so desire.
or via reference to [a later defined url][massivedynamic], if we so desire.
```
A simple paragraph can contain **bold text**, `inline codeblocks` and *italic text*. We can also link [with a direct url](https://google.com) *(i.e. to google)*
or via reference to [a later defined url][massivedynamic], i we so desire.
or via reference to [a later defined url][massivedynamic], if we so desire.
Paragraphs can be annotated with `id` and `class` attributes:
```markdown
Paragraphs can be annotated with ids and classes {.thisIsAClass, .anotherClass, #thisIsAnID}
```
results in
Paragraphs can be annotated with ids and classes {.thisIsAClass, .anotherClass, #thisIsAnID}
```html
<p class="thisIsAClass anotherClass" id="thisIsAnID">
Paragraphs can be annotated with ids and classes
</p>
```
### Images
```markdown
@ -59,14 +73,14 @@ or via reference to [a later defined url][massivedynamic], i we so desire.
> Only two things are infinite,
> the universe and human stupidity,
> i am not totally shure about the universe, though...
> - Albert Einstein
> Albert Einstein
```
> Only two things are infinite,
> the universe and human stupidity,
> i am not totally shure about the universe, though...
> - Albert Einstein
> Albert Einstein
### Code blocks
```markdown
@ -113,3 +127,29 @@ or via reference to [a later defined url][massivedynamic], i we so desire.
```
[massivedynamic]: https://massivedynamic.eu
## Usage
Simply construct an new `parkdown\Parkdown` object and pass the Markdown source code to it's constructor. The parsed `DOMDocument` or it's `HTML` output can then be retrieved through the `::html()` and `::tree()` member functions.
**Example**
```php
use parkdown\Parkdown;
$source = "
This is a **bold** word in a paragraph.
";
$parser = new Parkdown($source);
$tree = $parser->tree();
print_r($tree);
echo $parser->html();
```
## Testing
Unit tests can be run via `composer`:
```
composer test
```

@ -1,6 +1,7 @@
{
"name": "massivedynamic/parkdown",
"type": "library",
"version": "v1.2.0",
"license": "MIT",
"autoload": {
"psr-4": {
@ -13,7 +14,13 @@
"email": "miko@massivedynamic.eu"
}
],
"require": {
"php" : ">=8.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9"
},
"scripts" : {
"test" : "./vendor/bin/phpunit tests --testdox --bootstrap tests/util.php --color"
}
}

16
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e2289ec2def0b32ef8010e9336707400",
"content-hash": "279a20d650c6a9ed1a0b5762efc6325a",
"packages": [],
"packages-dev": [
{
@ -848,16 +848,16 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.16",
"version": "9.5.18",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "5ff8c545a50226c569310a35f4fa89d79f1ddfdc"
"reference": "1b5856028273bfd855e60a887278857d872ec67a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/5ff8c545a50226c569310a35f4fa89d79f1ddfdc",
"reference": "5ff8c545a50226c569310a35f4fa89d79f1ddfdc",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b5856028273bfd855e60a887278857d872ec67a",
"reference": "1b5856028273bfd855e60a887278857d872ec67a",
"shasum": ""
},
"require": {
@ -935,7 +935,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.16"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.18"
},
"funding": [
{
@ -947,7 +947,7 @@
"type": "github"
}
],
"time": "2022-02-23T17:10:58+00:00"
"time": "2022-03-08T06:52:28+00:00"
},
{
"name": "sebastian/cli-parser",
@ -2111,5 +2111,5 @@
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.1.0"
"plugin-api-version": "2.3.0"
}

@ -4,15 +4,24 @@ require __DIR__."/vendor/autoload.php";
$source = file_get_contents(dirname(__FILE__)."/README.md");
//$source = file_get_contents(dirname(__FILE__)."/tests/paragraph.md");
//$source = file_get_contents(dirname(__FILE__)."/tests/list.md");
echo "
<style>
body {
padding: 4rem;
margin: 0;
font-family: sans-serif;
}
img {
max-width: 100%;
}
code {
word-break: break-word;
white-space: break-spaces;
}
table {
width: 100%;
}

@ -104,6 +104,14 @@ class Lexer {
$clearBuffer();
array_push($tokens, new Token(TokenType::COLON, $char));
break;
case '{':
$clearBuffer();
array_push($tokens, new Token(TokenType::LBRACE, $char));
break;
case '}':
$clearBuffer();
array_push($tokens, new Token(TokenType::RBRACE, $char));
break;
default:
$buffer .= $char;
break;

@ -2,6 +2,7 @@
namespace parkdown;
use Attribute;
use DOMDocument;
use DOMElement;
use DOMNode;
@ -11,6 +12,11 @@ enum ListType {
case UNORDERED;
}
class Attributes {
public array $classes = [];
public ?string $id = null;
}
class Parser {
const MAGIC_CHAR = "*";
@ -164,7 +170,8 @@ class Parser {
TokenType::BACKTICK,
TokenType::ASTERISK,
TokenType::LBRACKET,
TokenType::BANG
TokenType::BANG,
TokenType::LBRACE
])) {
$this->consume()->data; // backslash
$buffer .= $this->consume()->data;
@ -228,6 +235,41 @@ class Parser {
$clearBuffer();
array_push($elms, $elm);
continue;
} elseif ($this->current()->type === TokenType::LBRACE) {
$lbrace = $this->consume();
assert($lbrace->type === TokenType::LBRACE, "expected left brace, got ".$lbrace->type->name);
$content = "";
while ($this->current()->type !== TokenType::EOF &&
$this->current()->type !== TokenType::EOL &&
$this->current()->type !== TokenType::RBRACE) {
$content .= $this->consume()->data;
}
$rbrace = $this->consume();
assert($rbrace->type === TokenType::RBRACE, "expected right brace, got ".$rbrace->type->name);
$attributes = array_map(function($element) {
return trim($element);
}, explode(',', $content));
$obj = new Attributes();
foreach($attributes as $attribute) {
if (!in_array($attribute[0], [".", "#"]))
continue;
switch ($attribute[0]) {
case ".":
array_push($obj->classes, substr($attribute, 1));
break;
case "#":
$obj->id = substr($attribute, 1);
break;
default:
continue 2;
}
}
array_push($elms, $obj);
} else
$buffer .= self::StripBackslashes($this->consume()->data);
}
@ -268,6 +310,7 @@ class Parser {
// then we parse the node content
$elm = $this->document->createElement("li");
foreach ($this->parseText() as $node)
if ($node instanceof DOMNode)
$elm->appendChild($node);
// now we check, if the level of the next line is higher than the current level.
@ -301,9 +344,26 @@ class Parser {
}
private function buildParagraph(array $elms) : void {
if (count($elms) < 1)
return;
$elm = $this->document->createElement("p");
foreach ($elms as $node)
$i = 0;
foreach ($elms as $node) {
if ($node instanceof Attributes) {
if (count($node->classes) > 0)
$elm->setAttribute("class", join(" ", $node->classes));
if ($node->id)
$elm->setAttribute("id", $node->id);
continue;
}
if ($node->nodeName === "#text" && trim($node->textContent) === "")
continue;
$elm->appendChild($node);
$i++;
}
if ($i < 1)
return;
$this->document->appendChild($elm);
}
@ -316,6 +376,7 @@ class Parser {
}
$elm = $this->document->createElement("h".$level);
foreach ($this->parseText() as $node)
if ($node instanceof DOMNode)
$elm->appendChild($node);
$this->document->appendChild($elm);
}
@ -334,8 +395,10 @@ class Parser {
$lang = count($lang) > 0 ? trim($lang[0]->data) : null;
$container = $this->document->createElement("pre");
if ($lang)
if ($lang) {
$container->setAttribute("data-lang", $lang);
$container->setAttribute("class", "language-$lang");
}
$buffer = "";
while (!($this->current()->type === TokenType::BACKTICK &&
@ -350,6 +413,10 @@ class Parser {
}
$elm = $this->document->createElement("code", htmlspecialchars($buffer));
if ($lang) {
$elm->setAttribute("data-lang", $lang);
$elm->setAttribute("class", "language-$lang");
}
$container->appendChild($elm);
$this->document->appendChild($container);
$this->consume();
@ -458,7 +525,7 @@ class Parser {
}
$buffer = "";
$elm = $this->document->createElement("blockquote", $buffer);
while (!($this->current()->type === TokenType::EOL && $this->next()->type !== TokenType::GT)) {
while (!($this->current()->type === TokenType::EOF) && !($this->current()->type === TokenType::EOL && $this->next()->type !== TokenType::GT)) {
$gt = $this->consume();
if ($this->current()->type === TokenType::EOL) {
$this->consume();
@ -495,6 +562,10 @@ class Parser {
while ($this->current()->type !== TokenType::EOF) {
switch($this->current()->type) {
case TokenType::ASTERISK:
if ($this->next()->type === TokenType::ASTERISK) {
$this->buildParagraph($this->parseText(true));
break;
}
$list = $this->parseList();
$this->document->appendChild($list);
break;

@ -22,6 +22,8 @@ enum TokenType {
case PIPE ;
case GT ;
case TAB ;
case LBRACE ;
case RBRACE ;
}
class Token {

@ -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 = "
![an image](https://massivedynamic.eu/wp-content/themes/massivedynamic/logo_massive_dynamic.png)
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&euro;</td>
</tr>
<tr>
<td style=\"text-align: left\">Editor</td>
<td style=\"text-align: center\">100</td>
<td style=\"text-align: right\">39,99&euro;</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 ![Eine Perle: für **die Ewigkeit* ..](https://mike-ochmann.de/assets/images/perl_jam.jpg)
| 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…
Cancel
Save