@@ -32,6 +32,8 @@ elif (len(args) == 2 && args(1) == "bas") then
3232 mk_bas(in_map)
3333elif (len(args) == 2 && args( 1 ) == "jekyll" ) then
3434 mk_jekyll(in_map)
35+ elif (len(args) == 2 && args( 1 ) == "markdown" ) then
36+ mk_markdown(in_map)
3537elif (len(args) == 2 && args( 1 ) == "test" ) then
3638 mk_test(in_map)
3739else
@@ -76,6 +78,23 @@ func fix_comments_jekyll(comments, keyword)
7678 fix_comments_jekyll = comments
7779end
7880
81+ func fix_comments_pandoc(comments, keyword)
82+ comments = translate(comments, "<code>" , chr( 10 ) + "~~~" + chr( 10 ))
83+ comments = translate(comments, "<?code>" , chr( 10 ) + "~~~" + chr( 10 ))
84+ comments = translate(comments, "</code>" , chr( 10 ) + "~~~" + chr( 10 ))
85+ comments = translate(comments, "<strong>" , "**" )
86+ comments = translate(comments, "</strong" , "**" )
87+ comments = translate(comments, "<cite>" , "" )
88+ comments = translate(comments, "</cite" , "" )
89+ comments = translate(comments, "<blockquote>" , "> " )
90+ comments = translate(comments, "</blockquote>" , "" )
91+ comments = translate(comments, "</blockqoute>" , "" )
92+ comments = translate(comments, "p. " , "" )
93+ comments = translate(comments, "bc. " , "> " )
94+ comments = fix_comments(comments, keyword)
95+ return comments
96+ end
97+
7998sub mk_bas( byref in_map)
8099 local i, row, group , keyword
81100 local in_map_len = len(in_map) - 1
166185' local test: $ bundle exec jekyll serve
167186'
168187sub mk_jekyll( byref in_map)
169- local i, row , group , type , keyword , syntax , brief , comments , buffer , fname
188+ local i, row, group , type, keyword, syntax, brief, comments, buffer, filename
170189 local in_map_len = len(in_map) - 1
171190 local end_block = "<!-- end heading block -->"
172191 dim buffer
@@ -203,8 +222,136 @@ sub mk_jekyll(byref in_map)
203222 i++
204223 buffer << fix_comments_jekyll(in_map(i).comment_body_value, keyword)
205224 wend
206- fname = " 2016-06-04-" + lower (group ) + " -" + lower (keyword ) + " .markdown"
207- tsave fname, buffer
225+ filename = "2016-06-04-" + lower( group ) + "-" + lower(keyword) + ".markdown"
226+ tsave filename, buffer
227+ next i
228+ end
229+
230+ '
231+ ' must contain at least 3 | chars
232+ '
233+ func is_table(s)
234+ local z
235+ z = instr( 0 , s, "|" )
236+ if (z!= 1 ) then return false
237+
238+ z = instr(z, s, "|" )
239+ if (z== 0 ) then return false
240+
241+ z = instr(z, s, "|" )
242+ if (z== 0 ) then return false
243+
244+ return true
245+ end
246+
247+ '
248+ ' generate the table pattern
249+ '
250+ func table_markdown(s)
251+ local result = ""
252+ local s_len = len(s)
253+ local i
254+ for i = 1 to s_len
255+ if (mid(s, i, 1 ) == "|" ) then
256+ result += " "
257+ else
258+ result += "-"
259+ endif
260+ next i
261+ return result
262+ end
263+
264+ '
265+ ' convert textile to markdown
266+ '
267+ func table_row(table_md, s)
268+ local out = trim(leftoflast(rightof(s, "|" ), "|" ))
269+ local j = instr(table_md, " " )
270+ local x = instr( out , "|" )
271+ local n = max( 1 , j - x)
272+ return translate( out , "|" , space(n))
273+ end
274+
275+ '
276+ ' convert textile to markdown
277+ '
278+ func update_tables( byref in_str)
279+ local in_table = false
280+ local table_md = ""
281+ local out = ""
282+ local row, rows
283+
284+ split in_str, chr( 10 ), rows
285+ for row in rows
286+ if (is_table(row)) then
287+ if (!in_table) then
288+ table_md = ltrim(table_markdown(row))
289+ in_table = true
290+ out += table_md
291+ out += chr( 10 )
292+ endif
293+ out += table_row(table_md, row)
294+ else
295+ if (in_table) then
296+ out += table_md
297+ out += chr( 10 )
298+ in_table = false
299+ endif
300+ out += row
301+ endif
302+ out += chr( 10 )
303+ next row
304+ return out
305+ end
306+
307+ '
308+ ' make post files for smallbasic.github.io
309+ '
310+ sub mk_markdown( byref in_map)
311+ local i, row, group , type, keyword, syntax, brief, comments, buffer, filename
312+ local in_map_len = len(in_map) - 1
313+ local end_block = "<!-- end heading block -->"
314+
315+ sub append_buf(s)
316+ buffer += s
317+ buffer += chr( 10 )
318+ end
319+
320+ for i = 0 to in_map_len
321+ buffer= ""
322+ row = in_map(i).body_value
323+ group = get_field(row, "group=" , false )
324+ type = get_field(row, "type=" , false )
325+ keyword = get_field(row, "keyword=" , false )
326+ syntax = get_field(row, "syntax=" , false )
327+ brief = get_field(row, "brief=" , false )
328+ append_buf( "# " + keyword)
329+ append_buf( "" )
330+ append_buf( "> " + syntax)
331+ append_buf( "" )
332+ append_buf(brief)
333+ append_buf( "" )
334+ pos = instr(row, end_block) + len(end_block)
335+ if (pos < len(row)) then
336+ append_buf(fix_comments_pandoc(mid(row, pos), keyword))
337+ endif
338+ comments = in_map(i).comment_body_value
339+ if (comments != "NULL" ) then
340+ append_buf(fix_comments_pandoc(comments, keyword))
341+ endif
342+ while (i + 1 < in_map_len && in_map(i).entity_id == in_map(i + 1 ).entity_id)
343+ i++
344+ append_buf(fix_comments_pandoc(in_map(i).comment_body_value, keyword))
345+ wend
346+
347+ filename = in_map(i).entity_id + "-" + lower( group ) + "-" + lower(keyword) + ".markdown"
348+ filename = translate(filename, " " , "" )
349+ buffer = update_tables(buffer)
350+
351+ if (len(filename) > 200 ) then
352+ filename = in_map(i).entity_id + ".markdown"
353+ endif
354+ tsave filename, buffer
208355 next i
209356end
210357
0 commit comments