Fossil SCM

Add the help_to_html() routine which transforms plaintext help into HTML for display on web pages. So far it only surrounds the text with <pre>..</pre>. But it can (in theory) be enhanced to do more sophisticated formatting.

drh 2016-09-23 13:53 trunk
Commit 7a69e5db64cd25d06eed411a127553c717839862
1 file changed +33 -19
+33 -19
--- src/dispatch.c
+++ src/dispatch.c
@@ -176,10 +176,36 @@
176176
fossil_print("%s\n\n", aCommand[i].zHelp);
177177
}
178178
fossil_print("---\n");
179179
version_cmd();
180180
}
181
+
182
+/*
183
+** Attempt to reformat plain-text help into HTML for display on a webpage.
184
+**
185
+** The HTML output is appended to Blob pHtml, which should already be
186
+** initialized.
187
+*/
188
+static void help_to_html(const char *zHelp, Blob *pHtml){
189
+ char *s;
190
+ char *d;
191
+ char *z;
192
+
193
+ /* Transform "%fossil" into just "fossil" */
194
+ z = s = d = mprintf("%s", zHelp);
195
+ while( *s ){
196
+ if( *s=='%' && strncmp(s, "%fossil", 7)==0 ){
197
+ s++;
198
+ }else{
199
+ *d++ = *s++;
200
+ }
201
+ }
202
+ *d = 0;
203
+
204
+ blob_appendf(pHtml, "<pre>\n%h\n</pre>\n", z);
205
+ fossil_free(z);
206
+}
181207
182208
/*
183209
** WEBPAGE: help
184210
** URL: /help?name=CMD
185211
**
@@ -191,11 +217,10 @@
191217
192218
if( zCmd==0 ) zCmd = P("name");
193219
style_header("Command-line Help");
194220
if( zCmd ){
195221
int rc;
196
- char *z, *s, *d;
197222
const CmdOrPage *pCmd = 0;
198223
199224
style_submenu_element("Command-List", "Command-List", "%s/help", g.zTop);
200225
if( *zCmd=='/' ){
201226
/* Some of the webpages require query parameters in order to work.
@@ -208,27 +233,16 @@
208233
if( rc==1 ){
209234
@ unknown command: %s(zCmd)
210235
}else if( rc==2 ){
211236
@ ambiguous command prefix: %s(zCmd)
212237
}else{
213
- z = (char*)pCmd->zHelp;
214
- if( z[0]==0 ){
238
+ if( pCmd->zHelp[0]==0 ){
215239
@ no help available for the %s(pCmd->zName) command
216240
}else{
217
- z=s=d=mprintf("%s",z);
218
- while( *s ){
219
- if( *s=='%' && strncmp(s, "%fossil", 7)==0 ){
220
- s++;
221
- }else{
222
- *d++ = *s++;
223
- }
224
- }
225
- *d = 0;
226
- @ <blockquote><pre>
227
- @ %h(z)
228
- @ </pre></blockquote>
229
- fossil_free(z);
241
+ @ <blockquote>
242
+ help_to_html(pCmd->zHelp, cgi_output_blob());
243
+ @ </blockquote>
230244
}
231245
}
232246
}else{
233247
int i, j, n;
234248
@@ -331,13 +345,13 @@
331345
int i;
332346
style_header("Testpage: All Help Text");
333347
for(i=0; i<MX_COMMAND; i++){
334348
if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue;
335349
@ <h2>%s(aCommand[i].zName):</h2>
336
- @ <blockquote><pre>
337
- @ %h(aCommand[i].zHelp)
338
- @ </pre></blockquote>
350
+ @ <blockquote>
351
+ help_to_html(aCommand[i].zHelp, cgi_output_blob());
352
+ @ </blockquote>
339353
}
340354
style_footer();
341355
}
342356
343357
static void multi_column_list(const char **azWord, int nWord){
344358
--- src/dispatch.c
+++ src/dispatch.c
@@ -176,10 +176,36 @@
176 fossil_print("%s\n\n", aCommand[i].zHelp);
177 }
178 fossil_print("---\n");
179 version_cmd();
180 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
182 /*
183 ** WEBPAGE: help
184 ** URL: /help?name=CMD
185 **
@@ -191,11 +217,10 @@
191
192 if( zCmd==0 ) zCmd = P("name");
193 style_header("Command-line Help");
194 if( zCmd ){
195 int rc;
196 char *z, *s, *d;
197 const CmdOrPage *pCmd = 0;
198
199 style_submenu_element("Command-List", "Command-List", "%s/help", g.zTop);
200 if( *zCmd=='/' ){
201 /* Some of the webpages require query parameters in order to work.
@@ -208,27 +233,16 @@
208 if( rc==1 ){
209 @ unknown command: %s(zCmd)
210 }else if( rc==2 ){
211 @ ambiguous command prefix: %s(zCmd)
212 }else{
213 z = (char*)pCmd->zHelp;
214 if( z[0]==0 ){
215 @ no help available for the %s(pCmd->zName) command
216 }else{
217 z=s=d=mprintf("%s",z);
218 while( *s ){
219 if( *s=='%' && strncmp(s, "%fossil", 7)==0 ){
220 s++;
221 }else{
222 *d++ = *s++;
223 }
224 }
225 *d = 0;
226 @ <blockquote><pre>
227 @ %h(z)
228 @ </pre></blockquote>
229 fossil_free(z);
230 }
231 }
232 }else{
233 int i, j, n;
234
@@ -331,13 +345,13 @@
331 int i;
332 style_header("Testpage: All Help Text");
333 for(i=0; i<MX_COMMAND; i++){
334 if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue;
335 @ <h2>%s(aCommand[i].zName):</h2>
336 @ <blockquote><pre>
337 @ %h(aCommand[i].zHelp)
338 @ </pre></blockquote>
339 }
340 style_footer();
341 }
342
343 static void multi_column_list(const char **azWord, int nWord){
344
--- src/dispatch.c
+++ src/dispatch.c
@@ -176,10 +176,36 @@
176 fossil_print("%s\n\n", aCommand[i].zHelp);
177 }
178 fossil_print("---\n");
179 version_cmd();
180 }
181
182 /*
183 ** Attempt to reformat plain-text help into HTML for display on a webpage.
184 **
185 ** The HTML output is appended to Blob pHtml, which should already be
186 ** initialized.
187 */
188 static void help_to_html(const char *zHelp, Blob *pHtml){
189 char *s;
190 char *d;
191 char *z;
192
193 /* Transform "%fossil" into just "fossil" */
194 z = s = d = mprintf("%s", zHelp);
195 while( *s ){
196 if( *s=='%' && strncmp(s, "%fossil", 7)==0 ){
197 s++;
198 }else{
199 *d++ = *s++;
200 }
201 }
202 *d = 0;
203
204 blob_appendf(pHtml, "<pre>\n%h\n</pre>\n", z);
205 fossil_free(z);
206 }
207
208 /*
209 ** WEBPAGE: help
210 ** URL: /help?name=CMD
211 **
@@ -191,11 +217,10 @@
217
218 if( zCmd==0 ) zCmd = P("name");
219 style_header("Command-line Help");
220 if( zCmd ){
221 int rc;
 
222 const CmdOrPage *pCmd = 0;
223
224 style_submenu_element("Command-List", "Command-List", "%s/help", g.zTop);
225 if( *zCmd=='/' ){
226 /* Some of the webpages require query parameters in order to work.
@@ -208,27 +233,16 @@
233 if( rc==1 ){
234 @ unknown command: %s(zCmd)
235 }else if( rc==2 ){
236 @ ambiguous command prefix: %s(zCmd)
237 }else{
238 if( pCmd->zHelp[0]==0 ){
 
239 @ no help available for the %s(pCmd->zName) command
240 }else{
241 @ <blockquote>
242 help_to_html(pCmd->zHelp, cgi_output_blob());
243 @ </blockquote>
 
 
 
 
 
 
 
 
 
 
244 }
245 }
246 }else{
247 int i, j, n;
248
@@ -331,13 +345,13 @@
345 int i;
346 style_header("Testpage: All Help Text");
347 for(i=0; i<MX_COMMAND; i++){
348 if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue;
349 @ <h2>%s(aCommand[i].zName):</h2>
350 @ <blockquote>
351 help_to_html(aCommand[i].zHelp, cgi_output_blob());
352 @ </blockquote>
353 }
354 style_footer();
355 }
356
357 static void multi_column_list(const char **azWord, int nWord){
358

Keyboard Shortcuts

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