Fossil SCM

Add the 'markdown' command to TH1.

mistachkin 2015-07-19 18:34 trunk
Commit f6d29e9c3d2863c63b1dc401d49441fed82e2d11
--- src/th_main.c
+++ src/th_main.c
@@ -337,10 +337,40 @@
337337
return Th_WrongNumArgs(interp, "puts STRING");
338338
}
339339
sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
340340
return TH_OK;
341341
}
342
+
343
+/*
344
+** TH1 command: markdown STRING
345
+**
346
+** Renders the input string as markdown. The result is a two-element list.
347
+** The first element is the text-only title string. The second element
348
+** contains the body, rendered as HTML.
349
+*/
350
+static int markdownCmd(
351
+ Th_Interp *interp,
352
+ void *p,
353
+ int argc,
354
+ const char **argv,
355
+ int *argl
356
+){
357
+ Blob src, title, body;
358
+ char *zValue = 0;
359
+ int nValue = 0;
360
+ if( argc!=2 ){
361
+ return Th_WrongNumArgs(interp, "markdown STRING");
362
+ }
363
+ blob_zero(&src);
364
+ blob_init(&src, (char*)argv[1], argl[1]);
365
+ blob_zero(&title); blob_zero(&body);
366
+ markdown_to_html(&src, &title, &body);
367
+ Th_ListAppend(interp, &zValue, &nValue, blob_str(&title), blob_size(&title));
368
+ Th_ListAppend(interp, &zValue, &nValue, blob_str(&body), blob_size(&body));
369
+ Th_SetResult(interp, zValue, nValue);
370
+ return TH_OK;
371
+}
342372
343373
/*
344374
** TH1 command: decorate STRING
345375
** TH1 command: wiki STRING
346376
**
@@ -1613,10 +1643,11 @@
16131643
{"hasfeature", hasfeatureCmd, 0},
16141644
{"html", putsCmd, (void*)&aFlags[0]},
16151645
{"htmlize", htmlizeCmd, 0},
16161646
{"http", httpCmd, 0},
16171647
{"linecount", linecntCmd, 0},
1648
+ {"markdown", markdownCmd, 0},
16181649
{"puts", putsCmd, (void*)&aFlags[1]},
16191650
{"query", queryCmd, 0},
16201651
{"randhex", randhexCmd, 0},
16211652
{"regexp", regexpCmd, 0},
16221653
{"reinitialize", reinitializeCmd, 0},
16231654
--- src/th_main.c
+++ src/th_main.c
@@ -337,10 +337,40 @@
337 return Th_WrongNumArgs(interp, "puts STRING");
338 }
339 sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
340 return TH_OK;
341 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
343 /*
344 ** TH1 command: decorate STRING
345 ** TH1 command: wiki STRING
346 **
@@ -1613,10 +1643,11 @@
1613 {"hasfeature", hasfeatureCmd, 0},
1614 {"html", putsCmd, (void*)&aFlags[0]},
1615 {"htmlize", htmlizeCmd, 0},
1616 {"http", httpCmd, 0},
1617 {"linecount", linecntCmd, 0},
 
1618 {"puts", putsCmd, (void*)&aFlags[1]},
1619 {"query", queryCmd, 0},
1620 {"randhex", randhexCmd, 0},
1621 {"regexp", regexpCmd, 0},
1622 {"reinitialize", reinitializeCmd, 0},
1623
--- src/th_main.c
+++ src/th_main.c
@@ -337,10 +337,40 @@
337 return Th_WrongNumArgs(interp, "puts STRING");
338 }
339 sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
340 return TH_OK;
341 }
342
343 /*
344 ** TH1 command: markdown STRING
345 **
346 ** Renders the input string as markdown. The result is a two-element list.
347 ** The first element is the text-only title string. The second element
348 ** contains the body, rendered as HTML.
349 */
350 static int markdownCmd(
351 Th_Interp *interp,
352 void *p,
353 int argc,
354 const char **argv,
355 int *argl
356 ){
357 Blob src, title, body;
358 char *zValue = 0;
359 int nValue = 0;
360 if( argc!=2 ){
361 return Th_WrongNumArgs(interp, "markdown STRING");
362 }
363 blob_zero(&src);
364 blob_init(&src, (char*)argv[1], argl[1]);
365 blob_zero(&title); blob_zero(&body);
366 markdown_to_html(&src, &title, &body);
367 Th_ListAppend(interp, &zValue, &nValue, blob_str(&title), blob_size(&title));
368 Th_ListAppend(interp, &zValue, &nValue, blob_str(&body), blob_size(&body));
369 Th_SetResult(interp, zValue, nValue);
370 return TH_OK;
371 }
372
373 /*
374 ** TH1 command: decorate STRING
375 ** TH1 command: wiki STRING
376 **
@@ -1613,10 +1643,11 @@
1643 {"hasfeature", hasfeatureCmd, 0},
1644 {"html", putsCmd, (void*)&aFlags[0]},
1645 {"htmlize", htmlizeCmd, 0},
1646 {"http", httpCmd, 0},
1647 {"linecount", linecntCmd, 0},
1648 {"markdown", markdownCmd, 0},
1649 {"puts", putsCmd, (void*)&aFlags[1]},
1650 {"query", queryCmd, 0},
1651 {"randhex", randhexCmd, 0},
1652 {"regexp", regexpCmd, 0},
1653 {"reinitialize", reinitializeCmd, 0},
1654
+76 -2
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,14 @@
1616
############################################################################
1717
#
1818
# TH1 Commands
1919
#
2020
21
+set dir [file dirname [info script]]
22
+
23
+###############################################################################
24
+
2125
fossil test-th-eval --open-config "setting th1-hooks"
2226
set th1Hooks [expr {$RESULT eq "1"}]
2327
2428
###############################################################################
2529
@@ -859,12 +863,12 @@
859863
#
860864
fossil test-th-eval "info commands"
861865
test th1-info-commands-1 {$RESULT eq {linecount htmlize date stime\
862866
enable_output uplevel http expr glob_match utime styleFooter catch if\
863867
tclReady searchable reinitialize combobox lindex query html anoncap randhex\
864
-llength for set break regexp styleHeader puts return checkout decorate\
865
-artifact trace wiki proc hascap globalState continue getParameter\
868
+llength for set break regexp markdown styleHeader puts return checkout\
869
+decorate artifact trace wiki proc hascap globalState continue getParameter\
866870
hasfeature setting lsearch breakpoint upvar render repository string unset\
867871
setParameter list error info rename anycap httpize}}
868872
869873
###############################################################################
870874
@@ -1171,5 +1175,75 @@
11711175
11721176
###############################################################################
11731177
11741178
fossil test-th-eval {string is integer 0xC0DEF00Z}
11751179
test th1-string-is-31 {$RESULT eq "0"}
1180
+
1181
+###############################################################################
1182
+
1183
+fossil test-th-eval {markdown}
1184
+test th1-markdown-1 {$RESULT eq \
1185
+{TH_ERROR: wrong # args: should be "markdown STRING"}}
1186
+
1187
+###############################################################################
1188
+
1189
+fossil test-th-eval {markdown one two}
1190
+test th1-markdown-2 {$RESULT eq \
1191
+{TH_ERROR: wrong # args: should be "markdown STRING"}}
1192
+
1193
+###############################################################################
1194
+
1195
+fossil test-th-eval {markdown "*This is a test.*"}
1196
+test th1-markdown-3 {[normalize_result] eq {{} {<div class="markdown">
1197
+
1198
+<p><em>This is a test.</em></p>
1199
+
1200
+</div>
1201
+}}}
1202
+
1203
+###############################################################################
1204
+
1205
+fossil test-th-eval {markdown "Test1\n=====\n*This is a test.*"}
1206
+test th1-markdown-4 {[normalize_result] eq {Test1 {<div class="markdown">
1207
+
1208
+<h1>Test1</h1>
1209
+<p><em>This is a test.</em></p>
1210
+
1211
+</div>
1212
+}}}
1213
+
1214
+###############################################################################
1215
+
1216
+set markdown [read_file [file join $dir markdown-test1.md]]
1217
+fossil test-th-eval [string map \
1218
+ [list %markdown% $markdown] {markdown {%markdown%}}]
1219
+test th1-markdown-5 {[normalize_result] eq \
1220
+{{Markdown Formatter Test Document} {<div class="markdown">
1221
+
1222
+<h1>Markdown Formatter Test Document</h1>
1223
+<p>This document is designed to test the markdown formatter.</p>
1224
+
1225
+<ul>
1226
+<li>A bullet item.
1227
+
1228
+<ul>
1229
+<li>A subitem</li>
1230
+</ul></li>
1231
+<li>Second bullet</li>
1232
+</ul>
1233
+
1234
+<p>More text</p>
1235
+
1236
+<ol>
1237
+<li>Enumeration
1238
+1.1. Subitem 1
1239
+1.2. Subitem 2</li>
1240
+<li>Second enumeration.</li>
1241
+</ol>
1242
+
1243
+<p>Another paragraph.</p>
1244
+
1245
+<h2>Other Features</h2>
1246
+<p>Text can show <em>emphasis</em> or <em>emphasis</em> or <strong>strong emphassis</strong>.</p>
1247
+
1248
+</div>
1249
+}}}
11761250
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,14 @@
16 ############################################################################
17 #
18 # TH1 Commands
19 #
20
 
 
 
 
21 fossil test-th-eval --open-config "setting th1-hooks"
22 set th1Hooks [expr {$RESULT eq "1"}]
23
24 ###############################################################################
25
@@ -859,12 +863,12 @@
859 #
860 fossil test-th-eval "info commands"
861 test th1-info-commands-1 {$RESULT eq {linecount htmlize date stime\
862 enable_output uplevel http expr glob_match utime styleFooter catch if\
863 tclReady searchable reinitialize combobox lindex query html anoncap randhex\
864 llength for set break regexp styleHeader puts return checkout decorate\
865 artifact trace wiki proc hascap globalState continue getParameter\
866 hasfeature setting lsearch breakpoint upvar render repository string unset\
867 setParameter list error info rename anycap httpize}}
868
869 ###############################################################################
870
@@ -1171,5 +1175,75 @@
1171
1172 ###############################################################################
1173
1174 fossil test-th-eval {string is integer 0xC0DEF00Z}
1175 test th1-string-is-31 {$RESULT eq "0"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1176
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,14 @@
16 ############################################################################
17 #
18 # TH1 Commands
19 #
20
21 set dir [file dirname [info script]]
22
23 ###############################################################################
24
25 fossil test-th-eval --open-config "setting th1-hooks"
26 set th1Hooks [expr {$RESULT eq "1"}]
27
28 ###############################################################################
29
@@ -859,12 +863,12 @@
863 #
864 fossil test-th-eval "info commands"
865 test th1-info-commands-1 {$RESULT eq {linecount htmlize date stime\
866 enable_output uplevel http expr glob_match utime styleFooter catch if\
867 tclReady searchable reinitialize combobox lindex query html anoncap randhex\
868 llength for set break regexp markdown styleHeader puts return checkout\
869 decorate artifact trace wiki proc hascap globalState continue getParameter\
870 hasfeature setting lsearch breakpoint upvar render repository string unset\
871 setParameter list error info rename anycap httpize}}
872
873 ###############################################################################
874
@@ -1171,5 +1175,75 @@
1175
1176 ###############################################################################
1177
1178 fossil test-th-eval {string is integer 0xC0DEF00Z}
1179 test th1-string-is-31 {$RESULT eq "0"}
1180
1181 ###############################################################################
1182
1183 fossil test-th-eval {markdown}
1184 test th1-markdown-1 {$RESULT eq \
1185 {TH_ERROR: wrong # args: should be "markdown STRING"}}
1186
1187 ###############################################################################
1188
1189 fossil test-th-eval {markdown one two}
1190 test th1-markdown-2 {$RESULT eq \
1191 {TH_ERROR: wrong # args: should be "markdown STRING"}}
1192
1193 ###############################################################################
1194
1195 fossil test-th-eval {markdown "*This is a test.*"}
1196 test th1-markdown-3 {[normalize_result] eq {{} {<div class="markdown">
1197
1198 <p><em>This is a test.</em></p>
1199
1200 </div>
1201 }}}
1202
1203 ###############################################################################
1204
1205 fossil test-th-eval {markdown "Test1\n=====\n*This is a test.*"}
1206 test th1-markdown-4 {[normalize_result] eq {Test1 {<div class="markdown">
1207
1208 <h1>Test1</h1>
1209 <p><em>This is a test.</em></p>
1210
1211 </div>
1212 }}}
1213
1214 ###############################################################################
1215
1216 set markdown [read_file [file join $dir markdown-test1.md]]
1217 fossil test-th-eval [string map \
1218 [list %markdown% $markdown] {markdown {%markdown%}}]
1219 test th1-markdown-5 {[normalize_result] eq \
1220 {{Markdown Formatter Test Document} {<div class="markdown">
1221
1222 <h1>Markdown Formatter Test Document</h1>
1223 <p>This document is designed to test the markdown formatter.</p>
1224
1225 <ul>
1226 <li>A bullet item.
1227
1228 <ul>
1229 <li>A subitem</li>
1230 </ul></li>
1231 <li>Second bullet</li>
1232 </ul>
1233
1234 <p>More text</p>
1235
1236 <ol>
1237 <li>Enumeration
1238 1.1. Subitem 1
1239 1.2. Subitem 2</li>
1240 <li>Second enumeration.</li>
1241 </ol>
1242
1243 <p>Another paragraph.</p>
1244
1245 <h2>Other Features</h2>
1246 <p>Text can show <em>emphasis</em> or <em>emphasis</em> or <strong>strong emphassis</strong>.</p>
1247
1248 </div>
1249 }}}
1250
--- www/changes.wiki
+++ www/changes.wiki
@@ -4,11 +4,12 @@
44
* Fix --hard option to mv/rm to enable them to work properly with certain
55
relative paths.
66
* Make the clean command undoable for files less than 10MiB.
77
* Add minimal <nowiki>[lsearch]</nowiki> command to TH1. Only exact
88
case-sensitive matching is supported.
9
- * Add the <nowiki>[glob_match]</nowiki> command to TH1.
9
+ * Add the <nowiki>[glob_match]</nowiki> and <nowiki>[markdown]</nowiki>
10
+ commands to TH1.
1011
* Add the <nowiki>[tclIsSafe] and [tclMakeSafe]</nowiki> TH1 commands to
1112
the Tcl integration subsystem.
1213
* Add 'double', 'integer', and 'list' classes to the
1314
<nowiki>[string is]</nowiki> command in TH1.
1415
* Update internal Unicode character tables, used in regular expression
1516
--- www/changes.wiki
+++ www/changes.wiki
@@ -4,11 +4,12 @@
4 * Fix --hard option to mv/rm to enable them to work properly with certain
5 relative paths.
6 * Make the clean command undoable for files less than 10MiB.
7 * Add minimal <nowiki>[lsearch]</nowiki> command to TH1. Only exact
8 case-sensitive matching is supported.
9 * Add the <nowiki>[glob_match]</nowiki> command to TH1.
 
10 * Add the <nowiki>[tclIsSafe] and [tclMakeSafe]</nowiki> TH1 commands to
11 the Tcl integration subsystem.
12 * Add 'double', 'integer', and 'list' classes to the
13 <nowiki>[string is]</nowiki> command in TH1.
14 * Update internal Unicode character tables, used in regular expression
15
--- www/changes.wiki
+++ www/changes.wiki
@@ -4,11 +4,12 @@
4 * Fix --hard option to mv/rm to enable them to work properly with certain
5 relative paths.
6 * Make the clean command undoable for files less than 10MiB.
7 * Add minimal <nowiki>[lsearch]</nowiki> command to TH1. Only exact
8 case-sensitive matching is supported.
9 * Add the <nowiki>[glob_match]</nowiki> and <nowiki>[markdown]</nowiki>
10 commands to TH1.
11 * Add the <nowiki>[tclIsSafe] and [tclMakeSafe]</nowiki> TH1 commands to
12 the Tcl integration subsystem.
13 * Add 'double', 'integer', and 'list' classes to the
14 <nowiki>[string is]</nowiki> command in TH1.
15 * Update internal Unicode character tables, used in regular expression
16
+9 -2
--- www/th1.md
+++ www/th1.md
@@ -139,10 +139,11 @@
139139
* html
140140
* htmlize
141141
* http
142142
* httpize
143143
* linecount
144
+ * markdown
144145
* puts
145146
* query
146147
* randhex
147148
* regexp
148149
* reinitialize
@@ -348,12 +349,18 @@
348349
<a name="linecount"></a>TH1 linecount Command
349350
---------------------------------------------
350351
351352
* linecount STRING MAX MIN
352353
353
-Returns one more than the number of \n characters in STRING. But
354
-never returns less than MIN or more than MAX.
354
+<a name="markdown"></a>TH1 markdown Command
355
+---------------------------------------------
356
+
357
+ * markdown STRING
358
+
359
+Renders the input string as markdown. The result is a two-element list.
360
+The first element contains the body, rendered as HTML. The second element
361
+is the text-only title string.
355362
356363
<a name="puts"></a>TH1 puts Command
357364
-----------------------------------
358365
359366
* puts STRING
360367
--- www/th1.md
+++ www/th1.md
@@ -139,10 +139,11 @@
139 * html
140 * htmlize
141 * http
142 * httpize
143 * linecount
 
144 * puts
145 * query
146 * randhex
147 * regexp
148 * reinitialize
@@ -348,12 +349,18 @@
348 <a name="linecount"></a>TH1 linecount Command
349 ---------------------------------------------
350
351 * linecount STRING MAX MIN
352
353 Returns one more than the number of \n characters in STRING. But
354 never returns less than MIN or more than MAX.
 
 
 
 
 
 
355
356 <a name="puts"></a>TH1 puts Command
357 -----------------------------------
358
359 * puts STRING
360
--- www/th1.md
+++ www/th1.md
@@ -139,10 +139,11 @@
139 * html
140 * htmlize
141 * http
142 * httpize
143 * linecount
144 * markdown
145 * puts
146 * query
147 * randhex
148 * regexp
149 * reinitialize
@@ -348,12 +349,18 @@
349 <a name="linecount"></a>TH1 linecount Command
350 ---------------------------------------------
351
352 * linecount STRING MAX MIN
353
354 <a name="markdown"></a>TH1 markdown Command
355 ---------------------------------------------
356
357 * markdown STRING
358
359 Renders the input string as markdown. The result is a two-element list.
360 The first element contains the body, rendered as HTML. The second element
361 is the text-only title string.
362
363 <a name="puts"></a>TH1 puts Command
364 -----------------------------------
365
366 * puts STRING
367

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button