0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

28 Commits

Author SHA1 Message Date
Aliaksei Budavei
dc7ed8f946
runtime(html): Optionally fold tags with the "expr" method
Tag folding poses a few difficulties.  Many elements, e.g.
"blockquote", are always delimited by start and end tags;
end tags for some elements, e.g. "p", can be omitted in
certain contexts; void elements, e.g. "hr", have no end tag.
Although the rules for supporting omissible end tags are
ad-hoc and involved, they apply to elements in scope.
Assuming syntactical wellformedness, an end tag can be
associated with its nearest matching start tag discoverable
in scope and towards the beginning of a file, whereas all
unbalanced tags and inlined tags can be disregarded.

For example:
------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">		<!-- >1 : 1 -->
  <body>			<!-- >2 : 2 -->
    <p>Paragraph #1.		<!--  = : 2 -->
    <p>				<!-- >3 : 3 -->
      Paragraph #2.		<!--  = : 3 -->
    </p>			<!-- <3 : 3 -->
    <p>Paragraph #3.</p>	<!--  = : 2 -->
  </body>			<!-- <2 : 2 -->
</html>				<!-- <1 : 1 -->
------------------------------------------------------------

(HTML comments here, "<!-- ... -->", record two values for
each folded line that are separated by ":", a value obtained
from "&foldexpr" and a value obtained from "foldlevel()".)

Innermost foldedable tags will be flattened.  For example:
------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">		<!-- >1 : 1 -->
  <body>			<!-- >2 : 2 -->
    <div class="block">		<!-- >3 : 3 -->
      <pre><code>		<!-- >4 : 4 -->
[CODE SNIPPET]			<!--  = : 4 -->
      </code></pre>		<!-- <4 : 4 -->
    </div>			<!-- <3 : 3 -->
  </body>			<!-- <2 : 2 -->
</html>				<!-- <1 : 1 -->
------------------------------------------------------------

No folding will be requested for the "<code>"-"</code>" tag
pair and reflected by "&foldexpr" because such a fold would
have claimed the same lines that the immediate fold of the
"<pre>"-"</pre>" tag already claims.

Run-on folded tags may confuse Vim.  When a file such as:
------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">		<!-- >1 : 1 -->
  <body>			<!-- >2 : 2 -->
    <div class="block">		<!-- >3 : 3 -->
      <pre>			<!-- >4 : 4 -->
	<code>			<!-- >5 : 5 -->
[CODE SNIPPET #1]		<!--  = : 5 -->
	</code>			<!-- <5 : 5 -->
      </pre>			<!-- <4 : 4 -->
    </div>			<!-- <3 : 3 -->
				<!--  = : 3 -->
    <div class="block">		<!-- >3 : 3 -->
      <pre>			<!-- >4 : 4 -->
	<code>			<!-- >5 : 5 -->
[CODE SNIPPET #2]		<!--  = : 5 -->
	</code>			<!-- <5 : 5 -->
      </pre>			<!-- <4 : 4 -->
    </div>			<!-- <3 : 3 -->
  </body>			<!-- <2 : 2 -->
</html>				<!-- <1 : 1 -->
------------------------------------------------------------

is reformatted as follows:
------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">		<!-- >1 : 1 -->
  <body>			<!-- >2 : 2 -->
    <div class="block">		<!-- >3 : 3 -->
      <pre>			<!-- >4 : 4 -->
	<code>			<!-- >5 : 5 -->
[CODE SNIPPET #1]		<!--  = : 5 -->
	</code>			<!-- <5 : 5 -->
      </pre>			<!-- <4 : 4 -->
    </div><div class="block"><pre><code> <!-- <3 : 3 -->
[CODE SNIPPET #2]		<!--  = : 2 ? -->
	</code>			<!-- <5 : 2 ? -->
      </pre>			<!-- <4 : 2 ? -->
    </div>			<!-- <3 : 2 ? -->
  </body>			<!-- <2 : 2 -->
</html>				<!-- <1 : 1 -->
------------------------------------------------------------

"&foldexpr" values will not be used as is for the lines
between (and including) "[CODE SNIPPET #2]" and "</div>".
(Cf. v9.1.0002.)

Having syntax highlighting in effect, tag folding using the
"fold-expr" method can be enabled with:
------------------------------------------------------------
	let g:html_expr_folding = 1
------------------------------------------------------------

By default, tag folding will be redone from scratch after
each occurrence of a TextChanged or an InsertLeave event.
Such frequency may not be desired, especially for large
files, and this recomputation can be disabled with:
------------------------------------------------------------
	let g:html_expr_folding_without_recomputation = 1
        doautocmd FileType
------------------------------------------------------------

To force another recomputation, do:
------------------------------------------------------------
	unlet! b:foldsmap
	normal zx
------------------------------------------------------------

References:
https://web.archive.org/web/20250328105626/https://html.spec.whatwg.org/multipage/syntax.html#optional-tags
https://en.wikipedia.org/wiki/Dangling_else

closes: #17141

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2025-05-10 21:40:41 +02:00
Christian Brabandt
df9f67e10d
runtime(html): update syntax script to sync by 250 minlines by default
closes: #14071

Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-07-30 20:22:20 +02:00
Mohamed Akram
917ff8a19d
runtime(html): bump length of character references in syntax script (#15022)
This allows handling longer references such as
`&CounterClockwiseContourIntegral;`.

Signed-off-by: Mohamed Akram <mohd.akram@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-06-16 16:47:36 +02:00
dkearns
a9058440b7
runtime(html): Update syntax file (#13591)
Add missing search element and update ARIA attribute list.

Add a very basic test file to check all elements are matched.

Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-11-28 20:41:41 +01:00
Bram Moolenaar
938ae280c7 Update runtime files. 2023-02-20 20:44:55 +00:00
Bram Moolenaar
d13166e788 Update runtime files 2022-11-18 21:49:57 +00:00
Bram Moolenaar
b529cfbd04 Update runtime files 2022-07-25 15:42:07 +01:00
Bram Moolenaar
c8cdf0f80b Update runtime files. 2021-03-13 13:28:13 +01:00
Bram Moolenaar
9faec4e3d4 Update runtime files. 2021-02-27 16:38:07 +01:00
Bram Moolenaar
ff78155aa1 Update runtime files 2020-03-19 20:37:11 +01:00
Bram Moolenaar
5666fcd0bd Update runtime files. 2019-12-26 14:35:26 +01:00
Bram Moolenaar
62e1bb4a11 Update runtime files. 2019-04-08 16:25:07 +02:00
Bram Moolenaar
d2f3a8b878 Update runtime files. 2018-06-19 14:35:59 +02:00
Bram Moolenaar
f0b03c4e98 Update runtime files 2017-12-17 17:17:07 +01:00
Bram Moolenaar
01164a6546 Long overdue runtime update. 2017-11-02 22:58:42 +01:00
Bram Moolenaar
690afe1fef Update runtime files. 2017-01-28 18:34:47 +01:00
Bram Moolenaar
68563937f5 Updated runtime files. 2017-01-10 13:31:15 +01:00
Bram Moolenaar
bc2eada542 Updated runtime files. 2017-01-02 21:27:47 +01:00
Bram Moolenaar
f37506f60f Updated runtime files. Remove HiLink commands. 2016-08-31 22:22:10 +02:00
Bram Moolenaar
89bcfda683 Updated runtime files. Remove version checks for Vim older than 6.0. 2016-08-30 23:26:57 +02:00
Bram Moolenaar
8feef4ff62 Update runtime files. 2015-01-07 16:57:10 +01:00
Bram Moolenaar
0c5fa7d740 Updated runtime files. 2012-10-05 22:26:30 +02:00
Bram Moolenaar
c81e5e79a0 updated for version 7.1a 2007-05-05 18:24:42 +00:00
Bram Moolenaar
9e54a0e753 updated for version 7.0d04 2006-04-14 20:42:25 +00:00
Bram Moolenaar
80fc04348a updated for version 7.0111 2005-07-20 22:06:07 +00:00
Bram Moolenaar
ce0842a6ee updated for version 7.0109 2005-07-18 21:58:11 +00:00
Bram Moolenaar
53180ce2e7 updated for version 7.0103 2005-07-05 21:48:14 +00:00
Bram Moolenaar
071d4279d6 updated for version 7.0001 2004-06-13 20:20:40 +00:00