Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 89580c5

Browse files
committed
Markdown and docs updates
Fixes #37
1 parent 4a1b862 commit 89580c5

File tree

5 files changed

+228
-47
lines changed

5 files changed

+228
-47
lines changed

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ composer require 8fold/php-markup
1515
```php
1616
$element = Element::fold("hello");
1717

18-
print($lement->unfold());
18+
print $lement->unfold();
1919

2020
// output: <hello></hello>
2121
```
@@ -25,7 +25,7 @@ You can also go straight to outputting a string.
2525
```php
2626
$element = Element::fold("hello");
2727

28-
print($lement);
28+
print $element;
2929

3030
// output: <hello></hello>
3131
```
@@ -35,7 +35,7 @@ You can add attributes to the elements.
3535
```php
3636
$element = Element::fold("hello")->attr("id my-element");
3737

38-
print($lement);
38+
print $element;
3939

4040
// output: <hello id="my-element"></hello>
4141
```
@@ -47,9 +47,9 @@ If the HTML element is unknown, Markup will fall back to using Element.
4747
```php
4848
$html = Html::p();
4949

50-
print($html->unfold());
50+
print $html->unfold();
5151

52-
print($html);
52+
print $html;
5353
```
5454

5555
There are two ways to create more compound elements (or components at this point). The first example uses `Html` while the second used `UIKit`.
@@ -58,18 +58,18 @@ If the `UIKit` component is unknown, it will fallback to `Html`.
5858

5959
```php
6060
$html = Html::ul(
61-
Html::li("Hello, "),
62-
Html::li("World!")
61+
Html::li("Hello, "),
62+
Html::li("World!")
6363
);
6464

65-
print($html);
65+
print $html;
6666

6767
// output:
6868
// <ul><li>Hello, </li><li>World!</li></ul>
6969

70-
$uikit = UIKit::list(
71-
"Hello, ",
72-
"World!"
70+
$uikit = UIKit::listWith(
71+
"Hello, ",
72+
"World!"
7373
);
7474

7575
print($uikit);

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"require": {
1313
"php": "~7.0",
1414
"8fold/php-shoop-extras": "~0.1",
15+
"8fold/commonmark-abbreviations": "~0.1",
1516
"nesbot/carbon": "~2.36"
1617
},
1718
"require-dev": {

composer.lock

+81-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/UIKit/Elements/Compound/Markdown.php

+65-14
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,83 @@
44

55
use Eightfold\Markup\Html\Elements\HtmlElement;
66

7-
use League\CommonMark\Converter;
8-
use League\CommonMark\DocParser;
9-
use League\CommonMark\Environment;
10-
use League\CommonMark\HtmlRenderer;
11-
use League\CommonMark\Extension\Table\TableExtension;
7+
use League\CommonMark\Extension\{
8+
Table\TableExtension,
9+
TaskList\TaskListExtension
10+
};
1211

1312
use Eightfold\ShoopExtras\Shoop;
1413

1514
class Markdown extends HtmlElement
1615
{
17-
private $config = [
18-
'html_input' => 'strip',
19-
'allow_unsafe_links' => false,
20-
];
16+
private $markdown = "";
17+
private $config = [];
18+
private $caseSensitive = true;
19+
private $markdownReplacements = [];
20+
private $htmlReplacements = [];
21+
private $trim = true;
22+
private $minified = true;
23+
private $extensions = [];
24+
2125

2226
public function __construct(string $markdown, array $config = [])
2327
{
24-
if (count($config) > 0) {
25-
$this->config = $config;
26-
}
28+
$this->config = $config;
2729
$this->markdown = $markdown;
2830
}
2931

32+
public function caseSensitive($caseSensitive = true)
33+
{
34+
$this->caseSensitive = $caseSensitive;
35+
return $this;
36+
}
37+
38+
public function markdownReplacements($replacements = [])
39+
{
40+
$this->markdownReplacements = $replacements;
41+
return $this;
42+
}
43+
44+
public function htmlReplacements($replacements = [])
45+
{
46+
$this->htmlReplacements = $replacements;
47+
return $this;
48+
}
49+
50+
public function trim($trim = true)
51+
{
52+
$this->trim = $trim;
53+
return $this;
54+
}
55+
56+
public function minified($minified = true)
57+
{
58+
$this->minified = $minified;
59+
return $this;
60+
}
61+
62+
public function extensions(...$extensions)
63+
{
64+
$this->extensions = Shoop::array($extensions)->isNotEmpty(function($result, $array) {
65+
return ($result->unfold())
66+
? Shoop::array($array)
67+
: Shoop::array([
68+
TableExtension::class,
69+
TaskListExtension::class
70+
]);
71+
})->noEmpties()->unfold();
72+
return $this;
73+
}
74+
3075
public function unfold(): string
3176
{
32-
return Shoop::markdown($this->markdown)
33-
->html([], [], true, true, $this->config);
77+
return Shoop::markdown($this->markdown, ...$this->extensions)
78+
->html(
79+
$this->markdownReplacements,
80+
$this->htmlReplacements,
81+
$this->caseSensitive,
82+
$this->minified,
83+
$this->config
84+
)->unfold();
3485
}
3586
}

0 commit comments

Comments
 (0)