Fossil

Check-in [cdbf0bf1]
Login

Check-in [cdbf0bf1]

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

Overview
Comment:Simplify the HTML block tag handling in the markdown formatter. (See forum thread 3f0136cd80.) Dramatically reduce the number of of HTML block tags that do not apply markdown formatting to their content. The list is now just <pre> and <script>. Formerly this list include things like <p> and <table>.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cdbf0bf179989a2dffbaab0748112b634f95867ec9cc370c042a00db3a5b3345
User & Date: drh 2021-08-06 23:23:22
References
2021-08-07
10:33
Fix an uninitialized variable resulting from check-in [cdbf0bf179989a2d]. ... (check-in: a099ccfe user: drh tags: trunk)
Context
2021-08-06
23:39
Minor internal doc fixes. ... (check-in: b473ba07 user: stephan tags: trunk)
23:23
Simplify the HTML block tag handling in the markdown formatter. (See forum thread 3f0136cd80.) Dramatically reduce the number of of HTML block tags that do not apply markdown formatting to their content. The list is now just <pre> and <script>. Formerly this list include things like <p> and <table>. ... (check-in: cdbf0bf1 user: drh tags: trunk)
2021-08-05
17:06
Minor doc fix for previous commit. No code changes. ... (check-in: 04a9e74a user: stephan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/markdown.c.

169
170
171
172
173
174
175
176





177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211



/********************
 * GLOBAL VARIABLES *
 ********************/

/* block_tags -- recognised block tags, sorted by cmp_html_tag */





static const struct html_tag block_tags[] = {
  { "p",            1 },
  { "dl",           2 },
  { "h1",           2 },
  { "h2",           2 },
  { "h3",           2 },
  { "h4",           2 },
  { "h5",           2 },
  { "h6",           2 },
  { "ol",           2 },
  { "ul",           2 },
  { "del",          3 },
  { "div",          3 },
  { "ins",          3 },
  { "pre",          3 },
  { "form",         4 },
  { "math",         4 },
  { "table",        5 },
  { "iframe",       6 },
  { "script",       6 },
  { "fieldset",     8 },
  { "noscript",     8 },
  { "blockquote",  10 }
};

#define INS_TAG (block_tags + 12)
#define DEL_TAG (block_tags + 10)



/***************************
 * STATIC HELPER FUNCTIONS *
 ***************************/

/* build_ref_id -- collapse whitespace from input text to make it a ref id */







|
>
>
>
>
>

<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
<
<

<
<
<

<
<
<
<







169
170
171
172
173
174
175
176
177
178
179
180
181
182













183




184



185




186
187
188
189
190
191
192



/********************
 * GLOBAL VARIABLES *
 ********************/

/* block_tags -- recognised block tags, sorted by cmp_html_tag.
**
** When these HTML tags are separated from other text by newlines
** then they are rendered verbatim.  Their content is not interpreted
** in any way.
*/
static const struct html_tag block_tags[] = {













  { "pre",          3 },




  { "script",       6 },



};






/***************************
 * STATIC HELPER FUNCTIONS *
 ***************************/

/* build_ref_id -- collapse whitespace from input text to make it a ref id */
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
      }
    }

    /* no special case recognised */
    return 0;
  }

  /* looking for an unindented matching closing tag */
  /*  followed by a blank line */
  i = 1;
  found = 0;
#if 0
  while( i<size ){
    i++;
    while( i<size && !(data[i-2]=='\n' && data[i-1]=='<' && data[i]=='/') ){
      i++;
    }
    if( (i+2+curtag->size)>=size ) break;
    j = htmlblock_end(curtag, data+i-1, size-i+1);
    if (j) {
      i += j-1;
      found = 1;
      break;
    }
  }
#endif

  /* if not found, trying a second pass looking for indented match */
  /* but not if tag is "ins" or "del" (following original Markdown.pl) */
  if( !found && curtag!=INS_TAG && curtag!=DEL_TAG ){
    i = 1;
    while( i<size ){
      i++;
      while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }
      if( (i+2+curtag->size)>=size ) break;
      j = htmlblock_end(curtag, data+i-1, size-i+1);
      if (j) {
        i += j-1;
        found = 1;
        break;
      }
    }
  }

  if( !found ) return 0;

  /* the end of the block has been found */
  blob_init(&work, data, i);
  if( rndr->make.blockhtml ){
    rndr->make.blockhtml(ob, &work, rndr->make.opaque);
  }







|
|

<
<


|
<
<








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1776
1777
1778
1779
1780
1781
1782
1783
1784
1785


1786
1787
1788


1789
1790
1791
1792
1793
1794
1795
1796



















1797
1798
1799
1800
1801
1802
1803
      }
    }

    /* no special case recognised */
    return 0;
  }

  /* looking for an matching closing tag */
  /* followed by a blank line */
  i = 1;


  while( i<size ){
    i++;
    while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }


    if( (i+2+curtag->size)>=size ) break;
    j = htmlblock_end(curtag, data+i-1, size-i+1);
    if (j) {
      i += j-1;
      found = 1;
      break;
    }
  }



















  if( !found ) return 0;

  /* the end of the block has been found */
  blob_init(&work, data, i);
  if( rndr->make.blockhtml ){
    rndr->make.blockhtml(ob, &work, rndr->make.opaque);
  }