Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FlameWolf/bc3f0cac6575f614ad503144d2ea7dbf to your computer and use it in GitHub Desktop.
Save FlameWolf/bc3f0cac6575f614ad503144d2ea7dbf to your computer and use it in GitHub Desktop.
How to display JavaScript template strings in markdown

One way is to use double backticks to wrap your code.

Example:

To display alert(`The sum is ${a + b}`);, type ``alert(`The sum is ${a + b}`);``.

But the double-tick approach will not work if you want to wrap an entire template string inside them, like this: ​`Sum: ${a + b}`​.

The trick here is to use triple backticks and a Zero-Width Space (ZWS) character. Example: ``[ZWS]`Sum: ${a + b}`[ZWS]``.

GitHub's editor will display the ZWS characters as red dots, so they'll be easy to locate and edit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment