Fossil

Check-in [d407c384]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Do not duplicate markdown titles in the title of the page and in the body of the document.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d407c3842116e163fce36055c3998e08731fc6f9
User & Date: drh 2015-12-03 15:19:39
Context
2015-12-03
15:41
Improved cross-linking of clusters. check-in: 24606598 user: drh tags: trunk
15:19
Do not duplicate markdown titles in the title of the page and in the body of the document. check-in: d407c384 user: drh tags: trunk
15:07
When markdown begins with a <h1> HTML element, consider the content of that element to be the title of the document. check-in: cc7f4df4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/markdown_html.c.

    98     98     INTER_BLOCK(ob);
    99     99     BLOB_APPEND_LITERAL(ob, "</div>\n");
   100    100   }
   101    101   
   102    102   static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){
   103    103     char *data = blob_buffer(text);
   104    104     size_t size = blob_size(text);
          105  +  Blob *title = (Blob*)opaque;
   105    106     while( size>0 && fossil_isspace(data[0]) ){ data++; size--; }
   106    107     while( size>0 && fossil_isspace(data[size-1]) ){ size--; }
   107    108     /* If the first raw block is an <h1> element, then use it as the title. */
   108    109     if( blob_size(ob)<=PROLOG_SIZE
   109    110      && size>9
          111  +   && title!=0
   110    112      && sqlite3_strnicmp("<h1",data,3)==0
   111    113      && sqlite3_strnicmp("</h1>", &data[size-5],5)==0
   112    114     ){
   113         -    Blob *title = (Blob*)opaque;
   114    115       int nTag = htmlTagLength(data);
   115    116       blob_append(title, data+nTag, size - nTag - 5);
          117  +    return;
   116    118     }
   117    119     INTER_BLOCK(ob);
   118    120     blob_append(ob, data, size);
   119    121     BLOB_APPEND_LITERAL(ob, "\n");
   120    122   }
   121    123   
   122    124   static void html_blockcode(struct Blob *ob, struct Blob *text, void *opaque){
................................................................................
   138    140     struct Blob *text,
   139    141     int level,
   140    142     void *opaque
   141    143   ){
   142    144     struct Blob *title = opaque;
   143    145     /* The first header at the beginning of a text is considered as
   144    146      * a title and not output. */
   145         -  if( blob_size(ob)<=PROLOG_SIZE && blob_size(title)==0 ){
          147  +  if( blob_size(ob)<=PROLOG_SIZE && title!=0 && blob_size(title)==0 ){
   146    148       BLOB_APPEND_BLOB(title, text);
          149  +    return;
   147    150     }
   148    151     INTER_BLOCK(ob);
   149    152     blob_appendf(ob, "<h%d>", level);
   150    153     BLOB_APPEND_BLOB(ob, text);
   151    154     blob_appendf(ob, "</h%d>", level);
   152    155   }
   153    156   
................................................................................
   379    382   }
   380    383   
   381    384   
   382    385   static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){
   383    386     html_escape(ob, blob_buffer(text), blob_size(text));
   384    387   }
   385    388   
   386         -
          389  +/*
          390  +** Convert markdown into HTML.
          391  +**
          392  +** The document title is placed in output_title if not NULL.  Or if
          393  +** output_title is NULL, the document title appears in the body.
          394  +*/
   387    395   void markdown_to_html(
   388         -  struct Blob *input_markdown,
   389         -  struct Blob *output_title,
   390         -  struct Blob *output_body
          396  +  struct Blob *input_markdown,   /* Markdown content to be rendered */
          397  +  struct Blob *output_title,     /* Put title here.  May be NULL */
          398  +  struct Blob *output_body       /* Put document body here. */
   391    399   ){
   392    400     struct mkd_renderer html_renderer = {
   393    401       /* prolog and epilog */
   394    402       html_prolog,
   395    403       html_epilog,
   396    404   
   397    405       /* block level elements */
................................................................................
   424    432   
   425    433       /* misc. parameters */
   426    434       64, /* maximum stack */
   427    435       "*_", /* emphasis characters */
   428    436       0 /* opaque data */
   429    437     };
   430    438     html_renderer.opaque = output_title;
   431         -  blob_reset(output_title);
          439  +  if( output_title ) blob_reset(output_title);
   432    440     blob_reset(output_body);
   433    441     markdown(output_body, input_markdown, &html_renderer);
   434    442   }

Changes to src/wiki.c.

   145    145   **   text/x-markdown         Markdown
   146    146   **   anything else...        Plain text
   147    147   */
   148    148   void wiki_render_by_mimetype(Blob *pWiki, const char *zMimetype){
   149    149     if( zMimetype==0 || fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){
   150    150       wiki_convert(pWiki, 0, 0);
   151    151     }else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){
   152         -    Blob title = BLOB_INITIALIZER;
   153    152       Blob tail = BLOB_INITIALIZER;
   154         -    markdown_to_html(pWiki, &title, &tail);
   155         -#if 0
   156         -    if( blob_size(&title)>0 ){
   157         -      @ <h1>%s(blob_str(&title))</h1>
   158         -    }
   159         -#endif
          153  +    markdown_to_html(pWiki, 0, &tail);
   160    154       @ %s(blob_str(&tail))
   161         -    blob_reset(&title);
   162    155       blob_reset(&tail);
   163    156     }else{
   164    157       @ <pre>
   165    158       @ %h(blob_str(pWiki))
   166    159       @ </pre>
   167    160     }
   168    161   }