Skip to content

comment highlighting continues after HTML tag #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Konfekt opened this issue Mar 28, 2025 · 3 comments · Fixed by #9
Closed

comment highlighting continues after HTML tag #8

Konfekt opened this issue Mar 28, 2025 · 3 comments · Fixed by #9
Assignees

Comments

@Konfekt
Copy link

Konfekt commented Mar 28, 2025

Hello, in a former issue #6 there was a typo making the issue irreproducible. This was about a comment header such as

    /**
     * Lorem..
     * <p>
    */
	...

highlighting the code following it as a comment. Expected would be that, similar to when the HTML tag, is missing, the text following is highlight as code. For example, in

Image

expected would public to be highlighted by the ID javaScopeDecl instead of JavaDocComment similar to what happens in

Image

where <p> is missing

@zzzyxwvut
Copy link
Owner

I only see the expected, second image syntax highlighting
regardless of whether <p> is present or not in a variety of
Vim builds.

Does the problem manifest itself when Vim is launched with
the --clean flag? Do any of Java syntax tests fail in your
local Vim repository's fork?

cd runtime/syntax
make clean java test

(In the java_comments_html.java test file, two <p> elements
also lack the end tag, i.e. </p>:

/**/ /*/ */ /* /*/ /*/*/ /*//*/ /** HTML comment tests.
* <p>There is no entry point method {@code main}:
* {@snippet file = HTMLSnippets.java region = main id = _01}
* <p>There is no textual representation:
* {@snippet class = HTMLSnippets region = toString id = _02} */
class HTMLCommentsTests implements Comparable<HTMLCommentsTests>

)

Does copying the HTML contents from the comment into a new
buffer, adding some additional HTML markup after <p>, and
doing setfiletype html, still produce runaway highlighting?

I would look at what :scriptnames reports. Perhaps some
syntax items from Vim-distributed syntax files are locally
overridden, or a third-party Java (or HTML) syntax file is
loaded. Can you move the cursor and post the definitions
for syntax items that claim p in <p> and p in public (after
<p>)?

echo synstack(line('.'), col('.'))
  \ ->foreach('exec "syntax list " . synIDattr(v:val, "name")')

@zzzyxwvut zzzyxwvut self-assigned this Mar 28, 2025
@Konfekt
Copy link
Author

Konfekt commented Mar 29, 2025

It is due to

let g:html_syntax_folding = 1
autocmd FileType html setlocal foldmethod=syntax

zzzyxwvut added a commit that referenced this issue Apr 22, 2025
HTML tags in Javadoc comments can additionally be folded
after applying
------------------------------------------------------------
	let g:html_syntax_folding = 1
	set foldmethod=syntax
------------------------------------------------------------

and giving explicit consent with
------------------------------------------------------------
	let g:java_consent_to_html_syntax_folding = 1
------------------------------------------------------------

Do not default to this kind of folding unless ALL start tags
and optional end tags are balanced in Javadoc comments;
otherwise, put up with creating runaway folds that break
syntax highlighting for the rest of a file.

Resolves #8.
@zzzyxwvut
Copy link
Owner

The documentation entry for HTML syntax folding insists on
creating a fold between a start tag and a corresponding end
tag for some element (:help html-folding). Void elements,
e.g. hr, do not have end tags and are never folded; whereas
optional end tags for elements like p etc. are assumed to
be present. Failing to observe this limitation, by either
making sure that all optional end tags are written when this
is convenient (e.g. with the aid of tidy(1)) or opting out
of tag folding altogether, leads to creating runaway folds
for unbalanced start tags and, in case of Javadoc comments,
breaking syntax highlighting for the rest of a file.

To deny inadvertent misuse, two variables must be defined to
allow tag folding in Javadoc comments: g:html_syntax_folding
and g:java_consent_to_html_syntax_folding. This way, the
said limitation will be made pronounced; users will not run
the risk of having syntax highlighting broken by default,
and they still be able to put up with possibly runaway folds
in buffers loaded with HTML files.

See #9.

zzzyxwvut added a commit to zzzyxwvut/vimvim that referenced this issue Apr 25, 2025
HTML tags in Javadoc comments can additionally be folded
after applying
------------------------------------------------------------
	let g:html_syntax_folding = 1
	set foldmethod=syntax
------------------------------------------------------------

and giving explicit consent with
------------------------------------------------------------
	let g:java_consent_to_html_syntax_folding = 1
------------------------------------------------------------

Do not default to this kind of folding unless ALL start tags
and optional end tags are balanced in Javadoc comments;
otherwise, put up with creating runaway folds that break
syntax highlighting for the rest of a file.

Resolves zzzyxwvut/java-vim#8.

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
zzzyxwvut added a commit to zzzyxwvut/vimvim that referenced this issue Apr 26, 2025
HTML tags in Javadoc comments can additionally be folded
after applying
------------------------------------------------------------
	let g:html_syntax_folding = 1
	set foldmethod=syntax
------------------------------------------------------------

and giving explicit consent with
------------------------------------------------------------
	let g:java_consent_to_html_syntax_folding = 1
------------------------------------------------------------

Do not default to this kind of folding unless ALL start tags
and optional end tags are balanced in Javadoc comments;
otherwise, put up with creating runaway folds that break
syntax highlighting for the rest of a file.

Resolves zzzyxwvut/java-vim#8.

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
zzzyxwvut added a commit to zzzyxwvut/vimvim that referenced this issue Apr 27, 2025
HTML tags in Javadoc comments can additionally be folded
after applying
------------------------------------------------------------
	let g:html_syntax_folding = 1
	set foldmethod=syntax
------------------------------------------------------------

and giving explicit consent with
------------------------------------------------------------
	let g:java_consent_to_html_syntax_folding = 1
------------------------------------------------------------

Do not default to this kind of folding unless ALL start tags
and optional end tags are balanced in Javadoc comments;
otherwise, put up with creating runaway folds that break
syntax highlighting.

Resolves zzzyxwvut/java-vim#8.

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
zzzyxwvut added a commit that referenced this issue Apr 27, 2025
HTML tags in Javadoc comments can additionally be folded
after applying
------------------------------------------------------------
	let g:html_syntax_folding = 1
	set foldmethod=syntax
------------------------------------------------------------

and giving explicit consent with
------------------------------------------------------------
	let g:java_consent_to_html_syntax_folding = 1
------------------------------------------------------------

Do not default to this kind of folding unless ALL start tags
and optional end tags are balanced in Javadoc comments;
otherwise, put up with creating runaway folds that break
syntax highlighting.

Resolves #8.
chrisbra pushed a commit to vim/vim that referenced this issue Apr 28, 2025
HTML tags in Javadoc comments can additionally be folded
after applying
------------------------------------------------------------
	let g:html_syntax_folding = 1
	set foldmethod=syntax
------------------------------------------------------------

and giving explicit consent with
------------------------------------------------------------
	let g:java_consent_to_html_syntax_folding = 1
------------------------------------------------------------

Do not default to this kind of folding unless ALL start tags
and optional end tags are balanced in Javadoc comments;
otherwise, put up with creating runaway folds that break
syntax highlighting.

resolves: zzzyxwvut/java-vim#8.
closes: #17216

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
zeertzjq added a commit to zeertzjq/neovim that referenced this issue Apr 29, 2025
…adoc comments

HTML tags in Javadoc comments can additionally be folded
after applying
------------------------------------------------------------
	let g:html_syntax_folding = 1
	set foldmethod=syntax
------------------------------------------------------------

and giving explicit consent with
------------------------------------------------------------
	let g:java_consent_to_html_syntax_folding = 1
------------------------------------------------------------

Do not default to this kind of folding unless ALL start tags
and optional end tags are balanced in Javadoc comments;
otherwise, put up with creating runaway folds that break
syntax highlighting.

resolves: zzzyxwvut/java-vim#8.
closes: vim/vim#17216

vim/vim@910bfd5

Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
zeertzjq added a commit to neovim/neovim that referenced this issue Apr 29, 2025
…adoc comments (#33718)

HTML tags in Javadoc comments can additionally be folded
after applying
------------------------------------------------------------
	let g:html_syntax_folding = 1
	set foldmethod=syntax
------------------------------------------------------------

and giving explicit consent with
------------------------------------------------------------
	let g:java_consent_to_html_syntax_folding = 1
------------------------------------------------------------

Do not default to this kind of folding unless ALL start tags
and optional end tags are balanced in Javadoc comments;
otherwise, put up with creating runaway folds that break
syntax highlighting.

resolves: zzzyxwvut/java-vim#8.
closes: vim/vim#17216

vim/vim@910bfd5

Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants