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.
Commit
7a69e5db64cd25d06eed411a127553c717839862
Parent
3ca2bc105a9c9a2…
1 file changed
+33
-19
+33
-19
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -176,10 +176,36 @@ | ||
| 176 | 176 | fossil_print("%s\n\n", aCommand[i].zHelp); |
| 177 | 177 | } |
| 178 | 178 | fossil_print("---\n"); |
| 179 | 179 | version_cmd(); |
| 180 | 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 | +} | |
| 181 | 207 | |
| 182 | 208 | /* |
| 183 | 209 | ** WEBPAGE: help |
| 184 | 210 | ** URL: /help?name=CMD |
| 185 | 211 | ** |
| @@ -191,11 +217,10 @@ | ||
| 191 | 217 | |
| 192 | 218 | if( zCmd==0 ) zCmd = P("name"); |
| 193 | 219 | style_header("Command-line Help"); |
| 194 | 220 | if( zCmd ){ |
| 195 | 221 | int rc; |
| 196 | - char *z, *s, *d; | |
| 197 | 222 | const CmdOrPage *pCmd = 0; |
| 198 | 223 | |
| 199 | 224 | style_submenu_element("Command-List", "Command-List", "%s/help", g.zTop); |
| 200 | 225 | if( *zCmd=='/' ){ |
| 201 | 226 | /* Some of the webpages require query parameters in order to work. |
| @@ -208,27 +233,16 @@ | ||
| 208 | 233 | if( rc==1 ){ |
| 209 | 234 | @ unknown command: %s(zCmd) |
| 210 | 235 | }else if( rc==2 ){ |
| 211 | 236 | @ ambiguous command prefix: %s(zCmd) |
| 212 | 237 | }else{ |
| 213 | - z = (char*)pCmd->zHelp; | |
| 214 | - if( z[0]==0 ){ | |
| 238 | + if( pCmd->zHelp[0]==0 ){ | |
| 215 | 239 | @ no help available for the %s(pCmd->zName) command |
| 216 | 240 | }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> | |
| 230 | 244 | } |
| 231 | 245 | } |
| 232 | 246 | }else{ |
| 233 | 247 | int i, j, n; |
| 234 | 248 | |
| @@ -331,13 +345,13 @@ | ||
| 331 | 345 | int i; |
| 332 | 346 | style_header("Testpage: All Help Text"); |
| 333 | 347 | for(i=0; i<MX_COMMAND; i++){ |
| 334 | 348 | if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue; |
| 335 | 349 | @ <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> | |
| 339 | 353 | } |
| 340 | 354 | style_footer(); |
| 341 | 355 | } |
| 342 | 356 | |
| 343 | 357 | static void multi_column_list(const char **azWord, int nWord){ |
| 344 | 358 |
| --- 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 |