|
| 1 | +; When dealing with a self-closing element that spans multiple lines, this lets |
| 2 | +; us fold the attribute list. |
| 3 | +; |
| 4 | +; This query captures elements that happen to be self-closing but don't end |
| 5 | +; with an XHTML-style ` />`. Because `tree-sitter-html` doesn't distinguish |
| 6 | +; these from elements that can have content, we have to check the tag name to |
| 7 | +; know how to treat these. |
| 8 | + |
| 9 | +((element |
| 10 | + (start_tag |
| 11 | + (tag_name) @_IGNORE_) @fold) |
| 12 | + (#match? @_IGNORE_ "^(area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$") |
| 13 | +) |
| 14 | + |
| 15 | +; This one captures the XHTML-style nodes. |
| 16 | +(self_closing_tag) @fold |
| 17 | + |
| 18 | + |
| 19 | +; TODO: Right now, the fold cache doesn't work properly when a given range |
| 20 | +; satisfies more than one fold. We should employ `ScopeResolver` to fix this. |
| 21 | + |
| 22 | +; Fold up all of |
| 23 | +; |
| 24 | +; <div |
| 25 | +; foo="bar" |
| 26 | +; baz="thud"> |
| 27 | +; |
| 28 | +; </div> |
| 29 | +; |
| 30 | +; with the fold indicator appearing on whichever line has the `>` that closes |
| 31 | +; the opening tag. |
| 32 | +; |
| 33 | +; Usually this'll be the same line on which the tag opened; but when it isn't, |
| 34 | +; this allows for the attribute list of the opening element to be folded |
| 35 | +; separately from the element's contents. |
| 36 | +; |
| 37 | + |
| 38 | +(element |
| 39 | + (start_tag |
| 40 | + (tag_name) @_IGNORE_ |
| 41 | + ">" @fold) |
| 42 | + (#not-match? @_IGNORE_ "^(area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$") |
| 43 | + (#set! fold.endAt parent.parent.lastNamedChild.startPosition) |
| 44 | + (#set! fold.adjustToEndOfPreviousRow true) |
| 45 | +) |
| 46 | + |
| 47 | + |
| 48 | +; When we have… |
| 49 | +; |
| 50 | +; <div |
| 51 | +; foo="bar" |
| 52 | +; baz="thud" |
| 53 | +; > |
| 54 | +; |
| 55 | +; </div> |
| 56 | +; |
| 57 | +; …we can put a fold indicator on the line with `<div` and use it to fold up |
| 58 | +; all of a start tag's attributes. |
| 59 | +; |
| 60 | +; We keep the end of the fold on a separate line because otherwise we lose the |
| 61 | +; ability to independently toggle the folding of the element's contents. |
| 62 | +; |
| 63 | +(element |
| 64 | + (start_tag |
| 65 | + (tag_name) @_IGNORE_) @fold |
| 66 | + (#not-match? @_IGNORE_ "^(area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$") |
| 67 | + (#set! fold.endAt lastChild.startPosition) |
| 68 | + (#set! fold.adjustToEndOfPreviousRow true)) |
| 69 | + |
1 | 70 |
|
2 | 71 | [
|
3 |
| - (element) |
4 | 72 | (script_element)
|
5 | 73 | (style_element)
|
6 | 74 | ] @fold
|
|
0 commit comments