PyCharm 2024.1 Help

Language Injection Settings dialog: JS Tagged Literal Injection

The dialog opens when you click the Add button and choose JS Tagged Literal Injection from the context menu, or select an entry and click the Edit button.

Item

Description

Name

The name of the injection.

Language

The language to be injected.

  • ID From this list, slect the ID or the name of the language to be injected.

  • Prefix A sequence of characters to be added before the corresponding string value.

  • Suffix A sequence of characters to be added after the corresponding string value.

The prefix and suffix are optional.

Template tag

In this field, specify one or several functions through which you want a template literal to be parsed. Use dots as separators.

Learn more from Tagged Templates.

Advanced

In this area, specify additional settings to narrow the context where the injection is applicable and thus to enable more fine-grained control over the injection process.

  • Value pattern - in this field, type a regular expression that determines the context to inject the language into. By using the first capturing group of the patterns as the target for injection, you can configure the procedure to have the language injected only into values that match a certain pattern or into multiple parts that match the pattern. For example, ^javascript:(.*) matches the javascript protocol that can be used in hyperlink-hrefs to execute JavaScript code.

  • Single file - If the option is off, the fragments that match the value pattern are treated separately, as different "files" - for example from the fragment editor's viewpoint.

    If the option is on, the corresponding fragments are all merged together to form a single unit, or "file".

    Given the value pattern

    xxx (.+) yyy (.+) zzz

    and the fragment

    xxx select * yyy from family zzz,

    select * and from family are treated as two independent fragments (or "files") if the option is off. If the option is on, select * from family is treated as a single unit or "file".

Last modified: 17 June 2024