flinker-markdown 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/dist/esm/md.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,22 +17,23 @@ npm run dev
|
|
|
17
17
|
|
|
18
18
|
## Example 1
|
|
19
19
|
```ts
|
|
20
|
-
import { md, MDGrammar, MDParser } from "flinker-markdown"
|
|
21
20
|
import { div, TextProps } from "flinker-dom"
|
|
21
|
+
import { md, MDGrammar, MDParser } from "flinker-markdown"
|
|
22
22
|
|
|
23
23
|
interface MarkdownProps extends TextProps {
|
|
24
|
-
absolutePathPrefix?: string
|
|
25
|
-
|
|
24
|
+
absolutePathPrefix?: string //it will be added to the relative path of a media file [<a>, <img>, <audio>, <video>]
|
|
25
|
+
mode: 'md' | 'rawText' | 'rawHtml'
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const
|
|
29
|
-
const parser = new MDParser(grammar)
|
|
28
|
+
const parser = new MDParser(new MDGrammar())
|
|
30
29
|
export const Markdown = () => {
|
|
31
30
|
return div<MarkdownProps>()
|
|
32
31
|
.map(s => {
|
|
33
|
-
if (
|
|
32
|
+
if (s.mode === 'md') {
|
|
34
33
|
s.htmlText = s.text ? md(parser, s.text, s.absolutePathPrefix) : ''
|
|
35
34
|
s.text = ''
|
|
35
|
+
} else if (s.mode === 'rawHtml') {
|
|
36
|
+
s.text = s.text ? md(parser, s.text, s.absolutePathPrefix) : ''
|
|
36
37
|
}
|
|
37
38
|
})
|
|
38
39
|
}
|
package/dist/esm/md.js
CHANGED
|
@@ -59,11 +59,11 @@ export class MDGrammar {
|
|
|
59
59
|
this.code = new MDInlineGrammarRule();
|
|
60
60
|
this.code.matcher = [/``([^`]+)``/g, '<code>$1</code>'];
|
|
61
61
|
this.figure = new MDInlineGrammarRule();
|
|
62
|
-
this.figure.matcher = [/\[img:([^, ]+), ?([^\]]+)\]/
|
|
62
|
+
this.figure.matcher = [/\[img:([^, ]+), ?([^\]]+)\]/g, '<figure><img src="$1"/><figcaption>$2</figcaption></figure>'];
|
|
63
63
|
this.img = new MDInlineGrammarRule();
|
|
64
|
-
this.img.matcher = [/\[img:([^\]]+)\]/
|
|
64
|
+
this.img.matcher = [/\[img:([^\]]+)\]/g, '<img src="$1"/>'];
|
|
65
65
|
this.link = new MDInlineGrammarRule();
|
|
66
|
-
this.link.matcher = [/\[link:([^, ]+),?
|
|
66
|
+
this.link.matcher = [/\[link:([^, \]]+),? *([^\]]*)\]/g, (line, url, descr) => {
|
|
67
67
|
return '<a href="' + url + '">' + (descr || url) + '</a>';
|
|
68
68
|
}];
|
|
69
69
|
this.globalRule.childrenInlineRules = [this.code, this.figure, this.img, this.link, this.sub, this.sup, this.strong, this.boldItalic, this.bold, this.em, this.italic];
|
|
@@ -71,7 +71,7 @@ export class MDGrammar {
|
|
|
71
71
|
// LINE GRAMMAR RULES
|
|
72
72
|
//
|
|
73
73
|
this.header = new MDLineGrammarRule();
|
|
74
|
-
this.header.matcher = [
|
|
74
|
+
this.header.matcher = [/^(#{1,6}) (.*)$/, (line, signs, header) => {
|
|
75
75
|
const count = signs.length;
|
|
76
76
|
return '<h' + count + '>' + header + '</h' + count + '>';
|
|
77
77
|
}];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flinker-markdown",
|
|
3
3
|
"description": "Free TypeScript library for parsing markdown text (customisable, not standardized).",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.11",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/Dittner/FlinkerMD.git"
|