notepad-plus-plus icon indicating copy to clipboard operation
notepad-plus-plus copied to clipboard

Yaml syntax highlighting does not respect empty lines in blocks of text

Open phoenikz opened this issue 5 years ago • 7 comments
trafficstars

Description of the Issue

Yaml syntax highlighting does not respect empty lines in blocks of text. An empty line is not considered to have lower indentation than the previous line, text blocks will continue across them.

Steps to Reproduce the Issue

Write yaml like this:

my_yaml_block: |
  This block is text

  even if the line above is empty
  these two lines below should also be highlighted as text. 

with row 2 empty

Expected Behavior

All lines above are highlighted as text

Actual Behavior

Rows 3 and 4 will be default-highlighted

Debug Information

Notepad++ v7.8.9 (64-bit) Build time : Jul 15 2020 - 20:31:49 Admin mode : OFF Local Conf mode : ON OS Name : Windows 10 Enterprise (64-bit) OS Version : 1809 OS Build : 17763.1457 Current ANSI codepage : 1252 Plugins : GitSCM.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppConverter.dll NppExport.dll NPPJSONViewer.dll NppXmlTreeviewPlugin.dll XMLTools.dll

phoenikz avatar Oct 20 '20 06:10 phoenikz

Suggest something similar to

diff --git a/scintilla/lexers/LexYAML.cxx b/scintilla/lexers/LexYAML.cxx
index 3002030d..e5a4cdfa 100644
--- a/scintilla/lexers/LexYAML.cxx
+++ b/scintilla/lexers/LexYAML.cxx
@@ -88,9 +88,11 @@ static void ColouriseYAMLLine(

                if ((parentLineState&YAML_STATE_MASK) == YAML_STATE_TEXT || (parentLineState&YAML_STATE_MASK) == YAML_STATE_TEXT_PARENT) {
                        unsigned int parentIndentAmount = parentLineState&(~YAML_STATE_MASK);
-                       if (indentAmount > parentIndentAmount) {
+                       if  (lineBuffer[indentAmount] == '\0' || indentAmount > parentIndentAmount) {
                                styler.SetLineState(currentLine, YAML_STATE_TEXT | parentIndentAmount);
-                               styler.ColourTo(endPos, SCE_YAML_TEXT);
+                               if (indentAmount > parentIndentAmount) {
+                                       styler.ColourTo(endPos, SCE_YAML_TEXT);
+                               }
                                return;
                        }
                }

And I'd be happy to write a pull request with it if you believe its correct.

phoenikz avatar Oct 20 '20 07:10 phoenikz

You can directly write to Scintilla.

ArkadiuszMichalski avatar Oct 20 '20 08:10 ArkadiuszMichalski

@phoenikz

What @ArkadiuszMichalski means is that this is a problem with Scintilla, not Notepad++. Thus there is nothing Notepad++ can do to fix it.

sasumner avatar Oct 20 '20 11:10 sasumner

https://sourceforge.net/p/scintilla/bugs/2218/

phoenikz avatar Oct 21 '20 13:10 phoenikz

@donho @sasumner

I can confirm this is NOT fixed in Notepad++ 7.9.3 Unicode Debug using the latest Scintilla 4.4.6 DLL. There are no YAML related updates to Scintilla change log since 3.7.5. Note that putting a single space on the blank line colors the text block correctly in both current 4.2.0 and 4.4.6.

Cheers.

vinsworldcom avatar Feb 22 '21 14:02 vinsworldcom

See #15273. Issue still exists with N++ v8.6.7.

chcg avatar Jun 12 '24 20:06 chcg

There is a related issue posted at https://github.com/notepad-plus-plus/notepad-plus-plus/issues/15273#issuecomment-2162139675, which I will repost here.

- run: |
    # first line of shell script
    # last line of shell script
  if: condition for running step
[
  {
    "run": "# first line of shell script\n# last line of shell script\n", 
    "if": "condition for running step"
  }
]

Notepad++ fails to highlight it correctly.

image

VS Code correctly highlights it.

image

GitHub actually highlights this correctly, even though GitHub fails when there is a blank line in the string.

image

theonlypwner avatar Jun 12 '24 23:06 theonlypwner

Reported again to Lexilla https://github.com/ScintillaOrg/lexilla/issues/326

oldium avatar Aug 14 '25 16:08 oldium