python-inline-source
python-inline-source copied to clipboard
Python Inline Source Syntax Highlighting Using Type Annotations
Python Inline Source Syntax Highlighting Using Type Annotations
This project enables inline syntax highligting of strings in python source files for multiple languages using type annotations.
Supports html, css, javascript, typescript, sql, graphql,
multiple css extension languages, template languages and many more,
see below for a full list.
Uses typing.Annotated
to annotate the str type with the language used. You can use
typing.get_type_hints
at runtime to determine the language that a string has been annotated with.
- sourcetypes Python Types Package.
- vscode-python-inline-source VS Code Plugin.
Installation
Python package:
pip install sourcetypes
VS Code plugin:
Install python-inline-source from extensions (ctrl + shift + x or cmd + shift + x
on mac).
Also available on marketplace.visualstudio.com
Example

Usage
Use a type decoration named for language that you are using:
import sourcetypes
my_html_string: sourcetypes.html = """
<h1>Some HTML</h1>
"""
or:
from sourcetypes import html
my_html_string: html = """
<h1>Some HTML</h1>
"""
Supported Languages
markdown(aliased asmd)htmldjango_html(aliased asdjango)django_txtjinjajinja_htmlcss(aliased asstyle, andstyles)scsslesssassstylusjavascript(aliased asjs)jsx(aliased asjavascriptreact, andreact)typescript(aliased asts)tsx(aliased astypescriptreact)coffeescript(aliased ascoffee)sqljsonyamlgraphqlxmlpython