<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to get correct syntax highlighting for Python 3 formatted strings]]></title><description><![CDATA[<p dir="auto">Hi there,</p>
<p dir="auto">Python 3 recently introduced a new feature: formatted strings, which are ordinary strings with an ‘f’ or ‘F’ in front, for example:</p>
<pre><code>f'Hello World in a formatted string'
</code></pre>
<p dir="auto">much like raw strings are ordinary strings with an ‘r’ in front:</p>
<pre><code>r'Hello World raw'
</code></pre>
<p dir="auto">The problem is that Notepad++ correctly recognizes raw strings and highlights them all in the chosen color, including the leading ‘r’, while it doesn’t seem to recognize formatted strings, and as soon as you put an ‘f’ in front of a string, the whole string loses its colour and is rendered as ordinary code (e.g. same colour as any user-defined variable).</p>
<p dir="auto">I’m using the latest version of Notepad++; has this worked before? Is there a quick way to add a rule to syntax highlighting to take formatted strings into account? I tried to make sense of the parser definition file but gave up after a while.</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/17794/how-to-get-correct-syntax-highlighting-for-python-3-formatted-strings</link><generator>RSS for Node</generator><lastBuildDate>Wed, 20 May 2026 22:37:45 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/17794.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 Jun 2019 15:45:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to get correct syntax highlighting for Python 3 formatted strings on Wed, 12 Jun 2019 12:40:38 GMT]]></title><description><![CDATA[<p dir="auto">Thanks all for the comments. Yes, adding those four lines to stylers.xml worked perfectly.</p>
<p dir="auto">I’m glad it will be fixed in the next release. I knew the issue must have already been picked up by someone.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/44435</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/44435</guid><dc:creator><![CDATA[Giulio.Portioli]]></dc:creator><pubDate>Wed, 12 Jun 2019 12:40:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to get correct syntax highlighting for Python 3 formatted strings on Tue, 11 Jun 2019 19:57:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said:</p>
<blockquote>
<p dir="auto">Since you were apparently up to <a class="plugin-mentions-user plugin-mentions-a" href="/user/dail" aria-label="Profile: dail">@<bdi>dail</bdi></a> 's earlier “adventurous” challenge</p>
</blockquote>
<p dir="auto">Copying four lines of XML wasn’t overly adventurous for me.  I think trying to properly install that, and get it working with the python27.dll in PythonScript is beyond what I want to tackle for a “bummer”. :-)</p>
<p dir="auto">But thanks.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/44429</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/44429</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 11 Jun 2019 19:57:42 GMT</pubDate></item><item><title><![CDATA[Reply to How to get correct syntax highlighting for Python 3 formatted strings on Tue, 11 Jun 2019 18:35:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said</p>
<blockquote>
<p dir="auto">…bummed…</p>
</blockquote>
<p dir="auto">Since you were apparently up to <a class="plugin-mentions-user plugin-mentions-a" href="/user/dail" aria-label="Profile: dail">@<bdi>dail</bdi></a> 's earlier “adventurous” challenge, maybe you could put the Indiana Jones hat back on and do a sequel:  <a href="https://github.com/asottile/future-fstrings" rel="nofollow ugc">https://github.com/asottile/future-fstrings</a></p>
<p dir="auto">Disclaimer: I can live without f-strings in my Pythonscript efforts, so I have NOT pursued this myself.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/44427</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/44427</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 11 Jun 2019 18:35:06 GMT</pubDate></item><item><title><![CDATA[Reply to How to get correct syntax highlighting for Python 3 formatted strings on Tue, 11 Jun 2019 18:02:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dail" aria-label="Profile: dail">@<bdi>dail</bdi></a> said:</p>
<blockquote>
<p dir="auto">And actually it doesn’t require any code changes, just a few additions to an XML file.</p>
</blockquote>
<p dir="auto">Ah… so it was in the lexer, but because those styles weren’t defined in the stylers.xml, I wasn’t seeing the highlighting.   Yes, once I added those to my v7.7, the f-strings get highlighted, and I can change the colors in the Style Configurator as well.  (But if I make the same changes in v7.6.6, with the ancient scintilla component, it still doesn’t highlight the f, because the old scintilla doesn’t understand those extra styles)  Thanks for that.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said:</p>
<blockquote>
<p dir="auto">as a Python 3 user, I’d heard of f-strings, … Going forward, I’ll probably remember to use f-strings more,</p>
</blockquote>
<p dir="auto">Since my only Python programming is for Notepad++ PythonScript automation, I was bummed when I saw those f-strings in various tutorials, but then learned that for PythonScript’s 2.7 interpreter they were not available to me, and I was stuck with <code>'string'.format(...)</code>.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/44424</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/44424</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 11 Jun 2019 18:02:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to get correct syntax highlighting for Python 3 formatted strings on Tue, 11 Jun 2019 17:41:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dail" aria-label="Profile: dail">@<bdi>dail</bdi></a> said</p>
<blockquote>
<p dir="auto">…add those changes to your theme.</p>
</blockquote>
<p dir="auto">I went ahead and did that.  It worked great.  As I am using a themeless portable version of Notepad++, the file I edited was <code>...\npp.7.7.bin\stylers.xml</code>.</p>
<p dir="auto">Of course, as a Python 3 user, I’d <em>heard</em> of f-strings, but to this point never really tried them out in real code, favoring <code>'foo {} bar'.format(blah)</code> instead of the simpler <code>f'foo {blah} bar'</code>.  Going forward, I’ll probably remember to use f-strings more, thanks to this thread and <a class="plugin-mentions-user plugin-mentions-a" href="/user/dail" aria-label="Profile: dail">@<bdi>dail</bdi></a>’s commit.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/44423</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/44423</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 11 Jun 2019 17:41:16 GMT</pubDate></item><item><title><![CDATA[Reply to How to get correct syntax highlighting for Python 3 formatted strings on Tue, 11 Jun 2019 17:28:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said:</p>
<blockquote>
<p dir="auto">Also, see <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5698" rel="nofollow ugc">here</a>.  And <a href="https://www.python.org/dev/peps/pep-0498/" rel="nofollow ugc">here</a> for why you might care.</p>
</blockquote>
<p dir="auto">@giulioportioli As Alan pointed out, there has been a fix for it and it will be in the next release. And actually it doesn’t require any code changes, just a few additions to an XML file. If you feel adventurous take a look <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/pull/5699/files#diff-0e8d56e12e5d6853a3d3e6f56a732ee8R935" rel="nofollow ugc">here</a> and add those changes to your theme.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/44422</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/44422</guid><dc:creator><![CDATA[dail]]></dc:creator><pubDate>Tue, 11 Jun 2019 17:28:23 GMT</pubDate></item><item><title><![CDATA[Reply to How to get correct syntax highlighting for Python 3 formatted strings on Tue, 11 Jun 2019 17:08:21 GMT]]></title><description><![CDATA[<p dir="auto">Also, see <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5698" rel="nofollow ugc">here</a>.  And <a href="https://www.python.org/dev/peps/pep-0498/" rel="nofollow ugc">here</a> for why you might care.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/44421</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/44421</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 11 Jun 2019 17:08:21 GMT</pubDate></item><item><title><![CDATA[Reply to How to get correct syntax highlighting for Python 3 formatted strings on Tue, 11 Jun 2019 16:38:24 GMT]]></title><description><![CDATA[<p dir="auto">@giulioportioli, Welcome to the Notepad++ Community.  You said:</p>
<blockquote>
<p dir="auto">Is there a quick way to add a rule to syntax highlighting to take formatted strings into account?</p>
</blockquote>
<p dir="auto">Not native to Notepad++.  The Python lexer is compiled as part of the scintilla component (the underlying editor component, which is a separate codebase from Notepad++), and it would have to be recompiled to add that recognition.  (If it were an older Notepad++ I was actually surprised that Notepad++ v7.7, with it’s new Scintilla 4.1.4, didn’t recognize/highlight formatted strings.)</p>
<p dir="auto">However, all is not lost.  <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a>  has shared the <a href="https://notepad-plus-plus.org/community/topic/17283/perl-language-syntax-highlighting-troubles-bug-or-limitation/110" rel="nofollow ugc">EnhanceAnyBuiltinLexer.py</a>, which is a script for the PythonScript plugin, which allows adding highlights based on regular expressions – the nice thing about this is that it can be used <em>in conjunction with</em> another active lexer, so it can add more highlighting than the active lexer supports.  Thus, you should be able to come up with a regex (first guess would be something like <code>f(['"]).*?\1</code>, untested: my intention is to find f, followed by either a single or double quote mark, followed by other characters, until the next instance of the same style of quote; it’s not perfect (doesn’t handle escaped quotes in the string, for example), but it’s a starting place).</p>
]]></description><link>https://community.notepad-plus-plus.org/post/44420</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/44420</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 11 Jun 2019 16:38:24 GMT</pubDate></item></channel></rss>