1 | // tok must come from htmlTok |
2 | // returns all container tags found (including content) as CNC |
3 | // honors nested tags correctly |
4 | static LL<S> findContainerTagDeep(L<S> tok, S tag) {
|
5 | new LL<S> l; |
6 | for (int i = 1; i < l(tok); i += 2) |
7 | if (isOpeningTag(tok.get(i), tag)) {
|
8 | int j, level = 1; |
9 | for (j = i+2; j < tok.size(); j += 2) |
10 | if (isOpeningTag(tok.get(j), tag)) |
11 | ++level; |
12 | else if (isTag(tok.get(j), "/" + tag)) {
|
13 | --level; |
14 | if (level == 0) {
|
15 | l.add(subList(tok, i-1, j+2)); // actual CNC |
16 | break; |
17 | } |
18 | } |
19 | } |
20 | ret l; |
21 | } |
22 | |
23 | static LL<S> findContainerTagDeep(S html, S tag) {
|
24 | ret findContainerTagDeep(htmlTok(html), tag); |
25 | } |
Began life as a copy of #1002309
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1008449 |
| Snippet name: | findContainerTagDeep - HTML/XML parsing, fixed tag name |
| Eternal ID of this version: | #1008449/3 |
| Text MD5: | 7f62194c86fe70ce4baab87ec4f47d59 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-07-24 03:11:37 |
| Source code size: | 740 bytes / 25 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1002 / 988 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |