flinker-markdown 1.1.0 → 1.1.2
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 +29 -3
- package/dist/esm/md.js +13 -5
- package/dist/types/md.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
## Intro
|
|
2
2
|
__FlinkerMD__ (MD) is a TypeScript library for parsing markdown text into html.
|
|
3
3
|
|
|
4
|
-
See demo:
|
|
5
|
-
[](https://wiki.archlinux.org/title/Installation_guide)
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
```cli
|
|
9
7
|
npm i flinker-markdown
|
|
10
8
|
```
|
|
11
9
|
|
|
12
|
-
## Example
|
|
10
|
+
## Example 1
|
|
13
11
|
```ts
|
|
12
|
+
import { md, MDGrammar, MDParser } from "flinker-markdown"
|
|
13
|
+
import { div, TextProps } from "flinker-dom"
|
|
14
|
+
|
|
14
15
|
interface MarkdownProps extends TextProps {
|
|
15
16
|
absolutePathPrefix?: string
|
|
16
17
|
showRawText?: boolean
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
const grammar = new MDGrammar()
|
|
19
21
|
const parser = new MDParser(grammar)
|
|
20
22
|
export const Markdown = () => {
|
|
21
23
|
return div<MarkdownProps>()
|
|
@@ -28,5 +30,29 @@ export const Markdown = () => {
|
|
|
28
30
|
}
|
|
29
31
|
```
|
|
30
32
|
|
|
33
|
+
## Example 2: Custom grammar rule
|
|
34
|
+
Parsing Bash code:
|
|
35
|
+
```ts
|
|
36
|
+
const grammar = new MDGrammar()
|
|
37
|
+
const bash = new MDLineGrammarRule()
|
|
38
|
+
bash.matcher = [/^>>> /, '> '] // begin text with symbols >>> to tranform line to bash code
|
|
39
|
+
bash.postProccessing = highlightBashCode // define highlight-func: (v: string) => string
|
|
40
|
+
grammar.globalRule.childrenLineRules.splice(0, 0, bash)
|
|
41
|
+
grammar.ol.childrenLineRules.splice(0, 0, bash) // allow lists to include bash code
|
|
42
|
+
grammar.ul.childrenLineRules.splice(0, 0, bash)
|
|
43
|
+
|
|
44
|
+
const parser = new MDParser(grammar)
|
|
45
|
+
export const Markdown = () => {...}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
highlightBashCode-func transforms text from e.g.:
|
|
49
|
+
```html
|
|
50
|
+
>>> npm run install
|
|
51
|
+
```
|
|
52
|
+
to the tokenized form:
|
|
53
|
+
```html
|
|
54
|
+
<pre class="bashcode-dark"><code class="md-dark"><span class="op">> </span><span class="bash-cmd">npm </span><span class="bash-param">run </span><span class="bash-param">install</span></code></pre>
|
|
55
|
+
```
|
|
56
|
+
|
|
31
57
|
## License
|
|
32
58
|
MIT
|
package/dist/esm/md.js
CHANGED
|
@@ -41,8 +41,14 @@ export class MDGrammar {
|
|
|
41
41
|
//
|
|
42
42
|
// INLINE GRAMMAR RULES
|
|
43
43
|
//
|
|
44
|
+
this.sup = new MDInlineGrammarRule();
|
|
45
|
+
this.sup.matcher = [/\^\{([^}]+)\}/g, '<sup>$1</sup>'];
|
|
46
|
+
this.sub = new MDInlineGrammarRule();
|
|
47
|
+
this.sub.matcher = [/_\{([^}]+)\}/g, '<sub>$1</sub>'];
|
|
44
48
|
this.strong = new MDInlineGrammarRule();
|
|
45
|
-
this.strong.matcher = [
|
|
49
|
+
this.strong.matcher = [/\*([^*]+)\*/g, '<strong>$1</strong>'];
|
|
50
|
+
this.boldItalic = new MDInlineGrammarRule();
|
|
51
|
+
this.boldItalic.matcher = [/_{3,}([^_]+)_{3,}/g, '<b><i>$1</i></b>'];
|
|
46
52
|
this.bold = new MDInlineGrammarRule();
|
|
47
53
|
this.bold.matcher = [/_{2,}([^_]+)_{2,}/g, '<b>$1</b>'];
|
|
48
54
|
this.italic = new MDInlineGrammarRule();
|
|
@@ -55,12 +61,14 @@ export class MDGrammar {
|
|
|
55
61
|
this.figure = new MDInlineGrammarRule();
|
|
56
62
|
this.figure.matcher = [/!\[([^\]]+)\]\(([^)]+)\)\(([^)]+)\)/gm, '<figure><img alt="$1" src="$2"/><figcaption>$3</figcaption></figure>'];
|
|
57
63
|
this.img = new MDInlineGrammarRule();
|
|
58
|
-
this.img.matcher = [
|
|
64
|
+
this.img.matcher = [/\[img:([^ ]+) ?([^\]]*)\]/gm, '<img src="$1" alt="$2"/>'];
|
|
59
65
|
this.link = new MDInlineGrammarRule();
|
|
60
|
-
this.link.matcher = [/\[([^\]]*)\]
|
|
66
|
+
this.link.matcher = [/\[link:([^ ]+) ?([^\]]*)\]/, (line, url, descr) => {
|
|
61
67
|
return '<a href="' + url + '">' + (descr || url) + '</a>';
|
|
62
68
|
}];
|
|
63
|
-
this.
|
|
69
|
+
this.audio = new MDInlineGrammarRule();
|
|
70
|
+
this.audio.matcher = [/\[audio:([^\]]+)\]/, '<audio controls src="$1"></audio>'];
|
|
71
|
+
this.globalRule.childrenInlineRules = [this.code, this.figure, this.img, this.link, this.audio, this.sub, this.sup, this.strong, this.boldItalic, this.bold, this.em, this.italic];
|
|
64
72
|
//
|
|
65
73
|
// LINE GRAMMAR RULES
|
|
66
74
|
//
|
|
@@ -69,7 +77,7 @@ export class MDGrammar {
|
|
|
69
77
|
const count = signs.length;
|
|
70
78
|
return '<h' + count + '>' + header + '</h' + count + '>';
|
|
71
79
|
}];
|
|
72
|
-
this.header.childrenInlineRules = [this.strong, this.bold, this.italic];
|
|
80
|
+
this.header.childrenInlineRules = [this.strong, this.boldItalic, this.bold, this.italic];
|
|
73
81
|
this.header.preProccessing = defLinePreproccessing;
|
|
74
82
|
this.quote = new MDLineGrammarRule();
|
|
75
83
|
this.quote.matcher = [/^> (.*)$/, '<blockquote><p>$1</p></blockquote>'];
|
package/dist/types/md.d.ts
CHANGED
|
@@ -24,14 +24,18 @@ export declare class MDMultilineGrammarRule {
|
|
|
24
24
|
}
|
|
25
25
|
export declare class MDGrammar {
|
|
26
26
|
readonly globalRule: GlobalGrammarRule;
|
|
27
|
+
readonly sup: MDInlineGrammarRule;
|
|
28
|
+
readonly sub: MDInlineGrammarRule;
|
|
27
29
|
readonly strong: MDInlineGrammarRule;
|
|
28
30
|
readonly bold: MDInlineGrammarRule;
|
|
29
31
|
readonly italic: MDInlineGrammarRule;
|
|
32
|
+
readonly boldItalic: MDInlineGrammarRule;
|
|
30
33
|
readonly em: MDInlineGrammarRule;
|
|
31
34
|
readonly code: MDInlineGrammarRule;
|
|
32
35
|
readonly figure: MDInlineGrammarRule;
|
|
33
36
|
readonly img: MDInlineGrammarRule;
|
|
34
37
|
readonly link: MDInlineGrammarRule;
|
|
38
|
+
readonly audio: MDInlineGrammarRule;
|
|
35
39
|
readonly header: MDLineGrammarRule;
|
|
36
40
|
readonly quote: MDLineGrammarRule;
|
|
37
41
|
readonly alignRight: MDLineGrammarRule;
|
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.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/Dittner/FlinkerMD.git"
|