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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
#
# == About ==
#
# This is my way of making slide-based presentations. In short, it just groups
# Markdown formatting into rectangles and adds options for layout formatting.
# Inside each slide, normal element flow is respected.
# Each slide is the size of a landscape-oriented A4 sheet of paper. Light/dark
# mode settings are respected (of course).
# Currently, this is active only in pages under the "slides" folder.
#
# == ftags ==
#
# &&presentation Must appear before any other presentation ftags.
# It "loads" everything necessary for a presentation, that being
# the navigation bar and logic script (which also inserts the
# custom stylesheet).
# Can be only one per page. Also refer to -- Surroundings --
#
# &&slide Everything following this tag is part of a slide. Each slide is
# presented in the order it appears in.
# &&/slide Ends (the last started) slide.
#
# &&clide Same as &&slide, but everything following is centered
# vertically. Uses flexbox.
# &&/slide Ends (the last started) clide. Not compatible with &&/slide!
#
# &&table Starts a table, where everything following it is formatted as a
# table cell in a row.
# &&ftable Same as &&table, but all colums have the same width.
# &&tarow Ends the last started row and begins a new row.
# Effectively everything following it is on a new row.
# &&/table Ends (the last started) (table row and) table or ftable.
#
# &&linebN Adds a line break (vertical spacing) of N (text) lines.
# Spacing is equivalent to N em.
# Available values for N: 1, 2, 3, 4, 5, 6, 7, 8, 9
#
# &&fontSIZE Changes font size to SIZE, in pixels. Default size is 30px.
# Available values for SIZE: 18, 20, 22, 25, 27, 35
# &&/font Text between &&fontSIZE and &&/font is sized accordingly
#
# &¢ered Center horizontally (only) text.
# &&/centered Text between &¢ered and &&/centered is aligned.
#
# &&fright Aligns following elements and text to the right.
# &&/fright Text between &&fright and &&/fright is aligned to the right
#
# &&cont Basic container with no properties. Useful if you need to group
# multiple elements into one table cell.
# &&/cont Ends (the last started) &&cont
#
# &&widthPER Sets the element's width to be PER percentage. Primarily made
# for images, since perfect scaling is impossible.
# Available values for PER: 5, 10, 15, 20, ..., 90, 95
# &&/width Text between &&widthPER and &&/width is sized accordingly
#
# -- Surroundings --
#
# As stated, there can only be one presentation per page.
# Everything that is around a presentation and it's slides is normally hidden
# during presenting mode and while printing.
#
# -- Placement/Flow --
#
# All ftags can be placed on their own line, or in a line with other ftags.
# The only requirement is that such a line must start with an ftag, ftags in the
# middle of text aren't recognized.
#
# -- Regarding flex --
#
# The older versions of the script, prior to commit
# 687ff3652e5695183ba1691e7d4b94470f8407b3
# used extensively flexbox for element alignment. This was done with the hope that
# spacing out elements evenly and centering them would be very easy, which turned
# out to be false.
#
# Now, the only thing that uses flexbox is &&clide, and it only allows to center
# everything in the slide vertically.
# Vertical centerings for portions of elements can be done with &&linebN, which,
# though imperfect, does the job very well and should suffice.
# Evenly spacing out elements next to each other can be done with &&table and
# &&ftable.
#
# -- Example Usage --
#
# Refer to src/talks/demo/index.md
BEGIN {
nopresentation=!(substr(ARGV[1], "slides") || substr(ARGV[1], "teaching")) # FILENAME isn't available yet
# names is name of ftag, meaning if `names[i] = "examp"` the ftag will be &&examp
# ended specifies how the HTML tag is ended
# `ended[i] = 0` means no closing ftag (so no &&/examp)
# `ended[i] = 1` means &&/examp exists
# `ended[i] = 2` means self-closing, so no &&/examp, but &&examp includes the closing tag
#
# &&examp is usually replaced by `<div class="examp">`
# &&/examp is usually replaced by `</div>`
# in case ended[i] = 2, &&examp is replaced by `<div class="examp"></div>`
# Main elements and exceptions to the normal replace format
names[ 1] = "presentation"
ended[ 1] = 0
names[ 2] = "slide"
ended[ 2] = 1
names[ 3] = "clide"
ended[ 3] = 1
names[ 4] = "table"
ended[ 4] = 1
names[ 5] = "ftable"
ended[ 5] = 0
names[ 6] = "tarow"
ended[ 6] = 0
names[ 7] = "/font" # all font ftags can be closed with a &&/font
ended[ 7] = 0
# Line breaks
names[ 8] = "lineb1"
ended[ 8] = 2
names[ 9] = "lineb2"
ended[ 9] = 2
names[10] = "lineb3"
ended[10] = 2
names[11] = "lineb4"
ended[11] = 2
names[12] = "lineb5"
ended[12] = 2
names[13] = "lineb6"
ended[13] = 2
names[14] = "lineb7"
ended[14] = 2
names[15] = "lineb8"
ended[15] = 2
names[16] = "lineb9"
ended[16] = 2
# Font sizes
names[17] = "font18"
ended[17] = 0
names[18] = "font20"
ended[18] = 0
names[19] = "font22"
ended[19] = 0
names[20] = "font25"
ended[20] = 0
names[21] = "font27"
ended[21] = 0
names[22] = "font35"
ended[22] = 0
# Everything else
names[23] = "centered"
ended[23] = 1
names[24] = "fright"
ended[24] = 1
names[25] = "cont"
ended[25] = 1
names[26] = "/width"
ended[26] = 0
nameslength = 26 # POSIX compatibility: length(names) isn't valid
for (i = 95; i >= 5; i -= 5) {
nameslength++
names[nameslength] = "width" i
ended[nameslength] = 0
}
pres = ORS \
"<nav id=\"presentCont\">" ORS \
" <span id=\"prevSlideBtn\" class=\"btn nodisplay\">\\←</span>" ORS \
" <a id=\"slideIndex\" class=\"nodisplay\" href=\"#slide-0\">0</a>" ORS \
" <span id=\"nextSlideBtn\" class=\"btn nodisplay\">\\→</span>" ORS \
" <span id=\"articleBtn\" class=\"btn setting-btn\">Article view \\☲</span>" ORS \
" <span id=\"presentBtn\" class=\"btn setting-btn\">Present \\⎚</span>" ORS \
" <span id=\"printBtn\" class=\"btn setting-btn\">Print \\⎙</span>" ORS \
" </nav><br><br>" ORS \
" <script type=\"text/javascript\" src=\"/scripts/presentation.js\" crossorigin=\"anonymous\"></script>"
for (i = 1; i <= nameslength; i++) {
pat[i] = "&&" names[i]
rep[i] = "<div class=\"" names[i] "\">"
if (ended[i] == 1) {
cpat[i] = "&&/" names[i]
crep[i] = "</div>"
}
else if (ended[i] == 2) {
rep[i] = rep[i] "</div>"
}
}
rep[ 1] = pres
rep[ 3] = "<div class=\"slide clide\"><div></div><div>" # flex-col + flex:1 + <div>
crep[3] = "</div><div></div></div>" # </div> + flex:1 + /flex-col
rep[ 4] = "<div class=\"layout-table\"><div class=\"layout-row\">" # <table><tr> (layout-row > * is td)
crep[4] = "</div></div>" # </tr><table>
rep[ 5] = "<div class=\"layout-table fixed-layout\"><div class=\"layout-row\">" # <table><tr> (layout-row > * is td)
rep[ 6] = "</div><div class=\"layout-row\">" # </tr><tr>
rep[ 7] = "</div>" # &&/font
rep[26] = "</div>" # &&/width
presInsideCode = 0
slideIndex = 0
}
function presentationSubstitute(ind) {
gsub(/(<p>|<\/p>)/, "")
if ((ind == 2 || ind == 3) && index($0, pat[ind]) != 0) { # &&slide or &&clide
gsub(pat[ind], "<div id=\"slide-" slideIndex "\"" substr(rep[ind], 5))
slideIndex++
}
else {
gsub(pat[ind], rep[ind])
}
if (ended[ind] == 1)
gsub(cpat[ind], crep[ind])
}
nopresentation == 0 && /<code>/ {
presInsideCode = 1
}
nopresentation == 0 && /<\/code>/ {
presInsideCode = 0
}
nopresentation == 0 && presInsideCode == 0 && /^[ \t]*(<p>)?&&/ {
for (i = 1; i <= nameslength; i++) {
if (index($0, names[i]) != 0)
presentationSubstitute(i)
}
}
|