Skip to content

Commit d0cbc9e

Browse files
committed
Initial commit
0 parents  commit d0cbc9e

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# editor detritus
2+
.*sw?
3+
*~
4+
5+
# Finder turds
6+
.DS_Store

markin

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/awk -f
2+
##
3+
## markin - interpolate shell script into Markdown files
4+
##
5+
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
6+
## Date: 12 March 2022
7+
## Homepage: https://github.com/ernstki/markin
8+
## License: MIT
9+
##
10+
BEGIN { loop_max = 10 }
11+
12+
# <!-- {{{begin
13+
/^ *<!-- *{+begin */ {
14+
c = LOOP_MAX
15+
i = 0
16+
print; getline
17+
18+
# }}} -->
19+
while (!/^ *}+ *--> *$/) {
20+
print
21+
cmd = "$SHELL -c '" $0 "'"
22+
23+
while (cmd | getline) {
24+
output[i++] = $0
25+
}
26+
27+
close(cmd)
28+
# “…[W]hen a file or pipe is opened for output, awk remembers the file
29+
# name or command associated with it, and subsequent writes to the same
30+
# file or command are appended to the previous writes. The file or pipe
31+
# stays open until awk exits.
32+
#
33+
# This implies that special steps are necessary in order to read the
34+
# same file again from the beginning, or to rerun a shell command
35+
# (rather than reading more output from the same command). The close()
36+
# function makes these things possible[.]”
37+
#
38+
# -- https://www.gnu.org/software/gawk/manual/html_node/Getline_002fPipe.html
39+
40+
c -= 1
41+
if (c == 0) {
42+
print "ERROR: Runaway loop looking for '}}}-->'. " > "/dev/stderr"
43+
exit 1
44+
}
45+
46+
getline
47+
} # while not '}}}'
48+
49+
} # within {{{begin …}}}
50+
51+
# }}} -->
52+
/^ *}+ *--> *$/ {
53+
print; getline
54+
c = LOOP_MAX
55+
56+
# <!-- {{{end}}} -->
57+
while (!/^ *<!-- *{+end}+ *--> *$/) {
58+
c -= 1
59+
if (c == 0) {
60+
print "ERROR: Runaway loop looking for '<!--{{{end}}}-->'. " > "/dev/stderr"
61+
exit 1
62+
}
63+
64+
getline
65+
}
66+
67+
# the order of `for (l in output)` is not defined by POSIX, so…
68+
# print "**Lines in putput: " length(output)
69+
for (i = 0; i < length(output); i++) {
70+
print output[i]
71+
}
72+
73+
delete output
74+
}
75+
76+
{
77+
# otherwise
78+
print
79+
}

test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Beginning stuff:
2+
<!-- {{{begin
3+
echo "Hello world!"
4+
}}} -->
5+
whatever was there before
6+
<!-- {{{end}}} -->
7+
8+
Ending stuff:
9+
<!-- {{{begin
10+
echo "-------"
11+
echo "THE END"
12+
echo "-------"
13+
}}} -->
14+
whatever was there before
15+
<!-- {{{end}}} -->

test_with_single_quotes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Beginning stuff:
2+
<!-- {{{begin
3+
echo "Top of the mornin' to ya's!"
4+
}}} -->
5+
whatever was there before
6+
<!-- {{{end}}} -->
7+
8+
Ending stuff:
9+
<!-- {{{begin
10+
echo "-------"
11+
echo "THE END"
12+
echo "-------"
13+
}}} -->
14+
whatever was there before
15+
<!-- {{{end}}} -->

0 commit comments

Comments
 (0)