Notepad ++ loses HTML tags that highlight after any <% Mako template tag. How to disable this behavior?

Let me attach a photo to explain:

enter image description here

So, after any Mako tag ( <%block , <%include , ets.), It makes the subsequent HTML code an integer single black color. I don’t know what to do with it. Options -> Style Options settings do not help.

I tried to disable asp syntax coloring in the stylers.xml file by taking the <LexerType name="asp" desc="asp" ext="asp">....</LexerType> part under the comment. As a result, I found that asp disappeared from Options -> Style Options . But the subsequent code is still black.

As the Mako Website says , you can set lexer.html.mako=1 in SciTEGlobal.properties . I did and tried to put this SciTEGlobal.properties in the directory where notepad++.exe lives or is in the Application Data\Notepad++ directory. It does not help.

How can I configure Notepad ++ to at least consider Mako tags as simple lines in an HTML document? No effect on another HTML label.

+4
source share
7 answers

After installing the "Python Script" plugin, add the file "startup.py" as follows:

 # Enable HTML Mako Template Syntax Highlighting def enableMako(args): editor.setProperty('lexer.html.mako', '1') notepad.callback(enableMako, [NOTIFICATION.READY, NOTIFICATION.BUFFERACTIVATED]) enableMako({}) 

The default file location is: C: \ Program Files \ Notepad ++ \ plugins \ PythonScript \ scripts \ startup.py

Since the mako option is per-buffer, it needs to be activated every time we start looking at it. We do this by registering the enableMako callback function.

In addition, in order for this to take effect, as soon as we open Notepad ++, we need to set the “Initialization” to “ATSTARTUP” in the following menu: Plugins → Python Script → Configuration

Finally, to automatically apply this syntax highlighting to .mako files, go to "Settings" → "Style Configurator", select "HTML" from the list of languages, and add mako to "User ext.". field.

+3
source

This is the workaround I used:

1) I followed the tip for using Python Scripts Plugin ( http://npppythonscript.sourceforge.net/ ).

2) Wrap the “Compare Clear Result Command” in a Python Script called CompareClearResultWrapper.py (the code is at the end).

3) Through the plugin configuration add MenuItem for Script CompareClearResultWrapper

4) Match the plugin command with the shortcut CTRL + ALT + D.

5) There seems to be some problem if you are comparing the last file in the correct view.

Here is the Script CompareClearResultWrapper code:

  def clearResultWrapper(): console.clear() console.show() for f in notepad.getFiles(): console.write( "filename, bufferID, index, view = %s\r\n" % str( f ) ) bufferID_Lang = [] for view in ( 0, 1 ): index = notepad.getCurrentDocIndex( view ) notepad.activateIndex( view, index ) fname = notepad.getCurrentFilename() bufferID = notepad.getCurrentBufferID() langType = notepad.getLangType( bufferID ) bufferID_Lang.append( ( view, index, bufferID, langType ) ) console.write( "view, fname, index, bufferID, langType = %s\r\n" % str( ( view, fname, index, bufferID, langType ) ) ) notepad.runPluginCommand( 'Compare', 'Clear Results' ) for ( view, index, bufferID, langType ) in bufferID_Lang: notepad.setLangType( LANGTYPE.TXT, bufferID ) # RESET notepad.setLangType( langType, bufferID ) # Re-Imposta 
0
source

Quickfix:

  • Ctrl + a
  • Ctrl + C
  • Ctrl + v
0
source

I think,

 <% should have %> 

and try NotePad ++ 6.2, the latest version 6.3.3 contains a lot of errors

0
source

As you point out, SciLexer considers the unmatched <% endless comment. SciLexer has a workaround, but Notepad ++ does not allow you to set arbitrary properties for your SciLexer. But I'm so stuck in Notepad ++, and this problem makes Mako templates so hard to edit that I circumvented this, omitting <% altogether.

Then I bind the function to a TemplateLookup object that displays <% at runtime:

 template_lookup = TemplateLookup( ... ) # your usual lookup declaration here # Work around horrible Notepad++ display issue with Mako <% tags import types def generate_mako_tag(lookup, context, tag_body): template = Template("<%" + tag_body + "/>") template.lookup = lookup return template.render_context(context) template_lookup.tag = types.MethodType( generate_mako_tag, template_lookup, TemplateLookup ) # this binds the function to the lookup object 

In the templates provided by this TemplateLookup, instead

 <%include file="component.html") /> 

I write

 <% context.lookup.tag(context, "include file='component.html'") %> 

It still looks like an ASP comment, but it is closed, so the problem goes away.

It does not work with some declarative Mako tags (e.g. <%page ).

Nested quotes occasionally become annoying. Especially in earlier versions of Notepad ++, which have problems with single quotes, but there is a patch for this .

0
source

<!-- %> --> is a workaround, but your best friend is here. For some reason, it took me a while to stumble upon it.

 <%include file="foo.html" args="bar='baz'" /> 

breaks the formatting under it. But

 <%include file="foo.html" args="bar='baz'" /> <!-- %> --> 

leaves the correct formatting. SciLexer believes that the unsurpassed <% is an infinite page directive, but it seems you can embarrass it enough by closing the directive in a comment (!)

I am using Notepad ++ v5.3.1.

0
source

I have the same problem. After using the comparison tool, the syntax highlighting disappears. This happens for any file extension. I mainly work with batch scripts.

I have a solution to add the coloring back: you can right-click and go to “Plugin Commands”, then “Copy Text with Syntax Highlight”. This (at least for me) repeats all the coloring for the whole file.

But it is annoying when you need to do this every time you open a file or compare a file or do what you did to cause color loss.

-1
source

All Articles