diff --git a/CHANGES.md b/CHANGES.md
index b1413c29a5..cb84f39877 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -26,6 +26,7 @@ Core Grammars:
- enh(json) add json5 support [Kerry Shetline][]
- fix(css) `unicode-range` parsing, issue #4253 [Kerry Shetline][]
- fix(csharp) Support digit separators [te-ing][]
+- enh(python) Support t-strings [Nicolas Le Cam][]
Documentation:
diff --git a/src/languages/python.js b/src/languages/python.js
index 2604889790..ab7930c030 100644
--- a/src/languages/python.js
+++ b/src/languages/python.js
@@ -194,7 +194,7 @@ export default function(hljs) {
relevance: 10
},
{
- begin: /([fF][rR]|[rR][fF]|[fF])'''/,
+ begin: /([fFtT][rR]|[rR][fFtT]|[fFtT])'''/,
end: /'''/,
contains: [
hljs.BACKSLASH_ESCAPE,
@@ -204,7 +204,7 @@ export default function(hljs) {
]
},
{
- begin: /([fF][rR]|[rR][fF]|[fF])"""/,
+ begin: /([fFtT][rR]|[rR][fFtT]|[fFtT])"""/,
end: /"""/,
contains: [
hljs.BACKSLASH_ESCAPE,
@@ -232,7 +232,7 @@ export default function(hljs) {
end: /"/
},
{
- begin: /([fF][rR]|[rR][fF]|[fF])'/,
+ begin: /([fFtT][rR]|[rR][fFtT]|[fFtT])'/,
end: /'/,
contains: [
hljs.BACKSLASH_ESCAPE,
@@ -241,7 +241,7 @@ export default function(hljs) {
]
},
{
- begin: /([fF][rR]|[rR][fF]|[fF])"/,
+ begin: /([fFtT][rR]|[rR][fFtT]|[fFtT])"/,
end: /"/,
contains: [
hljs.BACKSLASH_ESCAPE,
diff --git a/test/markup/python/template-strings.expect.txt b/test/markup/python/template-strings.expect.txt
new file mode 100644
index 0000000000..ea18264ea5
--- /dev/null
+++ b/test/markup/python/template-strings.expect.txt
@@ -0,0 +1,10 @@
+t"Hello {name}"
+T"Hello {name}"
+t"Hello {name!r}"
+t"Value: {value:.2f}"
+t"Value: {value:.{precision}f}"
+t"Hello {name=}"
+rt'Did you say "{trade}"?\n'
+tr'Did you say "{trade}"?\n'
+t"Hello {(lambda: name)}"
+t"Hello {await get_name()}"
diff --git a/test/markup/python/template-strings.txt b/test/markup/python/template-strings.txt
new file mode 100644
index 0000000000..1519e8d80b
--- /dev/null
+++ b/test/markup/python/template-strings.txt
@@ -0,0 +1,10 @@
+t"Hello {name}"
+T"Hello {name}"
+t"Hello {name!r}"
+t"Value: {value:.2f}"
+t"Value: {value:.{precision}f}"
+t"Hello {name=}"
+rt'Did you say "{trade}"?\n'
+tr'Did you say "{trade}"?\n'
+t"Hello {(lambda: name)}"
+t"Hello {await get_name()}"