webview

Check-in [78dabae49f]
Login

Check-in [78dabae49f]

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

Overview
Comment:Fragment rendering for write-html
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 78dabae49f716051e3af75ba947506d4e3cdfa7dc57847a8a692909f0264258a
User & Date: murphy 2018-09-01 01:49:27.138
Context
2018-09-01
04:23
Improved dialog interface, injection code check-in: f19371823b user: murphy tags: trunk
01:49
Fragment rendering for write-html check-in: 78dabae49f user: murphy tags: trunk
00:57
Corrected processing of callback errors check-in: 3134cb975d user: murphy tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to content.scm.
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132



133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
              (unless (and (pair? elt) (symbol? (car elt)) (list? (cdr elt)))
                (error 'write-html "not a proper element" elt))
              (let ([tag (car elt)]
                    [attributes&contents (cdr elt)])
                (when (eq? tag 'html)
                  (display "<!DOCTYPE html>" port)
                  (newline port))
                (display #\< port)
                (display tag port)
                (let-values ([(rule)
                              (html-tag-rule tag)]
                             [(attributes contents)
                              (cond
                               [(null? attributes&contents)
                                (values '() '())]
                               [(and (list? (car attributes&contents))
                                     (every pair? (car attributes&contents)))
                                (values (car attributes&contents) (cdr attributes&contents))]
                               [else
                                (values '() attributes&contents)])])



                  (for-each (cut write-attribute <> port) attributes)
                  (display #\> port)
                  (case rule
                    [(normal)
                     (for-each (cut write-content #t <> port) contents)]
                    [(raw)
                     (for-each (cut write-content #f <> port) contents)]
                    [(void)
                     (unless (null? contents)
                       (error 'write-html "void elements cannot have contents" elt))])

                  (case rule
                    [(normal raw)
                     (display "</" port)
                     (display tag port)
                     (display #\> port)]))
                (when (eq? tag 'html)
                  (newline port))))]
           [write-attribute
            (lambda (attr port)
              (unless (and (pair? attr) (symbol? (car attr)))
                (error 'write-html "not a proper attribute" attr))
              (let ([key (car attr)]







<
<



|
|
<
|
|
|
<
|
>
>
>
|
|








>
|
|
|
|
|







113
114
115
116
117
118
119


120
121
122
123
124

125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
              (unless (and (pair? elt) (symbol? (car elt)) (list? (cdr elt)))
                (error 'write-html "not a proper element" elt))
              (let ([tag (car elt)]
                    [attributes&contents (cdr elt)])
                (when (eq? tag 'html)
                  (display "<!DOCTYPE html>" port)
                  (newline port))


                (let-values ([(rule)
                              (html-tag-rule tag)]
                             [(attributes contents)
                              (if (and (not (eq? tag 'begin))
                                       (pair? attributes&contents)

                                       (list? (car attributes&contents))
                                       (every pair? (car attributes&contents)))
                                (values (car attributes&contents) (cdr attributes&contents))

                                (values '() attributes&contents))])
                  (unless (eq? tag 'begin)
                    (display #\< port)
                    (display tag port)
                    (for-each (cut write-attribute <> port) attributes)
                    (display #\> port))
                  (case rule
                    [(normal)
                     (for-each (cut write-content #t <> port) contents)]
                    [(raw)
                     (for-each (cut write-content #f <> port) contents)]
                    [(void)
                     (unless (null? contents)
                       (error 'write-html "void elements cannot have contents" elt))])
                  (unless (eq? tag 'begin)
                    (case rule
                      [(normal raw)
                       (display "</" port)
                       (display tag port)
                       (display #\> port)])))
                (when (eq? tag 'html)
                  (newline port))))]
           [write-attribute
            (lambda (attr port)
              (unless (and (pair? attr) (symbol? (car attr)))
                (error 'write-html "not a proper attribute" attr))
              (let ([key (car attr)]
Changes to tests/run.scm.
60
61
62
63
64
65
66
67

68
69
  (test 'void (html-tag-rule 'br))
  (test "<!DOCTYPE html>\n<html></html>\n" (html->string '(html)))
  (test "<br>" (html->string '(br)))
  (test "<p>Hello world!</p>" (html->string '(p "Hello world!")))
  (test "<span>&amp;</span>" (html->string '(span amp)))
  (test "<span>&#9997;</span>" (html->string '(span #x270d)))
  (test "<meta charset=\"utf-8\">" (html->string '(meta ([charset "utf-8"]))))
  (test "<span class=\"close\">blah &times;</span>" (html->string '(span ([class "close"]) "blah " times))))


;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;;







|
>


60
61
62
63
64
65
66
67
68
69
70
  (test 'void (html-tag-rule 'br))
  (test "<!DOCTYPE html>\n<html></html>\n" (html->string '(html)))
  (test "<br>" (html->string '(br)))
  (test "<p>Hello world!</p>" (html->string '(p "Hello world!")))
  (test "<span>&amp;</span>" (html->string '(span amp)))
  (test "<span>&#9997;</span>" (html->string '(span #x270d)))
  (test "<meta charset=\"utf-8\">" (html->string '(meta ([charset "utf-8"]))))
  (test "<span class=\"close\">blah &times;</span>" (html->string '(span ([class "close"]) "blah " times)))
  (test "<em>foo</em>x<tt>bar</tt>" (html->string '(begin (em "foo") "x" (tt "bar")))))

;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;;
Changes to webview.wiki.
172
173
174
175
176
177
178



  CONTENT = STRING                                         ;; character data
          | SYMBOL                                         ;; symbolic entity reference
          | INTEGER                                        ;; numeric entity reference
</verbatim>

If the tag symbol of the element is <tt>html</tt>, an HTML5 document
type declaration is written before the element itself.










>
>
>
172
173
174
175
176
177
178
179
180
181
  CONTENT = STRING                                         ;; character data
          | SYMBOL                                         ;; symbolic entity reference
          | INTEGER                                        ;; numeric entity reference
</verbatim>

If the tag symbol of the element is <tt>html</tt>, an HTML5 document
type declaration is written before the element itself.

If the tag symbol of the element is <tt>begin</tt>, attributes are not
allowed and only the contents are written as for a normal element.