Sublime Forum

Help with Syntax Definition Issue

#1

Hello,

Long-time ST user, first-time topic author…

I just encountered and submitted a syntax highlighting issue with a plugin (not my own). I want to offer a PR to the owner of this repo. Secondarily, I want to learn more about developing plugins for ST.

For context: This plugin includes syntax highlighting for Quarto Markdown files (.qmd). The issue seemingly stems from applying Markdown’s typical syntax rules—more specifically, the one that says underscores should be balanced on either side of the text the user intends to emphasize/italicize—within the scope of an {{< include >}} shortcode (see Includes section of Quarto’s Authoring guide).

I suspect a fix would something like "don’t apply any of these rules in a {{< ... >}} scope.

0 Likes

#2

It requres the syntax to include proper rules for those tags.

I am not familiar with Quarto in detail, but createing a syntax with support for such tags based on ST’s core Markdown syntax would look like:

%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
name: Markdown (Quarto)
scope: text.html.markdown.quarto
version: 2

extends: Packages/Markdown/Markdown.sublime-syntax

file_extensions:
  - qmd

contexts:

  prototype:
    - meta_prepend: true
    - include: template-tags

  template-tags:
    - match: '{{<'
      scope: punctuation.section.interpolation.begin.quarto
      push: template-tag-body

  template-tag-body:
    - meta_scope: meta.interpolation.quarto
    - match: '>}}'
      scope: punctuation.section.interpolation.end.quarto
      pop: 1
    - match: \b(?:include)\b
      scope: keyword.control.import.quarto

The prototype context is prepended to each context in a syntax, thus supporting such tags (nearly) everywhere. If those are to be supported within html, some extra steps are needed.

The outcome would be

grafik

A more advanced example including interpolation within html tags can be found in https://github.com/SublimeText/Liquid. Or have a look at https://github.com/sublimehq/Packages/blob/master/Go/Markdown%20(Go).sublime-syntax.

Quarto package seems to be based on a copy of ST’s Markdown syntax, thus related rules would need to be added directly to that syntax at appropriate position.

3 Likes