forked from neenjaw/compile-mermaid-markdown-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert-markdown.awk
56 lines (41 loc) · 1.07 KB
/
insert-markdown.awk
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
# n -- is to work on the nth code block
# rel_path -- is the relative path to the file
# hide_codeblocks -- is a flag to hide the markup with a details tag
BEGIN {
i=0;
start_comment="<!-- generated by mermaid compile action - START -->";
end_comment="<!-- generated by mermaid compile action - END -->";
link="![~mermaid diagram " n "~](" path ")";
}
# Rules to erase old generated code
($0 ~ start_comment && i+1 == n) {in_generated_block=1; next}
($0 ~ end_comment && in_generated_block) {in_generated_block=0; next}
# increment the block counter
(/```mermaid/) {i++}
# Found the block to work on
(/```mermaid/ && i == n) {
print start_comment;
print link;
if (hide_codeblocks) {
print "<details>";
print " <summary>Mermaid markup</summary>";
details_tag_open=1;
}
print "";
print;
in_code_block=1;
next;
}
(in_code_block && /```/) {
print;
print "";
if (details_tag_open) {
print "</details>";
details_tag_open=0;
}
print end_comment;
in_code_block=0;
next;
}
(in_generated_block && !in_code_block) {next}
{print}