Fossil SCM

Enhance the markdown formatter to ignore certain HTML tags such as <style>.

drh 2020-06-01 07:01 trunk
Commit a3ab0c6186b43236eb1143d3921d9e0f747fe3a7707163ba35dbfde83295e5d3
1 file changed +33 -29
+33 -29
--- src/markdown.c
+++ src/markdown.c
@@ -163,48 +163,45 @@
163163
164164
/* html_tag -- structure for quick HTML tag search (inspired from discount) */
165165
struct html_tag {
166166
const char *text;
167167
int size;
168
+ int flags;
168169
};
169170
171
+/* Allowed bits in html_tag.flags */
172
+#define HTMLTAG_FORBIDDEN 0x001 /* escape */
170173
171174
172175
/********************
173176
* GLOBAL VARIABLES *
174177
********************/
175178
176179
/* block_tags -- recognised block tags, sorted by cmp_html_tag */
177180
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 }
181
+ { "p", 1, 0 },
182
+ { "dl", 2, 0 },
183
+ { "h1", 2, 0 },
184
+ { "h2", 2, 0 },
185
+ { "h3", 2, 0 },
186
+ { "h4", 2, 0 },
187
+ { "h5", 2, 0 },
188
+ { "h6", 2, 0 },
189
+ { "ol", 2, 0 },
190
+ { "ul", 2, 0 },
191
+ { "div", 3, 0 },
192
+ { "pre", 3, 0 },
193
+ { "form", 4, HTMLTAG_FORBIDDEN },
194
+ { "math", 4, 0 },
195
+ { "style", 5, HTMLTAG_FORBIDDEN },
196
+ { "table", 5, 0 },
197
+ { "iframe", 6, HTMLTAG_FORBIDDEN },
198
+ { "script", 6, HTMLTAG_FORBIDDEN },
199
+ { "fieldset", 8, 0 },
200
+ { "noscript", 8, HTMLTAG_FORBIDDEN },
201
+ { "blockquote", 10, 0 }
200202
};
201
-
202
-#define INS_TAG (block_tags + 12)
203
-#define DEL_TAG (block_tags + 10)
204
-
205
-
206203
207204
/***************************
208205
* STATIC HELPER FUNCTIONS *
209206
***************************/
210207
@@ -1783,12 +1780,11 @@
17831780
}
17841781
}
17851782
#endif
17861783
17871784
/* if not found, trying a second pass looking for indented match */
1788
- /* but not if tag is "ins" or "del" (following original Markdown.pl) */
1789
- if( !found && curtag!=INS_TAG && curtag!=DEL_TAG ){
1785
+ if( !found ){
17901786
i = 1;
17911787
while( i<size ){
17921788
i++;
17931789
while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }
17941790
if( (i+2+curtag->size)>=size ) break;
@@ -1798,10 +1794,18 @@
17981794
found = 1;
17991795
break;
18001796
}
18011797
}
18021798
}
1799
+
1800
+ /* Do not display certain HTML tags */
1801
+ if( curtag->flags & HTMLTAG_FORBIDDEN ){
1802
+ if( !found ){
1803
+ for(i=1; i<size && data[i]!='>'; i++){}
1804
+ }
1805
+ return i;
1806
+ }
18031807
18041808
if( !found ) return 0;
18051809
18061810
/* the end of the block has been found */
18071811
blob_init(&work, data, i);
18081812
--- src/markdown.c
+++ src/markdown.c
@@ -163,48 +163,45 @@
163
164 /* html_tag -- structure for quick HTML tag search (inspired from discount) */
165 struct html_tag {
166 const char *text;
167 int size;
 
168 };
169
 
 
170
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 ***************************/
210
@@ -1783,12 +1780,11 @@
1783 }
1784 }
1785 #endif
1786
1787 /* if not found, trying a second pass looking for indented match */
1788 /* but not if tag is "ins" or "del" (following original Markdown.pl) */
1789 if( !found && curtag!=INS_TAG && curtag!=DEL_TAG ){
1790 i = 1;
1791 while( i<size ){
1792 i++;
1793 while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }
1794 if( (i+2+curtag->size)>=size ) break;
@@ -1798,10 +1794,18 @@
1798 found = 1;
1799 break;
1800 }
1801 }
1802 }
 
 
 
 
 
 
 
 
1803
1804 if( !found ) return 0;
1805
1806 /* the end of the block has been found */
1807 blob_init(&work, data, i);
1808
--- src/markdown.c
+++ src/markdown.c
@@ -163,48 +163,45 @@
163
164 /* html_tag -- structure for quick HTML tag search (inspired from discount) */
165 struct html_tag {
166 const char *text;
167 int size;
168 int flags;
169 };
170
171 /* Allowed bits in html_tag.flags */
172 #define HTMLTAG_FORBIDDEN 0x001 /* escape */
173
174
175 /********************
176 * GLOBAL VARIABLES *
177 ********************/
178
179 /* block_tags -- recognised block tags, sorted by cmp_html_tag */
180 static const struct html_tag block_tags[] = {
181 { "p", 1, 0 },
182 { "dl", 2, 0 },
183 { "h1", 2, 0 },
184 { "h2", 2, 0 },
185 { "h3", 2, 0 },
186 { "h4", 2, 0 },
187 { "h5", 2, 0 },
188 { "h6", 2, 0 },
189 { "ol", 2, 0 },
190 { "ul", 2, 0 },
191 { "div", 3, 0 },
192 { "pre", 3, 0 },
193 { "form", 4, HTMLTAG_FORBIDDEN },
194 { "math", 4, 0 },
195 { "style", 5, HTMLTAG_FORBIDDEN },
196 { "table", 5, 0 },
197 { "iframe", 6, HTMLTAG_FORBIDDEN },
198 { "script", 6, HTMLTAG_FORBIDDEN },
199 { "fieldset", 8, 0 },
200 { "noscript", 8, HTMLTAG_FORBIDDEN },
201 { "blockquote", 10, 0 }
 
202 };
 
 
 
 
 
203
204 /***************************
205 * STATIC HELPER FUNCTIONS *
206 ***************************/
207
@@ -1783,12 +1780,11 @@
1780 }
1781 }
1782 #endif
1783
1784 /* if not found, trying a second pass looking for indented match */
1785 if( !found ){
 
1786 i = 1;
1787 while( i<size ){
1788 i++;
1789 while( i<size && !(data[i-1]=='<' && data[i]=='/') ){ i++; }
1790 if( (i+2+curtag->size)>=size ) break;
@@ -1798,10 +1794,18 @@
1794 found = 1;
1795 break;
1796 }
1797 }
1798 }
1799
1800 /* Do not display certain HTML tags */
1801 if( curtag->flags & HTMLTAG_FORBIDDEN ){
1802 if( !found ){
1803 for(i=1; i<size && data[i]!='>'; i++){}
1804 }
1805 return i;
1806 }
1807
1808 if( !found ) return 0;
1809
1810 /* the end of the block has been found */
1811 blob_init(&work, data, i);
1812

Keyboard Shortcuts

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