Skip to content

Commit aa66f02

Browse files
author
Martin Brecht-Precht
committed
Added first CommonmarkHandler and CommonmarkDispatcher.
Missing the HTML block and inline HTML handling.
1 parent ce363c6 commit aa66f02

20 files changed

+1625
-77
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
},
2525
"require": {
2626
"php": ">=5.3",
27-
"markdom/handler-interface": "^1.0.5",
27+
"markdom/handler-interface": "^1.0.8",
2828
"markenwerk/stack-util": "~1.0",
29-
"markenwerk/string-builder": "~1.0",
30-
"markenwerk/json-pretty-printer": "~1.0"
29+
"markenwerk/string-builder": "^1.0.4",
30+
"markenwerk/json-pretty-printer": "~1.0",
31+
"league/commonmark": "^0.13"
3132
}
3233
}

example/commonmark-01.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Markdom\Test;
4+
5+
use Markdom\Dispatcher\JsonDispatcher;
6+
use Markdom\Handler\CommonmarkHandler;
7+
8+
require_once(__DIR__ . '/../vendor/autoload.php');
9+
10+
$handler = new CommonmarkHandler();
11+
$dispatcher = new JsonDispatcher($handler);
12+
$dispatcher->processFile(__DIR__ . '/example-data.json');
13+
fwrite(STDOUT, $handler->getResult());

example/commonmark-02.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Markdom\Test;
4+
5+
use Markdom\Dispatcher\CommonmarkDispatcher;
6+
use Markdom\Handler\CommonmarkHandler;
7+
8+
require_once(__DIR__ . '/../vendor/autoload.php');
9+
10+
$handler = new CommonmarkHandler();
11+
$dispatcher = new CommonmarkDispatcher($handler);
12+
$dispatcher->processFile(__DIR__ . '/result.md');
13+
fwrite(STDOUT, $handler->getResult());

example/debug.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010
$handler = new DebugHandler();
1111
$dispatcher = new JsonDispatcher($handler);
12-
$dispatcher->parseFile(__DIR__ . '/example-data.json');
12+
$dispatcher->processFile(__DIR__ . '/example-data.json');
1313
fwrite(STDOUT, $handler->getResult());

example/example-data-simple.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"version": {
3+
"major": 1,
4+
"minor": 0
5+
},
6+
"blocks": [
7+
{
8+
"type": "Heading",
9+
"level": 1,
10+
"contents": [
11+
{
12+
"type": "Text",
13+
"text": "some markdown"
14+
}
15+
]
16+
},
17+
{
18+
"type": "Paragraph",
19+
"contents": [
20+
{
21+
"type": "Text",
22+
"text": "this "
23+
},
24+
{
25+
"type": "Emphasis",
26+
"level": 1,
27+
"contents": [
28+
{
29+
"type": "Text",
30+
"text": "is"
31+
}
32+
]
33+
},
34+
{
35+
"type": "Text",
36+
"text": " a not so simple "
37+
},
38+
{
39+
"type": "Emphasis",
40+
"level": 2,
41+
"contents": [
42+
{
43+
"type": "Text",
44+
"text": "paragraph"
45+
}
46+
]
47+
},
48+
{
49+
"type": "Text",
50+
"text": " with different kinds of "
51+
}
52+
]
53+
}
54+
]
55+
}

example/example-data.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
}
3535
]
3636
},
37+
{
38+
"type": "Comment",
39+
"comment": "Etiam porta sem malesuada magna mollis euismod.\nwich is multiline"
40+
},
3741
{
3842
"type": "Comment",
3943
"comment": "Etiam porta sem malesuada magna mollis euismod."

example/html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
->setEscapeHtml(false)
1313
->setBreakSoftBreaks(false);
1414
$dispatcher = new JsonDispatcher($handler);
15-
$dispatcher->parseFile(__DIR__ . '/example-data.json');
15+
$dispatcher->processFile(__DIR__ . '/example-data.json');
1616
fwrite(STDOUT, $handler->getResult());

example/json.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
->setPrettyPrint(true)
1313
->setEscapeUnicode(true);
1414
$dispatcher = new JsonDispatcher($handler);
15-
$dispatcher->parseFile(__DIR__ . '/example-data.json');
15+
$dispatcher->processFile(__DIR__ . '/example-data.json');
1616
fwrite(STDOUT, $handler->getResult());

example/xhtml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
->setEscapeHtml(true)
1313
->setBreakSoftBreaks(true);
1414
$dispatcher = new JsonDispatcher($handler);
15-
$dispatcher->parseFile(__DIR__ . '/example-data.json');
15+
$dispatcher->processFile(__DIR__ . '/example-data.json');
1616
fwrite(STDOUT, $handler->getResult());

example/xml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
$handler
1212
->setPrettyPrint(true);
1313
$dispatcher = new JsonDispatcher($handler);
14-
$dispatcher->parseFile(__DIR__ . '/example-data.json');
14+
$dispatcher->processFile(__DIR__ . '/example-data.json');
1515
fwrite(STDOUT, $handler->getResult()->saveXML());

0 commit comments

Comments
 (0)