Commit fa876ec4d44a8d7e83df544f81449fba0bbdfc88
1 parent
cebdf6b7
add encode_HTML_quote
Showing
1 changed file
with
53 additions
and
4 deletions
Show diff stats
web/making_a_web_site.anubis
| ... | ... | @@ -120,6 +120,50 @@ public define String |
| 120 | 120 | _HTML_encode_entities(explode(source), []) |
| 121 | 121 | . |
| 122 | 122 | |
| 123 | +define List(Word8) | |
| 124 | +/** Test for HTML entity which must be encoded | |
| 125 | + * and return the encoded entity if needed | |
| 126 | + */ | |
| 127 | + get_entity_quote | |
| 128 | + ( | |
| 129 | + Word8 _char, | |
| 130 | + List(Word8) tail | |
| 131 | + )= | |
| 132 | + //test for the ampersand | |
| 133 | + if _char = '&' then | |
| 134 | + //test if it's already an encoded string like & < etc. In that case we do nothing | |
| 135 | + if insensitive_equal(['&','a','m','p',';'], tail, 0) then [_char] | |
| 136 | + else if insensitive_equal(['&','l','t',';'], tail, 0) then [_char] | |
| 137 | + else if insensitive_equal(['&','g','t',';'], tail, 0) then [_char] | |
| 138 | + else if insensitive_equal(['&','q','u','o','t',';'], tail, 0) then [_char] | |
| 139 | + else | |
| 140 | + [';','p','m','a','&'] | |
| 141 | + //test for '"' only. | |
| 142 | + else if _char = '\"' then [';','t','o','u','q','&'] | |
| 143 | + else [_char] | |
| 144 | +. | |
| 145 | + | |
| 146 | +define String | |
| 147 | + _HTML_encode_quote | |
| 148 | + ( | |
| 149 | + List(Word8) source, | |
| 150 | + List(Word8) current | |
| 151 | + )= | |
| 152 | + if source is | |
| 153 | + { | |
| 154 | + [] then implode(reverse(current)), | |
| 155 | + [c . t] then | |
| 156 | + _HTML_encode_quote(t, get_entity_quote(c, t) + current) | |
| 157 | + } | |
| 158 | +. | |
| 159 | + | |
| 160 | +public define String | |
| 161 | + encode_HTML_quote | |
| 162 | + ( | |
| 163 | + String source | |
| 164 | + )= | |
| 165 | + _HTML_encode_quote(explode(source), []) | |
| 166 | +. | |
| 123 | 167 | |
| 124 | 168 | * (1) Structure of a web site. |
| 125 | 169 | |
| ... | ... | @@ -1562,6 +1606,7 @@ public define HTML_Off_Form label(List(CoreAttrs) attrs, String string) |
| 1562 | 1606 | // <li> |
| 1563 | 1607 | public define HTML_Off_Form li(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("li", attrs, content). |
| 1564 | 1608 | public define HTML_Off_Form li(List(CoreAttrs) attrs, HTML_Off_Form content) = html_tag("li", attrs, [content]). |
| 1609 | +public define HTML_Off_Form li(CoreAttrs attr, List(HTML_Off_Form) content) = html_tag("li", [attr], content). | |
| 1565 | 1610 | public define HTML_Off_Form li(CoreAttrs attr, HTML_Off_Form content) = html_tag("li", [attr], [content]). |
| 1566 | 1611 | public define HTML_Off_Form li(List(HTML_Off_Form) content) = html_tag("li", [], content). |
| 1567 | 1612 | public define HTML_Off_Form li(HTML_Off_Form content) = html_tag("li", [], [content]). |
| ... | ... | @@ -5254,9 +5299,12 @@ define Printable_tree |
| 5254 | 5299 | format(cinfo, ic_v, any_div(options, html_elements), format_element, is_https, action_count, head_tags), |
| 5255 | 5300 | // div_empty(options) then |
| 5256 | 5301 | // format(cinfo, ic_v, any_div_empty(options), format_element, is_https, action_count, head_tags), |
| 5257 | - iframe(options, css_styles, css_files, js_files, body) then | |
| 5302 | + iframe(options, css_styles, css_files, js_files, body) then | |
| 5303 | + println("formating iframe"); | |
| 5258 | 5304 | if body is body(body_options,elem) then |
| 5259 | - [ "<iframe", format_attrs(options), ">\n", | |
| 5305 | + [ "<iframe", format_attrs(options), " srcdoc=\"\n", | |
| 5306 | + | |
| 5307 | + encode_HTML_quote(to_String([ | |
| 5260 | 5308 | "<html style=\"margin: 0pt; padding: 0pt;\">\n", |
| 5261 | 5309 | "<head>\n", |
| 5262 | 5310 | add_css_styles(css_styles), |
| ... | ... | @@ -5266,8 +5314,9 @@ define Printable_tree |
| 5266 | 5314 | "<body ", format(body_options), ">\n", // format body options |
| 5267 | 5315 | format(cinfo,ic_v,elem,is_https, action_count, head_tags), |
| 5268 | 5316 | "</body>\n", |
| 5269 | - "</html>\n", | |
| 5270 | - "</iframe>\n", | |
| 5317 | + "</html>\n",])), | |
| 5318 | + | |
| 5319 | + "\"></iframe>\n", | |
| 5271 | 5320 | ], |
| 5272 | 5321 | partial(p_content) then |
| 5273 | 5322 | if p_content is partial_content(tags, html_elements) then | ... | ... |