Fossil SCM

Simplify the HTML block tag handling in the markdown formatter. (See [forum:/forumpost/3f0136cd8054a14e|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>.

drh 2021-08-06 23:23 trunk
Commit cdbf0bf179989a2dffbaab0748112b634f95867ec9cc370c042a00db3a5b3345
1 file changed +9 -51
+9 -51
--- src/markdown.c
+++ src/markdown.c
@@ -171,39 +171,20 @@
171171
172172
/********************
173173
* GLOBAL VARIABLES *
174174
********************/
175175
176
-/* block_tags -- recognised block tags, sorted by cmp_html_tag */
176
+/* block_tags -- recognised block tags, sorted by cmp_html_tag.
177
+**
178
+** When these HTML tags are separated from other text by newlines
179
+** then they are rendered verbatim. Their content is not interpreted
180
+** in any way.
181
+*/
177182
static const struct html_tag block_tags[] = {
178
- { "p", 1 },
179
- { "dl", 2 },
180
- { "h1", 2 },
181
- { "h2", 2 },
182
- { "h3", 2 },
183
- { "h4", 2 },
184
- { "h5", 2 },
185
- { "h6", 2 },
186
- { "ol", 2 },
187
- { "ul", 2 },
188
- { "del", 3 },
189
- { "div", 3 },
190
- { "ins", 3 },
191183
{ "pre", 3 },
192
- { "form", 4 },
193
- { "math", 4 },
194
- { "table", 5 },
195
- { "iframe", 6 },
196184
{ "script", 6 },
197
- { "fieldset", 8 },
198
- { "noscript", 8 },
199
- { "blockquote", 10 }
200185
};
201
-
202
-#define INS_TAG (block_tags + 12)
203
-#define DEL_TAG (block_tags + 10)
204
-
205186
206187
207188
/***************************
208189
* STATIC HELPER FUNCTIONS *
209190
***************************/
@@ -1797,47 +1778,24 @@
17971778
17981779
/* no special case recognised */
17991780
return 0;
18001781
}
18011782
1802
- /* looking for an unindented matching closing tag */
1803
- /* followed by a blank line */
1783
+ /* looking for an matching closing tag */
1784
+ /* followed by a blank line */
18041785
i = 1;
1805
- found = 0;
1806
-#if 0
18071786
while( i<size ){
18081787
i++;
1809
- while( i<size && !(data[i-2]=='\n' && data[i-1]=='<' && data[i]=='/') ){
1810
- i++;
1811
- }
1788
+ while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }
18121789
if( (i+2+curtag->size)>=size ) break;
18131790
j = htmlblock_end(curtag, data+i-1, size-i+1);
18141791
if (j) {
18151792
i += j-1;
18161793
found = 1;
18171794
break;
18181795
}
18191796
}
1820
-#endif
1821
-
1822
- /* if not found, trying a second pass looking for indented match */
1823
- /* but not if tag is "ins" or "del" (following original Markdown.pl) */
1824
- if( !found && curtag!=INS_TAG && curtag!=DEL_TAG ){
1825
- i = 1;
1826
- while( i<size ){
1827
- i++;
1828
- while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }
1829
- if( (i+2+curtag->size)>=size ) break;
1830
- j = htmlblock_end(curtag, data+i-1, size-i+1);
1831
- if (j) {
1832
- i += j-1;
1833
- found = 1;
1834
- break;
1835
- }
1836
- }
1837
- }
1838
-
18391797
if( !found ) return 0;
18401798
18411799
/* the end of the block has been found */
18421800
blob_init(&work, data, i);
18431801
if( rndr->make.blockhtml ){
18441802
--- src/markdown.c
+++ src/markdown.c
@@ -171,39 +171,20 @@
171
172 /********************
173 * GLOBAL VARIABLES *
174 ********************/
175
176 /* block_tags -- recognised block tags, sorted by cmp_html_tag */
 
 
 
 
 
177 static const struct html_tag block_tags[] = {
178 { "p", 1 },
179 { "dl", 2 },
180 { "h1", 2 },
181 { "h2", 2 },
182 { "h3", 2 },
183 { "h4", 2 },
184 { "h5", 2 },
185 { "h6", 2 },
186 { "ol", 2 },
187 { "ul", 2 },
188 { "del", 3 },
189 { "div", 3 },
190 { "ins", 3 },
191 { "pre", 3 },
192 { "form", 4 },
193 { "math", 4 },
194 { "table", 5 },
195 { "iframe", 6 },
196 { "script", 6 },
197 { "fieldset", 8 },
198 { "noscript", 8 },
199 { "blockquote", 10 }
200 };
201
202 #define INS_TAG (block_tags + 12)
203 #define DEL_TAG (block_tags + 10)
204
205
206
207 /***************************
208 * STATIC HELPER FUNCTIONS *
209 ***************************/
@@ -1797,47 +1778,24 @@
1797
1798 /* no special case recognised */
1799 return 0;
1800 }
1801
1802 /* looking for an unindented matching closing tag */
1803 /* followed by a blank line */
1804 i = 1;
1805 found = 0;
1806 #if 0
1807 while( i<size ){
1808 i++;
1809 while( i<size && !(data[i-2]=='\n' && data[i-1]=='<' && data[i]=='/') ){
1810 i++;
1811 }
1812 if( (i+2+curtag->size)>=size ) break;
1813 j = htmlblock_end(curtag, data+i-1, size-i+1);
1814 if (j) {
1815 i += j-1;
1816 found = 1;
1817 break;
1818 }
1819 }
1820 #endif
1821
1822 /* if not found, trying a second pass looking for indented match */
1823 /* but not if tag is "ins" or "del" (following original Markdown.pl) */
1824 if( !found && curtag!=INS_TAG && curtag!=DEL_TAG ){
1825 i = 1;
1826 while( i<size ){
1827 i++;
1828 while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }
1829 if( (i+2+curtag->size)>=size ) break;
1830 j = htmlblock_end(curtag, data+i-1, size-i+1);
1831 if (j) {
1832 i += j-1;
1833 found = 1;
1834 break;
1835 }
1836 }
1837 }
1838
1839 if( !found ) return 0;
1840
1841 /* the end of the block has been found */
1842 blob_init(&work, data, i);
1843 if( rndr->make.blockhtml ){
1844
--- src/markdown.c
+++ src/markdown.c
@@ -171,39 +171,20 @@
171
172 /********************
173 * GLOBAL VARIABLES *
174 ********************/
175
176 /* block_tags -- recognised block tags, sorted by cmp_html_tag.
177 **
178 ** When these HTML tags are separated from other text by newlines
179 ** then they are rendered verbatim. Their content is not interpreted
180 ** in any way.
181 */
182 static const struct html_tag block_tags[] = {
 
 
 
 
 
 
 
 
 
 
 
 
 
183 { "pre", 3 },
 
 
 
 
184 { "script", 6 },
 
 
 
185 };
 
 
 
 
186
187
188 /***************************
189 * STATIC HELPER FUNCTIONS *
190 ***************************/
@@ -1797,47 +1778,24 @@
1778
1779 /* no special case recognised */
1780 return 0;
1781 }
1782
1783 /* looking for an matching closing tag */
1784 /* followed by a blank line */
1785 i = 1;
 
 
1786 while( i<size ){
1787 i++;
1788 while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }
 
 
1789 if( (i+2+curtag->size)>=size ) break;
1790 j = htmlblock_end(curtag, data+i-1, size-i+1);
1791 if (j) {
1792 i += j-1;
1793 found = 1;
1794 break;
1795 }
1796 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1797 if( !found ) return 0;
1798
1799 /* the end of the block has been found */
1800 blob_init(&work, data, i);
1801 if( rndr->make.blockhtml ){
1802

Keyboard Shortcuts

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