Skip to content

jrburke/tts-syntax-highlight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Tagged template string syntax highlight

test.js is an example JS file that uses template strings to test editor syntax highlighting behavior.

Specifically, it tests if the editors can syntax highlight the HTML and CSS in the strings as HTML and CSS, if the tagged template string function ends in (case-insensitive) html or css, respectively.

Rationale

By targeting tagged template functions and looking at the suffix of the name, it gives us a hint to the content type inside the string, similar to a mime type. For security purposes, HTML and CSS should be escaping programmatic values (the stuff in the ${expression} parts), so using a function for a tagged template string will be commonplace.

Out of the possible parts of a JS function name to use for indicating the string type, it seems using the suffix, ending part of the function name makes the most sense: it is closest to the string value, and shoudl be a clearer, simpler regexp to use for syntax highlighting. If a developer wanted to get this syntax highlighting, but the tag function name was not the correct form, it is easy enough to create a local variable like var html = htmlify then use the html for the tagged template use.

Editors/source displays that are known to work as expected:

If you know of others, send the repo a pull request, ideally with a screenshot showing how test.js is displayed in the editor, and we can add it to this list.

Editor tracking info

Atom

atom/language-javascript

Sublime Text

vim

Default syntax file seems old, dated 2013, so no es2015 support. Seems like plugins are used instead. Need to investigate which ones are commonly used. From conversations on twitter, in no particular order:

About

An example JS file that uses template strings to test editor syntax highlighting behavior

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published