|
|
@@ -1,6 +1,100 @@
|
|
1
|
1
|
# Markdown Library
|
|
2
|
2
|
|
|
|
3
|
+A markdown library with parallel Javascript and PHP implementations. Supports
|
|
|
4
|
+modular "readers" for customizing the flavor of markdown desired, including
|
|
|
5
|
+making custom modules. Javascript implementation is vanilla Javascript with
|
|
|
6
|
+no dependencies. PHP implementation is written for 8.3 but may work on older
|
|
|
7
|
+versions (only dependency is PHPUnit if running tests).
|
|
|
8
|
+
|
|
|
9
|
+## Usage - JS
|
|
|
10
|
+
|
|
|
11
|
+Copy [markdown.js](js/markdown.js) (or [markdown.min.js](js/markdown.min.js))
|
|
|
12
|
+into your project and include with a `<script src="markdown.js"></script>` tag
|
|
|
13
|
+in your HTML. That's it.
|
|
|
14
|
+
|
|
|
15
|
+To use, create a parser with:
|
|
|
16
|
+
|
|
|
17
|
+```javascript
|
|
|
18
|
+const myParser = new Markdown(); // defaults to standard syntax
|
|
|
19
|
+
|
|
|
20
|
+// or with a custom set of readers
|
|
|
21
|
+const myParser = new Markdown([
|
|
|
22
|
+ new MDParagraphReader(),
|
|
|
23
|
+ new MDStrongReader(),
|
|
|
24
|
+ new MDEmphasisReader(),
|
|
|
25
|
+]);
|
|
|
26
|
+
|
|
|
27
|
+// or use one of the two premade parsers
|
|
|
28
|
+const myParser = Markdown.standardParser; // for a basic set of common syntaxes
|
|
|
29
|
+const myParser = Markdown.completeParser; // for all supported syntaxes (except line breaks)
|
|
|
30
|
+```
|
|
|
31
|
+
|
|
|
32
|
+Then convert markdown to HTML with:
|
|
|
33
|
+
|
|
|
34
|
+```javascript
|
|
|
35
|
+const html = myParser.toHTML("Your **markdown** here.");
|
|
|
36
|
+```
|
|
|
37
|
+
|
|
|
38
|
+## Usage - PHP
|
|
|
39
|
+
|
|
|
40
|
+As with Javascript, simply copy [markdown.php](php/markdown.php) into your
|
|
|
41
|
+project and `require` it in your source.
|
|
|
42
|
+
|
|
|
43
|
+To use, create a parser with:
|
|
|
44
|
+
|
|
|
45
|
+```php
|
|
|
46
|
+$myParser = new Markdown(); // defaults to standard syntax
|
|
|
47
|
+
|
|
|
48
|
+// or with a custom set of readers
|
|
|
49
|
+$myParser = new Markdown([
|
|
|
50
|
+ new MDParagraphReader(),
|
|
|
51
|
+ new MDStrongReader(),
|
|
|
52
|
+ new MDEmphasisReader(),
|
|
|
53
|
+]);
|
|
|
54
|
+
|
|
|
55
|
+// or use one of the two premade parsers
|
|
|
56
|
+$myParser = Markdown::standardParser(); // for a basic set of common syntaxes
|
|
|
57
|
+$myParser = Markdown::completeParser(); // for all supported syntaxes (except line breaks)
|
|
|
58
|
+```
|
|
|
59
|
+
|
|
|
60
|
+Then convert markdown to HTML with:
|
|
|
61
|
+
|
|
|
62
|
+```php
|
|
|
63
|
+$html = $myParser->toHTML("Your **markdown** here.");
|
|
|
64
|
+```
|
|
|
65
|
+
|
|
|
66
|
+## Spreadsheets
|
|
|
67
|
+
|
|
|
68
|
+One innovation in this markdown library is the ability to include _greatly
|
|
|
69
|
+simplified_ spreadsheet expressions in markdown tables. Intended for simple
|
|
|
70
|
+formulas and sums. To use, include [spreadsheet.js](js/spreadsheet.js) or
|
|
|
71
|
+[spreadsheet.php](php/spreadsheet.php) in your project along with the regular
|
|
|
72
|
+markdown source and include `MDSpreadsheetReader` in your `Markdown` instance.
|
|
|
73
|
+
|
|
|
74
|
+Example:
|
|
|
75
|
+
|
|
|
76
|
+```markdown
|
|
|
77
|
+| Name | Unit Price | Qty | Discount | Subtotal |
|
|
|
78
|
+| ----- | ---------: | --: | -------: | --------------: |
|
|
|
79
|
+| Apple | $0.99 | 2 | | =B*C*(1-D) FILL |
|
|
|
80
|
+| Pear | $1.09 | 1 | 10% | |
|
|
|
81
|
+| **TOTAL** | | | | =SUM(E:E) |
|
|
|
82
|
+```
|
|
|
83
|
+
|
|
|
84
|
+can render as:
|
|
|
85
|
+
|
|
|
86
|
+<table>
|
|
|
87
|
+<thead>
|
|
|
88
|
+<tr><th>Name</th><th>Unit Price</th><th>Qty</th><th>Discount</th><th>Subtotal</th></tr>
|
|
|
89
|
+</thead>
|
|
|
90
|
+<tbody>
|
|
|
91
|
+<tr><td>Apple</td><td style="text-align: right;">$0.99</td><td style="text-align: right;">2</td><td></td><td style="text-align: right;">$1.98</td></tr>
|
|
|
92
|
+<tr><td>Pear</td><td style="text-align: right;">$1.09</td><td style="text-align: right;">1</td><td style="text-align: right;">10%</td><td style="text-align: right;">$0.98</td></tr>
|
|
|
93
|
+<tr><td><strong>TOTAL</strong></td><td></td><td></td><td></td><td style="text-align: right;">$3.07</td></tr>
|
|
|
94
|
+</table>
|
|
|
95
|
+
|
|
|
96
|
+## More info
|
|
|
97
|
+
|
|
3
|
98
|
* [Markdown syntax reference](markdown.md)
|
|
|
99
|
+* [Table spreadsheet formulas](spreadsheet.md)
|
|
4
|
100
|
* [Creating custom syntax](custom.md)
|
|
5
|
|
-
|
|
6
|
|
-Minified versions of source created with `terser --compress --mangle`.
|