How to use Add method of html Package

Best K6 code snippet using html.Add

parse.go

Source:parse.go Github

copy

Full Screen

...579 switch p.tok.Type {580 case TextToken:581 s := strings.TrimLeft(p.tok.Data, whitespace)582 if len(s) < len(p.tok.Data) {583 // Add the initial whitespace to the current node.584 p.addText(p.tok.Data[:len(p.tok.Data)-len(s)])585 if s == "" {586 return true587 }588 p.tok.Data = s589 }590 case StartTagToken:591 switch p.tok.DataAtom {592 case a.Html:593 return inBodyIM(p)594 case a.Base, a.Basefont, a.Bgsound, a.Link, a.Meta:595 p.addElement()596 p.oe.pop()597 p.acknowledgeSelfClosingTag()598 return true599 case a.Noscript:600 if p.scripting {601 p.parseGenericRawTextElement()602 return true603 }604 p.addElement()605 p.im = inHeadNoscriptIM606 // Don't let the tokenizer go into raw text mode when scripting is disabled.607 p.tokenizer.NextIsNotRawText()608 return true609 case a.Script, a.Title:610 p.addElement()611 p.setOriginalIM()612 p.im = textIM613 return true614 case a.Noframes, a.Style:615 p.parseGenericRawTextElement()616 return true617 case a.Head:618 // Ignore the token.619 return true620 case a.Template:621 p.addElement()622 p.afe = append(p.afe, &scopeMarker)623 p.framesetOK = false624 p.im = inTemplateIM625 p.templateStack = append(p.templateStack, inTemplateIM)626 return true627 }628 case EndTagToken:629 switch p.tok.DataAtom {630 case a.Head:631 p.oe.pop()632 p.im = afterHeadIM633 return true634 case a.Body, a.Html, a.Br:635 p.parseImpliedToken(EndTagToken, a.Head, a.Head.String())636 return false637 case a.Template:638 if !p.oe.contains(a.Template) {639 return true640 }641 // TODO: remove this divergence from the HTML5 spec.642 //643 // See https://bugs.chromium.org/p/chromium/issues/detail?id=829668644 p.generateImpliedEndTags()645 for i := len(p.oe) - 1; i >= 0; i-- {646 if n := p.oe[i]; n.Namespace == "" && n.DataAtom == a.Template {647 p.oe = p.oe[:i]648 break649 }650 }651 p.clearActiveFormattingElements()652 p.templateStack.pop()653 p.resetInsertionMode()654 return true655 default:656 // Ignore the token.657 return true658 }659 case CommentToken:660 p.addChild(&Node{661 Type: CommentNode,662 Data: p.tok.Data,663 })664 return true665 case DoctypeToken:666 // Ignore the token.667 return true668 }669 p.parseImpliedToken(EndTagToken, a.Head, a.Head.String())670 return false671}672// 12.2.6.4.5.673func inHeadNoscriptIM(p *parser) bool {674 switch p.tok.Type {675 case DoctypeToken:676 // Ignore the token.677 return true678 case StartTagToken:679 switch p.tok.DataAtom {680 case a.Html:681 return inBodyIM(p)682 case a.Basefont, a.Bgsound, a.Link, a.Meta, a.Noframes, a.Style:683 return inHeadIM(p)684 case a.Head, a.Noscript:685 // Ignore the token.686 return true687 }688 case EndTagToken:689 switch p.tok.DataAtom {690 case a.Noscript, a.Br:691 default:692 // Ignore the token.693 return true694 }695 case TextToken:696 s := strings.TrimLeft(p.tok.Data, whitespace)697 if len(s) == 0 {698 // It was all whitespace.699 return inHeadIM(p)700 }701 case CommentToken:702 return inHeadIM(p)703 }704 p.oe.pop()705 if p.top().DataAtom != a.Head {706 panic("html: the new current node will be a head element.")707 }708 p.im = inHeadIM709 if p.tok.DataAtom == a.Noscript {710 return true711 }712 return false713}714// Section 12.2.6.4.6.715func afterHeadIM(p *parser) bool {716 switch p.tok.Type {717 case TextToken:718 s := strings.TrimLeft(p.tok.Data, whitespace)719 if len(s) < len(p.tok.Data) {720 // Add the initial whitespace to the current node.721 p.addText(p.tok.Data[:len(p.tok.Data)-len(s)])722 if s == "" {723 return true724 }725 p.tok.Data = s726 }727 case StartTagToken:728 switch p.tok.DataAtom {729 case a.Html:730 return inBodyIM(p)731 case a.Body:732 p.addElement()733 p.framesetOK = false734 p.im = inBodyIM735 return true736 case a.Frameset:737 p.addElement()738 p.im = inFramesetIM739 return true740 case a.Base, a.Basefont, a.Bgsound, a.Link, a.Meta, a.Noframes, a.Script, a.Style, a.Template, a.Title:741 p.oe = append(p.oe, p.head)742 defer p.oe.remove(p.head)743 return inHeadIM(p)744 case a.Head:745 // Ignore the token.746 return true747 }748 case EndTagToken:749 switch p.tok.DataAtom {750 case a.Body, a.Html, a.Br:751 // Drop down to creating an implied <body> tag.752 case a.Template:753 return inHeadIM(p)754 default:755 // Ignore the token.756 return true757 }758 case CommentToken:759 p.addChild(&Node{760 Type: CommentNode,761 Data: p.tok.Data,762 })763 return true764 case DoctypeToken:765 // Ignore the token.766 return true767 }768 p.parseImpliedToken(StartTagToken, a.Body, a.Body.String())769 p.framesetOK = true770 return false771}772// copyAttributes copies attributes of src not found on dst to dst.773func copyAttributes(dst *Node, src Token) {774 if len(src.Attr) == 0 {775 return776 }777 attr := map[string]string{}778 for _, t := range dst.Attr {779 attr[t.Key] = t.Val780 }781 for _, t := range src.Attr {782 if _, ok := attr[t.Key]; !ok {783 dst.Attr = append(dst.Attr, t)784 attr[t.Key] = t.Val785 }786 }787}788// Section 12.2.6.4.7.789func inBodyIM(p *parser) bool {790 switch p.tok.Type {791 case TextToken:792 d := p.tok.Data793 switch n := p.oe.top(); n.DataAtom {794 case a.Pre, a.Listing:795 if n.FirstChild == nil {796 // Ignore a newline at the start of a <pre> block.797 if d != "" && d[0] == '\r' {798 d = d[1:]799 }800 if d != "" && d[0] == '\n' {801 d = d[1:]802 }803 }804 }805 d = strings.Replace(d, "\x00", "", -1)806 if d == "" {807 return true808 }809 p.reconstructActiveFormattingElements()810 p.addText(d)811 if p.framesetOK && strings.TrimLeft(d, whitespace) != "" {812 // There were non-whitespace characters inserted.813 p.framesetOK = false814 }815 case StartTagToken:816 switch p.tok.DataAtom {817 case a.Html:818 if p.oe.contains(a.Template) {819 return true820 }821 copyAttributes(p.oe[0], p.tok)822 case a.Base, a.Basefont, a.Bgsound, a.Link, a.Meta, a.Noframes, a.Script, a.Style, a.Template, a.Title:823 return inHeadIM(p)824 case a.Body:825 if p.oe.contains(a.Template) {826 return true827 }828 if len(p.oe) >= 2 {829 body := p.oe[1]830 if body.Type == ElementNode && body.DataAtom == a.Body {831 p.framesetOK = false832 copyAttributes(body, p.tok)833 }834 }835 case a.Frameset:836 if !p.framesetOK || len(p.oe) < 2 || p.oe[1].DataAtom != a.Body {837 // Ignore the token.838 return true839 }840 body := p.oe[1]841 if body.Parent != nil {842 body.Parent.RemoveChild(body)843 }844 p.oe = p.oe[:1]845 p.addElement()846 p.im = inFramesetIM847 return true848 case a.Address, a.Article, a.Aside, a.Blockquote, a.Center, a.Details, a.Dialog, a.Dir, a.Div, a.Dl, a.Fieldset, a.Figcaption, a.Figure, a.Footer, a.Header, a.Hgroup, a.Main, a.Menu, a.Nav, a.Ol, a.P, a.Section, a.Summary, a.Ul:849 p.popUntil(buttonScope, a.P)850 p.addElement()851 case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6:852 p.popUntil(buttonScope, a.P)853 switch n := p.top(); n.DataAtom {854 case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6:855 p.oe.pop()856 }857 p.addElement()858 case a.Pre, a.Listing:859 p.popUntil(buttonScope, a.P)860 p.addElement()861 // The newline, if any, will be dealt with by the TextToken case.862 p.framesetOK = false863 case a.Form:864 if p.form != nil && !p.oe.contains(a.Template) {865 // Ignore the token866 return true867 }868 p.popUntil(buttonScope, a.P)869 p.addElement()870 if !p.oe.contains(a.Template) {871 p.form = p.top()872 }873 case a.Li:874 p.framesetOK = false875 for i := len(p.oe) - 1; i >= 0; i-- {876 node := p.oe[i]877 switch node.DataAtom {878 case a.Li:879 p.oe = p.oe[:i]880 case a.Address, a.Div, a.P:881 continue882 default:883 if !isSpecialElement(node) {884 continue885 }886 }887 break888 }889 p.popUntil(buttonScope, a.P)890 p.addElement()891 case a.Dd, a.Dt:892 p.framesetOK = false893 for i := len(p.oe) - 1; i >= 0; i-- {894 node := p.oe[i]895 switch node.DataAtom {896 case a.Dd, a.Dt:897 p.oe = p.oe[:i]898 case a.Address, a.Div, a.P:899 continue900 default:901 if !isSpecialElement(node) {902 continue903 }904 }905 break906 }907 p.popUntil(buttonScope, a.P)908 p.addElement()909 case a.Plaintext:910 p.popUntil(buttonScope, a.P)911 p.addElement()912 case a.Button:913 p.popUntil(defaultScope, a.Button)914 p.reconstructActiveFormattingElements()915 p.addElement()916 p.framesetOK = false917 case a.A:918 for i := len(p.afe) - 1; i >= 0 && p.afe[i].Type != scopeMarkerNode; i-- {919 if n := p.afe[i]; n.Type == ElementNode && n.DataAtom == a.A {920 p.inBodyEndTagFormatting(a.A, "a")921 p.oe.remove(n)922 p.afe.remove(n)923 break924 }925 }926 p.reconstructActiveFormattingElements()927 p.addFormattingElement()928 case a.B, a.Big, a.Code, a.Em, a.Font, a.I, a.S, a.Small, a.Strike, a.Strong, a.Tt, a.U:929 p.reconstructActiveFormattingElements()930 p.addFormattingElement()931 case a.Nobr:932 p.reconstructActiveFormattingElements()933 if p.elementInScope(defaultScope, a.Nobr) {934 p.inBodyEndTagFormatting(a.Nobr, "nobr")935 p.reconstructActiveFormattingElements()936 }937 p.addFormattingElement()938 case a.Applet, a.Marquee, a.Object:939 p.reconstructActiveFormattingElements()940 p.addElement()941 p.afe = append(p.afe, &scopeMarker)942 p.framesetOK = false943 case a.Table:944 if !p.quirks {945 p.popUntil(buttonScope, a.P)946 }947 p.addElement()948 p.framesetOK = false949 p.im = inTableIM950 return true951 case a.Area, a.Br, a.Embed, a.Img, a.Input, a.Keygen, a.Wbr:952 p.reconstructActiveFormattingElements()953 p.addElement()954 p.oe.pop()955 p.acknowledgeSelfClosingTag()956 if p.tok.DataAtom == a.Input {957 for _, t := range p.tok.Attr {958 if t.Key == "type" {959 if strings.ToLower(t.Val) == "hidden" {960 // Skip setting framesetOK = false961 return true962 }963 }964 }965 }966 p.framesetOK = false967 case a.Param, a.Source, a.Track:968 p.addElement()969 p.oe.pop()970 p.acknowledgeSelfClosingTag()971 case a.Hr:972 p.popUntil(buttonScope, a.P)973 p.addElement()974 p.oe.pop()975 p.acknowledgeSelfClosingTag()976 p.framesetOK = false977 case a.Image:978 p.tok.DataAtom = a.Img979 p.tok.Data = a.Img.String()980 return false981 case a.Textarea:982 p.addElement()983 p.setOriginalIM()984 p.framesetOK = false985 p.im = textIM986 case a.Xmp:987 p.popUntil(buttonScope, a.P)988 p.reconstructActiveFormattingElements()989 p.framesetOK = false990 p.parseGenericRawTextElement()991 case a.Iframe:992 p.framesetOK = false993 p.parseGenericRawTextElement()994 case a.Noembed:995 p.parseGenericRawTextElement()996 case a.Noscript:997 if p.scripting {998 p.parseGenericRawTextElement()999 return true1000 }1001 p.reconstructActiveFormattingElements()1002 p.addElement()1003 // Don't let the tokenizer go into raw text mode when scripting is disabled.1004 p.tokenizer.NextIsNotRawText()1005 case a.Select:1006 p.reconstructActiveFormattingElements()1007 p.addElement()1008 p.framesetOK = false1009 p.im = inSelectIM1010 return true1011 case a.Optgroup, a.Option:1012 if p.top().DataAtom == a.Option {1013 p.oe.pop()1014 }1015 p.reconstructActiveFormattingElements()1016 p.addElement()1017 case a.Rb, a.Rtc:1018 if p.elementInScope(defaultScope, a.Ruby) {1019 p.generateImpliedEndTags()1020 }1021 p.addElement()1022 case a.Rp, a.Rt:1023 if p.elementInScope(defaultScope, a.Ruby) {1024 p.generateImpliedEndTags("rtc")1025 }1026 p.addElement()1027 case a.Math, a.Svg:1028 p.reconstructActiveFormattingElements()1029 if p.tok.DataAtom == a.Math {1030 adjustAttributeNames(p.tok.Attr, mathMLAttributeAdjustments)1031 } else {1032 adjustAttributeNames(p.tok.Attr, svgAttributeAdjustments)1033 }1034 adjustForeignAttributes(p.tok.Attr)1035 p.addElement()1036 p.top().Namespace = p.tok.Data1037 if p.hasSelfClosingToken {1038 p.oe.pop()1039 p.acknowledgeSelfClosingTag()1040 }1041 return true1042 case a.Caption, a.Col, a.Colgroup, a.Frame, a.Head, a.Tbody, a.Td, a.Tfoot, a.Th, a.Thead, a.Tr:1043 // Ignore the token.1044 default:1045 p.reconstructActiveFormattingElements()1046 p.addElement()1047 }1048 case EndTagToken:1049 switch p.tok.DataAtom {1050 case a.Body:1051 if p.elementInScope(defaultScope, a.Body) {1052 p.im = afterBodyIM1053 }1054 case a.Html:1055 if p.elementInScope(defaultScope, a.Body) {1056 p.parseImpliedToken(EndTagToken, a.Body, a.Body.String())1057 return false1058 }1059 return true1060 case a.Address, a.Article, a.Aside, a.Blockquote, a.Button, a.Center, a.Details, a.Dialog, a.Dir, a.Div, a.Dl, a.Fieldset, a.Figcaption, a.Figure, a.Footer, a.Header, a.Hgroup, a.Listing, a.Main, a.Menu, a.Nav, a.Ol, a.Pre, a.Section, a.Summary, a.Ul:1061 p.popUntil(defaultScope, p.tok.DataAtom)1062 case a.Form:1063 if p.oe.contains(a.Template) {1064 i := p.indexOfElementInScope(defaultScope, a.Form)1065 if i == -1 {1066 // Ignore the token.1067 return true1068 }1069 p.generateImpliedEndTags()1070 if p.oe[i].DataAtom != a.Form {1071 // Ignore the token.1072 return true1073 }1074 p.popUntil(defaultScope, a.Form)1075 } else {1076 node := p.form1077 p.form = nil1078 i := p.indexOfElementInScope(defaultScope, a.Form)1079 if node == nil || i == -1 || p.oe[i] != node {1080 // Ignore the token.1081 return true1082 }1083 p.generateImpliedEndTags()1084 p.oe.remove(node)1085 }1086 case a.P:1087 if !p.elementInScope(buttonScope, a.P) {1088 p.parseImpliedToken(StartTagToken, a.P, a.P.String())1089 }1090 p.popUntil(buttonScope, a.P)1091 case a.Li:1092 p.popUntil(listItemScope, a.Li)1093 case a.Dd, a.Dt:1094 p.popUntil(defaultScope, p.tok.DataAtom)1095 case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6:1096 p.popUntil(defaultScope, a.H1, a.H2, a.H3, a.H4, a.H5, a.H6)1097 case a.A, a.B, a.Big, a.Code, a.Em, a.Font, a.I, a.Nobr, a.S, a.Small, a.Strike, a.Strong, a.Tt, a.U:1098 p.inBodyEndTagFormatting(p.tok.DataAtom, p.tok.Data)1099 case a.Applet, a.Marquee, a.Object:1100 if p.popUntil(defaultScope, p.tok.DataAtom) {1101 p.clearActiveFormattingElements()1102 }1103 case a.Br:1104 p.tok.Type = StartTagToken1105 return false1106 case a.Template:1107 return inHeadIM(p)1108 default:1109 p.inBodyEndTagOther(p.tok.DataAtom, p.tok.Data)1110 }1111 case CommentToken:1112 p.addChild(&Node{1113 Type: CommentNode,1114 Data: p.tok.Data,1115 })1116 case ErrorToken:1117 // TODO: remove this divergence from the HTML5 spec.1118 if len(p.templateStack) > 0 {1119 p.im = inTemplateIM1120 return false1121 }1122 for _, e := range p.oe {1123 switch e.DataAtom {1124 case a.Dd, a.Dt, a.Li, a.Optgroup, a.Option, a.P, a.Rb, a.Rp, a.Rt, a.Rtc, a.Tbody, a.Td, a.Tfoot, a.Th,1125 a.Thead, a.Tr, a.Body, a.Html:1126 default:1127 return true1128 }1129 }1130 }1131 return true1132}1133func (p *parser) inBodyEndTagFormatting(tagAtom a.Atom, tagName string) {1134 // This is the "adoption agency" algorithm, described at1135 // https://html.spec.whatwg.org/multipage/syntax.html#adoptionAgency1136 // TODO: this is a fairly literal line-by-line translation of that algorithm.1137 // Once the code successfully parses the comprehensive test suite, we should1138 // refactor this code to be more idiomatic.1139 // Steps 1-21140 if current := p.oe.top(); current.Data == tagName && p.afe.index(current) == -1 {1141 p.oe.pop()1142 return1143 }1144 // Steps 3-5. The outer loop.1145 for i := 0; i < 8; i++ {1146 // Step 6. Find the formatting element.1147 var formattingElement *Node1148 for j := len(p.afe) - 1; j >= 0; j-- {1149 if p.afe[j].Type == scopeMarkerNode {1150 break1151 }1152 if p.afe[j].DataAtom == tagAtom {1153 formattingElement = p.afe[j]1154 break1155 }1156 }1157 if formattingElement == nil {1158 p.inBodyEndTagOther(tagAtom, tagName)1159 return1160 }1161 // Step 7. Ignore the tag if formatting element is not in the stack of open elements.1162 feIndex := p.oe.index(formattingElement)1163 if feIndex == -1 {1164 p.afe.remove(formattingElement)1165 return1166 }1167 // Step 8. Ignore the tag if formatting element is not in the scope.1168 if !p.elementInScope(defaultScope, tagAtom) {1169 // Ignore the tag.1170 return1171 }1172 // Step 9. This step is omitted because it's just a parse error but no need to return.1173 // Steps 10-11. Find the furthest block.1174 var furthestBlock *Node1175 for _, e := range p.oe[feIndex:] {1176 if isSpecialElement(e) {1177 furthestBlock = e1178 break1179 }1180 }1181 if furthestBlock == nil {1182 e := p.oe.pop()1183 for e != formattingElement {1184 e = p.oe.pop()1185 }1186 p.afe.remove(e)1187 return1188 }1189 // Steps 12-13. Find the common ancestor and bookmark node.1190 commonAncestor := p.oe[feIndex-1]1191 bookmark := p.afe.index(formattingElement)1192 // Step 14. The inner loop. Find the lastNode to reparent.1193 lastNode := furthestBlock1194 node := furthestBlock1195 x := p.oe.index(node)1196 // Step 14.1.1197 j := 01198 for {1199 // Step 14.2.1200 j++1201 // Step. 14.3.1202 x--1203 node = p.oe[x]1204 // Step 14.4. Go to the next step if node is formatting element.1205 if node == formattingElement {1206 break1207 }1208 // Step 14.5. Remove node from the list of active formatting elements if1209 // inner loop counter is greater than three and node is in the list of1210 // active formatting elements.1211 if ni := p.afe.index(node); j > 3 && ni > -1 {1212 p.afe.remove(node)1213 // If any element of the list of active formatting elements is removed,1214 // we need to take care whether bookmark should be decremented or not.1215 // This is because the value of bookmark may exceed the size of the1216 // list by removing elements from the list.1217 if ni <= bookmark {1218 bookmark--1219 }1220 continue1221 }1222 // Step 14.6. Continue the next inner loop if node is not in the list of1223 // active formatting elements.1224 if p.afe.index(node) == -1 {1225 p.oe.remove(node)1226 continue1227 }1228 // Step 14.7.1229 clone := node.clone()1230 p.afe[p.afe.index(node)] = clone1231 p.oe[p.oe.index(node)] = clone1232 node = clone1233 // Step 14.8.1234 if lastNode == furthestBlock {1235 bookmark = p.afe.index(node) + 11236 }1237 // Step 14.9.1238 if lastNode.Parent != nil {1239 lastNode.Parent.RemoveChild(lastNode)1240 }1241 node.AppendChild(lastNode)1242 // Step 14.10.1243 lastNode = node1244 }1245 // Step 15. Reparent lastNode to the common ancestor,1246 // or for misnested table nodes, to the foster parent.1247 if lastNode.Parent != nil {1248 lastNode.Parent.RemoveChild(lastNode)1249 }1250 switch commonAncestor.DataAtom {1251 case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr:1252 p.fosterParent(lastNode)1253 default:1254 commonAncestor.AppendChild(lastNode)1255 }1256 // Steps 16-18. Reparent nodes from the furthest block's children1257 // to a clone of the formatting element.1258 clone := formattingElement.clone()1259 reparentChildren(clone, furthestBlock)1260 furthestBlock.AppendChild(clone)1261 // Step 19. Fix up the list of active formatting elements.1262 if oldLoc := p.afe.index(formattingElement); oldLoc != -1 && oldLoc < bookmark {1263 // Move the bookmark with the rest of the list.1264 bookmark--1265 }1266 p.afe.remove(formattingElement)1267 p.afe.insert(bookmark, clone)1268 // Step 20. Fix up the stack of open elements.1269 p.oe.remove(formattingElement)1270 p.oe.insert(p.oe.index(furthestBlock)+1, clone)1271 }1272}1273// inBodyEndTagOther performs the "any other end tag" algorithm for inBodyIM.1274// "Any other end tag" handling from 12.2.6.5 The rules for parsing tokens in foreign content1275// https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inforeign1276func (p *parser) inBodyEndTagOther(tagAtom a.Atom, tagName string) {1277 for i := len(p.oe) - 1; i >= 0; i-- {1278 // Two element nodes have the same tag if they have the same Data (a1279 // string-typed field). As an optimization, for common HTML tags, each1280 // Data string is assigned a unique, non-zero DataAtom (a uint32-typed1281 // field), since integer comparison is faster than string comparison.1282 // Uncommon (custom) tags get a zero DataAtom.1283 //1284 // The if condition here is equivalent to (p.oe[i].Data == tagName).1285 if (p.oe[i].DataAtom == tagAtom) &&1286 ((tagAtom != 0) || (p.oe[i].Data == tagName)) {1287 p.oe = p.oe[:i]1288 break1289 }1290 if isSpecialElement(p.oe[i]) {1291 break1292 }1293 }1294}1295// Section 12.2.6.4.8.1296func textIM(p *parser) bool {1297 switch p.tok.Type {1298 case ErrorToken:1299 p.oe.pop()1300 case TextToken:1301 d := p.tok.Data1302 if n := p.oe.top(); n.DataAtom == a.Textarea && n.FirstChild == nil {1303 // Ignore a newline at the start of a <textarea> block.1304 if d != "" && d[0] == '\r' {1305 d = d[1:]1306 }1307 if d != "" && d[0] == '\n' {1308 d = d[1:]1309 }1310 }1311 if d == "" {1312 return true1313 }1314 p.addText(d)1315 return true1316 case EndTagToken:1317 p.oe.pop()1318 }1319 p.im = p.originalIM1320 p.originalIM = nil1321 return p.tok.Type == EndTagToken1322}1323// Section 12.2.6.4.9.1324func inTableIM(p *parser) bool {1325 switch p.tok.Type {1326 case TextToken:1327 p.tok.Data = strings.Replace(p.tok.Data, "\x00", "", -1)1328 switch p.oe.top().DataAtom {1329 case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr:1330 if strings.Trim(p.tok.Data, whitespace) == "" {1331 p.addText(p.tok.Data)1332 return true1333 }1334 }1335 case StartTagToken:1336 switch p.tok.DataAtom {1337 case a.Caption:1338 p.clearStackToContext(tableScope)1339 p.afe = append(p.afe, &scopeMarker)1340 p.addElement()1341 p.im = inCaptionIM1342 return true1343 case a.Colgroup:1344 p.clearStackToContext(tableScope)1345 p.addElement()1346 p.im = inColumnGroupIM1347 return true1348 case a.Col:1349 p.parseImpliedToken(StartTagToken, a.Colgroup, a.Colgroup.String())1350 return false1351 case a.Tbody, a.Tfoot, a.Thead:1352 p.clearStackToContext(tableScope)1353 p.addElement()1354 p.im = inTableBodyIM1355 return true1356 case a.Td, a.Th, a.Tr:1357 p.parseImpliedToken(StartTagToken, a.Tbody, a.Tbody.String())1358 return false1359 case a.Table:1360 if p.popUntil(tableScope, a.Table) {1361 p.resetInsertionMode()1362 return false1363 }1364 // Ignore the token.1365 return true1366 case a.Style, a.Script, a.Template:1367 return inHeadIM(p)1368 case a.Input:1369 for _, t := range p.tok.Attr {1370 if t.Key == "type" && strings.ToLower(t.Val) == "hidden" {1371 p.addElement()1372 p.oe.pop()1373 return true1374 }1375 }1376 // Otherwise drop down to the default action.1377 case a.Form:1378 if p.oe.contains(a.Template) || p.form != nil {1379 // Ignore the token.1380 return true1381 }1382 p.addElement()1383 p.form = p.oe.pop()1384 case a.Select:1385 p.reconstructActiveFormattingElements()1386 switch p.top().DataAtom {1387 case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr:1388 p.fosterParenting = true1389 }1390 p.addElement()1391 p.fosterParenting = false1392 p.framesetOK = false1393 p.im = inSelectInTableIM1394 return true1395 }1396 case EndTagToken:1397 switch p.tok.DataAtom {1398 case a.Table:1399 if p.popUntil(tableScope, a.Table) {1400 p.resetInsertionMode()1401 return true1402 }1403 // Ignore the token.1404 return true1405 case a.Body, a.Caption, a.Col, a.Colgroup, a.Html, a.Tbody, a.Td, a.Tfoot, a.Th, a.Thead, a.Tr:1406 // Ignore the token.1407 return true1408 case a.Template:1409 return inHeadIM(p)1410 }1411 case CommentToken:1412 p.addChild(&Node{1413 Type: CommentNode,1414 Data: p.tok.Data,1415 })1416 return true1417 case DoctypeToken:1418 // Ignore the token.1419 return true1420 case ErrorToken:1421 return inBodyIM(p)1422 }1423 p.fosterParenting = true1424 defer func() { p.fosterParenting = false }()1425 return inBodyIM(p)1426}1427// Section 12.2.6.4.11.1428func inCaptionIM(p *parser) bool {1429 switch p.tok.Type {1430 case StartTagToken:1431 switch p.tok.DataAtom {1432 case a.Caption, a.Col, a.Colgroup, a.Tbody, a.Td, a.Tfoot, a.Thead, a.Tr:1433 if !p.popUntil(tableScope, a.Caption) {1434 // Ignore the token.1435 return true1436 }1437 p.clearActiveFormattingElements()1438 p.im = inTableIM1439 return false1440 case a.Select:1441 p.reconstructActiveFormattingElements()1442 p.addElement()1443 p.framesetOK = false1444 p.im = inSelectInTableIM1445 return true1446 }1447 case EndTagToken:1448 switch p.tok.DataAtom {1449 case a.Caption:1450 if p.popUntil(tableScope, a.Caption) {1451 p.clearActiveFormattingElements()1452 p.im = inTableIM1453 }1454 return true1455 case a.Table:1456 if !p.popUntil(tableScope, a.Caption) {1457 // Ignore the token.1458 return true1459 }1460 p.clearActiveFormattingElements()1461 p.im = inTableIM1462 return false1463 case a.Body, a.Col, a.Colgroup, a.Html, a.Tbody, a.Td, a.Tfoot, a.Th, a.Thead, a.Tr:1464 // Ignore the token.1465 return true1466 }1467 }1468 return inBodyIM(p)1469}1470// Section 12.2.6.4.12.1471func inColumnGroupIM(p *parser) bool {1472 switch p.tok.Type {1473 case TextToken:1474 s := strings.TrimLeft(p.tok.Data, whitespace)1475 if len(s) < len(p.tok.Data) {1476 // Add the initial whitespace to the current node.1477 p.addText(p.tok.Data[:len(p.tok.Data)-len(s)])1478 if s == "" {1479 return true1480 }1481 p.tok.Data = s1482 }1483 case CommentToken:1484 p.addChild(&Node{1485 Type: CommentNode,1486 Data: p.tok.Data,1487 })1488 return true1489 case DoctypeToken:1490 // Ignore the token....

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...19 reader8000.HandleFunc("/historical_rates.json", beReader.HandleReaderHistoricalJson)20 writer8001 := http.NewServeMux()21 writer8001.HandleFunc("/", beWriter.HandleWriterHtml)22 writer8001.HandleFunc("/index.html", beWriter.HandleWriterHtml)23 writer8001.HandleFunc("/add_date.html", beWriter.HandleWriterAddDateHtml)24 writer8001.HandleFunc("/add_date.json", beWriter.HandleWriterAddDateJson)25 writer8001.HandleFunc("/add_rss.html", beWriter.HandleWriterAddRssHtml)26 writer8001.HandleFunc("/add_rss.json", beWriter.HandleWriterAddRssJson)27 writer8001.HandleFunc("/fill_gaps.html", beWriter.HandleWriterFeelGapsHtml)28 writer8001.HandleFunc("/fill_gaps.json", beWriter.HandleWriterFeelGapsJson)29 writer8001.HandleFunc("/missing_dates.html", beWriter.HandleWriterGetMissingHtml)30 writer8001.HandleFunc("/missing_dates.json", beWriter.HandleWriterGetMissingJson)31 writer8001.HandleFunc("/lock.html", beWriter.HandleWriterLockHtml)32 writer8001.HandleFunc("/lock.json", beWriter.HandleWriterLockJson)33 writer8001.HandleFunc("/unlock.html", beWriter.HandleWriterUnLockHtml)34 writer8001.HandleFunc("/unlock.json", beWriter.HandleWriterUnLockJson)35 admin8002 := http.NewServeMux()36 admin8002.HandleFunc("/", beAdmin.HandleAdminHtml)37 admin8002.HandleFunc("/index.html", beAdmin.HandleAdminHtml)38 // For compatibility with previous version:39 reader8000.HandleFunc("/actual_rates/", beReader.HandleReaderActualHtml)40 reader8000.HandleFunc("/historic_rates/", beReader.HandleReaderHistoricalHtml)41 writer8001.HandleFunc("/add_date/", beWriter.HandleWriterAddDateHtml)42 writer8001.HandleFunc("/add_rss/", beWriter.HandleWriterAddRssHtml)43 writer8001.HandleFunc("/fill_gaps/", beWriter.HandleWriterFeelGapsHtml)44 writer8001.HandleFunc("/missing_dates/", beWriter.HandleWriterGetMissingHtml)45 writer8001.HandleFunc("/pause/", beWriter.HandleWriterLockHtml)46 writer8001.HandleFunc("/unpause/", beWriter.HandleWriterUnLockHtml)47 go func() {48 http.ListenAndServe(":8000", reader8000)49 log.Print(http.ListenAndServe(":8000", handlers.LoggingHandler(os.Stdout, reader8000)))50 }()51 go func() {52 http.ListenAndServe(":8001", writer8001)53 log.Print(http.ListenAndServe(":8001", handlers.LoggingHandler(os.Stdout, writer8001)))54 }()55 go func() {56 http.ListenAndServe(":8002", admin8002)...

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 tpl, err := template.ParseFiles("tpl.gohtml")4 if err != nil {5 log.Fatalln(err)6 }7 err = tpl.Execute(os.Stdout, 42)8 if err != nil {9 log.Fatalln(err)10 }11}12{{. | html}}13import (14func main() {15 tpl, err := template.ParseFiles("tpl.gohtml")16 if err != nil {17 log.Fatalln(err)18 }19 err = tpl.Execute(os.Stdout, "<h1>Hey</h1>")20 if err != nil {21 log.Fatalln(err)22 }23}24{{. | html}}25<p>&lt;h1&gt;Hey&lt;/h1&gt;</p>26import (27func main() {28 tpl, err := template.ParseFiles("tpl.gohtml")29 if err != nil {30 log.Fatalln(err)31 }32 err = tpl.Execute(os.Stdout, `<script>alert("Hello")</script>`)33 if err != nil {34 log.Fatalln(err)35 }36}37{{. | html}}38<p>&lt;script&gt;alert(&#34;Hello&#34;)&lt;/script&gt;</p>39import (40func main() {41 tpl, err := template.ParseFiles("tpl.gohtml")42 if err != nil {43 log.Fatalln(err)44 }45 err = tpl.Execute(os.Stdout

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("Hello, world!"))4}5import (6func main() {7 tmpl, err := template.New("test").Parse("{{.Name}} is {{.Age}} years old")8 if err != nil {9 panic(err)10 }11 err = tmpl.Execute(os.Stdout, map[string]interface{}{"Name": "John", "Age": 24})12 if err != nil {13 panic(err)14 }15}16import (17func main() {18 tmpl, err := template.New("test").Parse("{{.Name}} is {{.Age}} years old")19 if err != nil {20 panic(err)21 }22 err = tmpl.Execute(os.Stdout, map[string]interface{}{"Name": "John", "Age": 24})23 if err != nil {24 panic(err)25 }26}27import (28func main() {29 tmpl, err := template.New("test").Parse("{{.Name}} is {{.Age}} years old")30 if err != nil {31 panic(err)32 }33 err = tmpl.Execute(os.Stdout, map[string]interface{}{"Name": "John", "Age": 24})34 if err != nil {35 panic(err)36 }37}38import (39func main() {40 tmpl, err := template.New("test").Parse("{{.Name}} is {{.Age}} years old")41 if err != nil {42 panic(err)43 }44 err = tmpl.Execute(os.Stdout, map[string]interface{}{"Name": "John", "Age": 24})45 if err != nil {46 panic(err)47 }48}49import (50func main() {

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("Hello, world!"))4 fmt.Println(html.EscapeString("<script>alert('you have been pwned')</script>"))5}6import (7func main() {8 fmt.Println(html.UnescapeString("Hello, world!"))9 fmt.Println(html.UnescapeString("&lt;script&gt;alert(&#39;you have been pwned&#39;)&lt;/script&gt;"))10}11import (12func main() {13 fmt.Println(html.UnescapeString("Hello, world!"))14 fmt.Println(html.UnescapeString("&lt;script&gt;alert(&#39;you have been pwned&#39;)&lt;/script&gt;"))15}16import (17func main() {18 fmt.Println(html.UnescapeString("Hello, world!"))19 fmt.Println(html.UnescapeString("&lt;script&gt;alert(&#39;you have been pwned&#39;)&lt;/script&gt;"))20}21import (22func main() {23 fmt.Println(html.UnescapeString("Hello, world!"))24 fmt.Println(html.UnescapeString("&lt;script&gt;alert(&#39;you have been pwned&#39;)&lt;/script&gt;"))25}26import (27func main() {28 fmt.Println(html.UnescapeString("Hello, world!"))29 fmt.Println(html.UnescapeString("&lt;script&gt;alert(&#39;you have been pwned&#39;)&lt;/script&gt;"))30}31import (32func main() {33 fmt.Println(html.Un

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("<script>alert('Hello, world!');</script>"))4}5&lt;script&gt;alert(&#39;Hello, world!&#39;);&lt;/script&gt;6func EscapeString(s string) string7func UnescapeString(s string) string

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1func main() {2 h.Add("a", "b", "c")3 fmt.Printf("%v", h)4}5func main() {6 h.Add("a", "b", "c")7 fmt.Printf("%v", h)8}9func main() {10 h.Add("a", "b", "c")11 fmt.Printf("%v", h)12}13func main() {14 h.Add("a", "b", "c")15 fmt.Printf("%v", h)16}17func main() {18 h.Add("a", "b", "c")19 fmt.Printf("%v", h)20}21func main() {22 h.Add("a", "b", "c")23 fmt.Printf("%v", h)24}25func main() {26 h.Add("a", "b", "c")27 fmt.Printf("%v", h)28}29func main() {30 h.Add("a", "b", "c")31 fmt.Printf("%v", h)32}33func main() {34 h.Add("a", "b", "c")35 fmt.Printf("%v", h)36}

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("Hello, world!"))4}5import (6func main() {7 fmt.Println(html.UnescapeString("Hello, world!"))8}9import (10func main() {11 fmt.Println(html.EscapeString("Hello, world!"))12}13import (14func main() {15 fmt.Println(html.UnescapeString("Hello, world!"))16}17import (18func main() {19 fmt.Println(html.EscapeString("Hello, world!"))20}21import (22func main() {

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.Add(5, 6))4 fmt.Println(html.Add(10, 6))5}6import (7func main() {8 fmt.Println(html.Add(5, 6))9 fmt.Println(html.Add(10, 6))10}11import (12func main() {13 fmt.Println(html.Add(5, 6))14 fmt.Println(html.Add(10, 6))15}16import (17func main() {18 fmt.Println(html.Add(5, 6))19 fmt.Println(html.Add(10, 6))20}21import (22func main() {23 fmt.Println(html.Add(5, 6))24 fmt.Println(html.Add(10, 6))25}26import (27func main() {28 fmt.Println(html.Add(5, 6))29 fmt.Println(html.Add(10, 6))30}31import (32func main() {33 fmt.Println(html.Add(5, 6))34 fmt.Println(html.Add(10, 6))35}36import (37func main() {38 fmt.Println(html.Add(5, 6

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful