@@ -19,16 +19,6 @@ function preview(content; reuse=true)
19
19
DefaultApplication. open (file)
20
20
end
21
21
22
- # -----------------------------------------------------------------------------# Page
23
- function Page (x)
24
- Base. depwarn (" Page(x) is deprecated. Use preview(x) instead." , :Page ; force= true )
25
- preview (x)
26
- end
27
- function Tab (x)
28
- Base. depwarn (" Tab(x) is deprecated. Use preview(x; reuse=false) instead." , :Tab ; force= true )
29
- preview (x; reuse= false )
30
- end
31
-
32
22
# -----------------------------------------------------------------------------# consts
33
23
const HTML5_TAGS = [:a ,:abbr ,:address ,:area ,:article ,:aside ,:audio ,:b ,:base ,:bdi ,:bdo ,:blockquote ,:body ,:br ,:button ,:canvas ,:caption ,:cite ,:code ,:col ,:colgroup ,:command ,:datalist ,:dd ,:del ,:details ,:dfn ,:dialog ,:div ,:dl ,:dt ,:em ,:embed ,:fieldset ,:figcaption ,:figure ,:footer ,:form ,:h1 ,:h2 ,:h3 ,:h4 ,:h5 ,:h6 ,:head ,:header ,:hgroup ,:hr ,:html ,:i ,:iframe ,:img ,:input ,:ins ,:kbd ,:label ,:legend ,:li ,:link ,:main ,:map ,:mark ,:math ,:menu ,:menuitem ,:meta ,:meter ,:nav ,:noscript ,:object ,:ol ,:optgroup ,:option ,:output ,:p ,:param ,:picture ,:pre ,:progress ,:q ,:rb ,:rp ,:rt ,:rtc ,:ruby ,:s ,:samp ,:script ,:section ,:select ,:slot ,:small ,:source ,:span ,:strong ,:style ,:sub ,:summary ,:sup ,:svg ,:table ,:tbody ,:td ,:template ,:textarea ,:tfoot ,:th ,:thead ,:time ,:title ,:tr ,:track ,:u ,:ul ,:var ,:video ,:wbr ]
34
24
@@ -48,11 +38,14 @@ struct Node
48
38
tag:: Symbol
49
39
attrs:: OrderedDict{Symbol, String}
50
40
children:: Vector{Any}
41
+ function Node (tag, attributes, children)
42
+ sym = Symbol (tag)
43
+ sym in HTML5_TAGS || @warn " <$tag > is not a valid HTML5 tag."
44
+ new (sym, attrs (attributes), [children... ])
45
+ end
51
46
end
52
- function Node (tag:: Symbol , attrs:: OrderedDict{Symbol, String} , children:: AbstractVector )
53
- tag in HTML5_TAGS || @warn " <$tag > is not a valid HTML5 tag."
54
- Node (tag, attrs, collect (children))
55
- end
47
+
48
+
56
49
tag (o:: Node ) = getfield (o, :tag )
57
50
attrs (o:: Node ) = getfield (o, :attrs )
58
51
children (o:: Node ) = getfield (o, :children )
@@ -67,13 +60,11 @@ Base.:(==)(a::Node, b::Node) = all(f(a) == f(b) for f in (tag, attrs, children))
67
60
Base. getproperty (o:: Node , class:: String ) = o (class = lstrip (get (o, :class , " " ) * " " * class))
68
61
69
62
# methods that pass through to attrs(o)
70
- Base. propertynames (o:: Node ) = Symbol .(keys (o ))
63
+ Base. propertynames (o:: Node ) = Symbol .(keys (attrs (o) ))
71
64
Base. getproperty (o:: Node , name:: Symbol ) = attrs (o)[name]
72
65
Base. setproperty! (o:: Node , name:: Symbol , x) = attrs (o)[name] = string (x)
73
- Base. get (o:: Node , name, val) = get (attrs (o), string (name), string (val))
74
- Base. get! (o:: Node , name, val) = get! (attrs (o), string (name), string (val))
75
- Base. haskey (o:: Node , name) = haskey (attrs (o), string (name))
76
- Base. keys (o:: Node ) = keys (attrs (o))
66
+ Base. get (o:: Node , name, val) = get (attrs (o), Symbol (name), val)
67
+ Base. get! (o:: Node , name, val) = get! (attrs (o), Symbol (name), val)
77
68
78
69
# methods that pass through to children(o)
79
70
Base. lastindex (o:: Node ) = lastindex (children (o))
@@ -161,7 +152,7 @@ Create an html node with the given `tag`, `children`, and `kw` attributes.
161
152
h.div."myclass"("content")
162
153
# <div class="myclass">content</div>
163
154
"""
164
- h (tag, children... ; kw... ) = Node (tag, attrs (kw), collect (children))
155
+ h (tag, children... ; kw... ) = Node (Symbol ( tag) , attrs (kw), collect (children))
165
156
166
157
h (tag, attrs:: AbstractDict , children... ) = Node (tag, attrs, collect (children))
167
158
@@ -170,19 +161,23 @@ Base.getproperty(::typeof(h), tag::Symbol) = h(tag)
170
161
Base. propertynames (:: typeof (h)) = HTML5_TAGS
171
162
172
163
# -----------------------------------------------------------------------------# @h
164
+ """
165
+ @h ex
166
+
167
+ Convert any valid HTML `<tag>` in `ex` to `Cobweb.h.<tag>`.
168
+
169
+ ### Examples
170
+
171
+ @h div(p("This is a paragraph"), p("Here is some", strong("bold"), "text"))
172
+ # <div><p>This is a paragraph</p><p>Here is some<strong>bold</strong>text</p></div>
173
+ """
173
174
macro h (ex)
174
175
esc (_h (ex))
175
176
end
176
177
177
- function _h (ex:: Expr )
178
- for (i, x) in enumerate (ex. args)
179
- ex. args[i] = x isa Expr ? _h (x) :
180
- x isa Symbol && x in HTML5_TAGS ? Expr (:., :(Cobweb. h), QuoteNode (x)) :
181
- x
182
- end
183
- ex
184
- end
185
- _h (x:: Symbol ) = x in propertynames (typeof (h)) ? Expr (:., :(Cobweb. h), QuoteNode (x)) : x
178
+ _h (ex:: Expr ) = (ex. args .= _h .(ex. args); return ex)
179
+ _h (x:: Symbol ) = x in propertynames (h) ? Expr (:., :(Cobweb. h), QuoteNode (x)) : x
180
+ _h (x) = x
186
181
187
182
# -----------------------------------------------------------------------------# escape
188
183
escape_chars = [' &' => " &" , ' "' => " "" , ' '' => " '" , ' <' => " <" , ' >' => " >" ]
0 commit comments