-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
AstroMarkdown.astro
95 lines (94 loc) · 2.51 KB
/
AstroMarkdown.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
import Heading from './Heading.astro';
import DataTable from './table/DataTable.astro'
import MarkdownImage from './image/MarkdownImage.astro'
import Code from './code/Code.astro'
import Tag from './Tag.astro'
import Link from './Link.astro'
import Directive from './directive/Directive.astro'
import ContainerDirective from './directive/ContainerDirective.astro';
import {toHast} from 'mdast-util-to-hast'
import {toHtml} from 'hast-util-to-html'
import {dirname} from 'path'
import {text_only_children,has_image} from './node_check.js'
export interface Props {
node: object;
data: object;
}
const {node, data} = Astro.props;
const handled_types = [ "root","heading","table","paragraph",
"image","code","tag","link",
"list", "listItem","textDirective",
"containerDirective"
]
const other_type = !handled_types.includes(node.type)
data.dirpath = dirname(data.path)
let paragraph_style = "paragraph"
if(node.type == "paragraph"){
if(text_only_children(node)){
paragraph_style = "paragraph text"
}
if(has_image(node)){
paragraph_style = "paragraph image"
}
}
---
{(node.type == "root") &&
<>
{node.children.map((node)=>(
<Astro.self node={node} data={data} />
))}
</>
}
{(node.type == "paragraph") &&
<div class={paragraph_style}>
{node.children.map((node)=>(
<Astro.self node={node} data={data}/>
))}
</div>
}
{(node.type == "containerDirective") &&
<ContainerDirective name={node.name} attributes={node.attributes}>
{node.children.map((node)=>(
<Astro.self node={node} data={data}/>
))}
</ContainerDirective>
}
{(node.type == "list") &&
<ul>
{node.children.map((node)=>(
<Astro.self node={node} data={data}/>
))}
</ul>
}
{(node.type == "listItem") &&
<li>
{node.children.map((node)=>(
<Astro.self node={node} data={data}/>
))}
</li>
}
{(node.type == "heading") &&
<Heading node={node} headings={data.headings}/>
}
{(node.type == "table") &&
<DataTable node={node} />
}
{(node.type == "image") &&
<MarkdownImage node={node} dirpath={data.dirpath}/>
}
{(node.type == "code") &&
<Code node={node} dirpath={data.dirpath}/>
}
{(node.type == "tag") &&
<Tag node={node} />
}
{(node.type == "link") &&
<Link node={node} dirpath={data.dirpath}/>
}
{(node.type == "textDirective") &&
<Directive node={node} dirpath={data.dirpath}/>
}
{other_type &&
<Fragment set:html={toHtml(toHast(node))}></Fragment>
}