Mark in sourcecode how to color stringliterals

Hi. I would like to share my idea how to improve python.
I suggest adding a way to syntax to indicate IDE how to color a stringliteral in sourcecode (I emphasize ,that it is only about sourcecode coloring in IDE). Like “TODO” it would not affect the behavior of the program. It would make IDE to color content of the stringliteral like sourcecode of indicated language should be colored and maybe mark out syntaxerrors. It would be useful if a stringliteral consist of sourcecode of some programminglanguage or markuplanguage. Colored code in stringliteral could still be darker or more dull, than code outside of stringliterals.
I suggest 2 syntaxes for that:

  • “[string content]”#COLOR("[coloring way]")
  • c("[coloring way]")"[string content]"

An example with first syntax:

@app.route("/an/address")
def page_generator():
    html_content="""<html>
    <head>
        <title>Facere eum veritatis asperiores</title>
    </head>
    <body>
        <div style="background-color:blue;border:3px solid black">
            <h1 style="display:inline">distinctio earum. Soluta id cupiditate aut porro sed</h1>
            <p>voluptatem. Qui quis omnis rerum molestiae occaecati ipsam pariatur</p>
        </div>
        <img src="/static/lorem.png" alt="pic of lorem" style="width:400px;height:500px;" border="1px">"""#COLOR("html")
    if request.form["wants_ipsum"]=="yes":
        html_content+="""        <img src="/static/ipsum.png" alt="pic of ipsum" style="width:1200px;height:400px;" border="1px">"""#COLOR("html")
    return html_content+"""    </body>
</html>"""#COLOR("html")

It should color stringliterals that contain html-sourcecode as html-sourcecode is colored.

Example with second syntax:

exec(c("python")"""def ef(i):
    while True:\n"""+\
c("python")"        yield i\n"*(input("insert Y if want to yield i:")=="Y")+\
c("python")"""        if i%13 and not i%2:
            i=i**2-i\n"""*(input("insert Y if want that:")=="Y")+\
c("python")"""        if not i%11:
            yield i//11\n"""*(input("insert Y if want that:")=="Y")+\
c("python")"""        if i<9 or i>10000:
            print(i)\n"""*(input("insert Y if want that:")=="Y")+\
c("python")"""        if i==783 or i==253421 or i==934148913:
            yield False\n"""*(input("insert Y if want that:")=="Y")+\
c("python")"""        if not i:
            return True\n"""*(input("insert Y if want that:")=="Y")+\
c("python")"""        if i==1:
            return True
        if i%2==0:
            i=i//2
        else:
            i=i*3+1"""*(input("insert Y if you want to do collatz:")=="Y"))
for v in ef(345):
    print(v)

It should color stringliterals that contain python-sourcecode as python-sourcecode is colored.

Another example with first syntax:

pattern=r"^(?:f|ht)tps?://www."#COLOR("re")
print(match(pattern, url))

And with second syntax:

print(match(rc("re")"^(?:f|ht)tps?://www.", url))

What do you think of this?

Python doesn’t care what colour your editor uses to colour string
literals. This suggestion has nothing to do with Python the language, it
is an editor feature.

Editors can have all sorts of specialised tagged comments to control
settings such as line length, tab width, etc. This would be another one.
Those comments are not part of the language Python.

Choose a text editor or IDE, and propose the feature to them.

Good luck!