Skip to content

JuroOravec/python-inline-source-2

 
 

Repository files navigation

Python Inline Source 2: Syntax Highlighting Using Type Annotations

The original Python Inline Source by Sam Willis is no longer maintained. Please raise your issues and questions in this repo.

The PyPI package and VSCode extension have also been migrated:

This fork is based on v0.0.4.

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.

Installation

Python package:

pip install sourcetypes2

VS Code plugin:

Install python-inline-source-2 from extensions (ctrl + shift + x or cmd + shift + x on mac).

Also available on marketplace.visualstudio.com

Example

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 as md)
  • html
  • django_html (aliased as django)
  • django_txt
  • jinja
  • jinja_html
  • css (aliased as style, and styles)
  • scss
  • less
  • sass
  • stylus
  • javascript (aliased as js)
  • jsx (aliased as javascriptreact, and react)
  • typescript (aliased as ts)
  • tsx (aliased as typescriptreact)
  • coffeescript (aliased as coffee)
  • sql
  • json
  • yaml
  • graphql
  • xml
  • python

About

Python Inline Source Syntax Highlighting Using Type Annotations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%