about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-07-15 20:19:30 +0200
committerbptato <nincsnevem662@gmail.com>2023-07-15 20:19:30 +0200
commitc12abb7ddbbdfa6414fe00542f942276aefa7182 (patch)
tree2ddec332eb8eecb7195e71b6e28a69612f6ad4cb
parentdc934380de353d16ff62c633ff949fb85b30fd13 (diff)
downloadchawan-c12abb7ddbbdfa6414fe00542f942276aefa7182.tar.gz
htmlparser: make getTemplateContent optional
-rw-r--r--src/html/htmlparser.nim7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim
index 442068ad..727ff804 100644
--- a/src/html/htmlparser.nim
+++ b/src/html/htmlparser.nim
@@ -32,7 +32,7 @@ type
     elementPopped*: DOMBuilderElementPopped[Handle]
     ## May be nil.
     getTemplateContent*: DOMBuilderGetTemplateContent[Handle]
-    ## Must never be nil.
+    ## May be nil. (If nil, templates are treated as regular elements.)
     getParentNode*: DOMBuilderGetParentNode[Handle]
     ## Must never be nil.
     getLocalName*: DOMBuilderGetLocalName[Handle]
@@ -473,6 +473,7 @@ func appropriatePlaceForInsert[Handle](parser: HTML5Parser[Handle],
     let lastTemplate = parser.lastElementOfTag(TAG_TEMPLATE)
     let lastTable = parser.lastElementOfTag(TAG_TABLE)
     if lastTemplate.element != nil and
+        parser.dombuilder.getTemplateContent != nil and
         (lastTable.element == nil or lastTable.pos < lastTemplate.pos):
       let content = parser.getTemplateContent(lastTemplate.element)
       return last_child_of(content)
@@ -485,7 +486,8 @@ func appropriatePlaceForInsert[Handle](parser: HTML5Parser[Handle],
     result = last_child_of(previousElement)
   else:
     result = last_child_of(target)
-  if parser.getTagType(result.inside) == TAG_TEMPLATE:
+  if parser.getTagType(result.inside) == TAG_TEMPLATE and
+      parser.dombuilder.getTemplateContent != nil:
     result = (parser.getTemplateContent(result.inside), nil)
 
 func appropriatePlaceForInsert[Handle](parser: HTML5Parser[Handle]):
@@ -2673,7 +2675,6 @@ proc bomSniff(inputStream: Stream): Charset =
 
 # Any of these pointers being nil would later result in a crash.
 proc checkCallbacks(dombuilder: DOMBuilder) =
-  doAssert dombuilder.getTemplateContent != nil
   doAssert dombuilder.getParentNode != nil
   doAssert dombuilder.getLocalName != nil
   doAssert dombuilder.createElement != nil
l?h=main&id=9ac3fde9ab9651ecf5eb0ae0af6691e65ab3b122'>^
ce2c1efc ^
60338448 ^
e99038ea ^
ce2c1efc ^
39d718af ^
60338448 ^
104e521c ^















ce2c1efc ^
104e521c ^















c8a3ccbe ^
104e521c ^
ef31035a ^
104e521c ^

14a38052 ^


d1c9392a ^
e99038ea ^

33352536 ^

14a38052 ^
d1c9392a ^
b1635a5c ^

33352536 ^

14a38052 ^
33352536 ^



14a38052 ^
33352536 ^







14a38052 ^
33352536 ^
14a38052 ^
33352536 ^

52daf072 ^


33352536 ^



b1635a5c ^
33352536 ^

52daf072 ^




33352536 ^

52daf072 ^



104e521c ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120