branch: elpa/typst-ts-mode commit 2dbf17da1a25718989afa652f71a46b65a06acaf Author: Meow King <mr.meowk...@anche.no> Commit: Meow King <mr.meowk...@anche.no>
feat(face): more precise face for some markup elements --- README.md | 2 +- basic-syntax.typ | 3 +- typst-ts-mode.el | 119 ++++++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 94 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 5f6ae564eb..dc7dd5850f 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ because Typst itself do this style. You may find `auto-save-visited-mode`, 7. `typst-ts-mode-before-compile-hook` and `typst-ts-mode-after-compile-hook` ### Raw block highlighting - +Only support tree-sitter languages. For more detailed documentation about raw block highlighting see [this documentation](./doc/raw-block-highlighing.md) 1. `typst-ts-mode-enable-raw-blocks-highlight` (default `t`) diff --git a/basic-syntax.typ b/basic-syntax.typ index 11870e0bc8..ad85254c64 100644 --- a/basic-syntax.typ +++ b/basic-syntax.typ @@ -14,7 +14,8 @@ _emph_ // emphasis "El Psy Kongraoo" // quote hello \ // line break `El Psy Kongraoo` // raw span -```bash // raw block +// raw block +```bash sudo rm -rf * ``` <label> // label diff --git a/typst-ts-mode.el b/typst-ts-mode.el index e4152cea36..733ad03c5a 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -174,9 +174,19 @@ is eliminated." ;; Markup Faces ================================================================= +(defface typst-ts-markup-header-indicator-face + '((t :weight bold)) + "Face for Typst ts markup header indicator.") + (defface typst-ts-markup-header-face '((t :weight bold)) - "The basic face for Typst ts markup headers.") + "Face for Typst ts markup headers text.") + +(defface typst-ts-markup-header-indicator-face-1 + `((t :inherit typst-ts-markup-header-indicator-face + :height ,(nth 0 typst-ts-markup-header-scale))) + "See `typst-ts-markup-header-indicator-face'." + :group 'typst-ts-faces) (defface typst-ts-markup-header-face-1 `((t :inherit typst-ts-markup-header-face @@ -184,30 +194,60 @@ is eliminated." "See `typst-ts-markup-header-face'." :group 'typst-ts-faces) +(defface typst-ts-markup-header-indicator-face-2 + `((t :inherit typst-ts-markup-header-indicator-face + :height ,(nth 1 typst-ts-markup-header-scale))) + "See `typst-ts-markup-header-indicator-face'." + :group 'typst-ts-faces) + (defface typst-ts-markup-header-face-2 `((t :inherit typst-ts-markup-header-face :height ,(nth 1 typst-ts-markup-header-scale))) "See `typst-ts-markup-header-face'." :group 'typst-ts-faces) +(defface typst-ts-markup-header-indicator-face-3 + `((t :inherit typst-ts-markup-header-indicator-face + :height ,(nth 2 typst-ts-markup-header-scale))) + "See `typst-ts-markup-header-indicator-face'." + :group 'typst-ts-faces) + (defface typst-ts-markup-header-face-3 `((t :inherit typst-ts-markup-header-face :height ,(nth 2 typst-ts-markup-header-scale))) "See `typst-ts-markup-header-face'." :group 'typst-ts-faces) +(defface typst-ts-markup-header-indicator-face-4 + `((t :inherit typst-ts-markup-header-indicator-face + :height ,(nth 3 typst-ts-markup-header-scale))) + "See `typst-ts-markup-header-indicator-face'." + :group 'typst-ts-faces) + (defface typst-ts-markup-header-face-4 `((t :inherit typst-ts-markup-header-face :height ,(nth 3 typst-ts-markup-header-scale))) "See `typst-ts-markup-header-face'." :group 'typst-ts-faces) +(defface typst-ts-markup-header-indicator-face-5 + `((t :inherit typst-ts-markup-header-indicator-face + :height ,(nth 4 typst-ts-markup-header-scale))) + "See `typst-ts-markup-header-indicator-face'." + :group 'typst-ts-faces) + (defface typst-ts-markup-header-face-5 `((t :inherit typst-ts-markup-header-face :height ,(nth 4 typst-ts-markup-header-scale))) "See `typst-ts-markup-header-face'." :group 'typst-ts-faces) +(defface typst-ts-markup-header-indicator-face-6 + `((t :inherit typst-ts-markup-header-indicator-face + :height ,(nth 5 typst-ts-markup-header-scale))) + "See `typst-ts-markup-header-indicator-face'." + :group 'typst-ts-faces) + (defface typst-ts-markup-header-face-6 `((t :inherit typst-ts-markup-header-face :height ,(nth 5 typst-ts-markup-header-scale))) @@ -219,27 +259,34 @@ is eliminated." "Face for url." :group 'typst-ts-faces) +(defface typst-ts-markup-emphasis-indicator-face + '((t :inherit italic)) + "Face for emphasis." + :group 'typst-ts-faces) + (defface typst-ts-markup-emphasis-face '((t :inherit italic)) "Face for emphasis." :group 'typst-ts-faces) +(defface typst-ts-markup-strong-indicator-face + '((t :inherit bold)) + "Face for strong." + :group 'typst-ts-faces) + (defface typst-ts-markup-strong-face '((t :inherit bold)) "Face for strong." :group 'typst-ts-faces) -(defface typst-ts-markup-item-face +(defface typst-ts-markup-item-indicator-face '((t :inherit shadow)) "Face for item." :group 'typst-ts-faces) -;; NOTE: add a defcustom option to let user choose whether to only fontify the -;; the whole element -;; same as `typst-ts-markup-rawspan-face' and `typst-ts-markup-rawblock-face' -(defface typst-ts-markup-term-face - nil - "Face for term." +(defface typst-ts-markup-item-face + '((t :inherit default)) + "Face for item." :group 'typst-ts-faces) (defface typst-ts-markup-term-indicator-face @@ -253,7 +300,7 @@ is eliminated." :group 'typst-ts-faces) (defface typst-ts-markup-term-description-face - '((t :inherit normal)) + '((t :inherit italic)) "Face for term." :group 'typst-ts-faces) @@ -282,11 +329,6 @@ is eliminated." "Face for rawblock and rawspan blob." :group 'typst-ts-faces) -(defface typst-ts-markup-rawblock-face - '((t :inherit normal)) - "Face for rawblock." - :group 'typst-ts-faces) - (defface typst-ts-markup-rawblock-indicator-face '((t :inherit typst-ts-markup-raw-indicator-face)) "Face for rawblock indicator." @@ -302,11 +344,6 @@ is eliminated." "Face for rawblock blob." :group 'typst-ts-faces) -(defface typst-ts-markup-rawspan-face - '((t :inherit normal)) - "Face for rawspan." - :group 'typst-ts-faces) - (defface typst-ts-markup-rawspan-indicator-face '((t :inherit typst-ts-markup-raw-indicator-face)) "Face for rawspan indicator." @@ -384,15 +421,41 @@ If you want to customize the rules, please customize the same name variable :language typst :feature markup-basic (,@(if typst-ts-markup-header-same-height - '((heading (text)) @typst-ts-markup-header-face) - '((heading "=" (text)) @typst-ts-markup-header-face-1 - (heading "==" (text)) @typst-ts-markup-header-face-2 - (heading "===" (text)) @typst-ts-markup-header-face-3 - (heading "====" (text)) @typst-ts-markup-header-face-4 - (heading "=====" (text)) @typst-ts-markup-header-face-5)) - (emph) @typst-ts-markup-emphasis-face - (strong) @typst-ts-markup-strong-face - (item "-" @typst-ts-markup-item-face) + '((heading "=" @typst-ts-markup-header-indicator-face + (text) @typst-ts-markup-header-face) + (heading "==" @typst-ts-markup-header-indicator-face + (text) @typst-ts-markup-header-face) + (heading "===" @typst-ts-markup-header-indicator-face + (text) @typst-ts-markup-header-face) + (heading "====" @typst-ts-markup-header-indicator-face + (text) @typst-ts-markup-header-face) + (heading "=====" @typst-ts-markup-header-indicator-face + (text) @typst-ts-markup-header-face) + (heading "======" @typst-ts-markup-header-indicator-face + (text) @typst-ts-markup-header-face)) + '((heading "=" @typst-ts-markup-header-indicator-face-1 + (text) @typst-ts-markup-header-face-1) + (heading "==" @typst-ts-markup-header-indicator-face-2 + (text) @typst-ts-markup-header-face-2) + (heading "===" @typst-ts-markup-header-indicator-face-3 + (text) @typst-ts-markup-header-face-3) + (heading "====" @typst-ts-markup-header-indicator-face-4 + (text) @typst-ts-markup-header-face-4) + (heading "=====" @typst-ts-markup-header-indicator-face-5 + (text) @typst-ts-markup-header-face-5) + (heading "======" @typst-ts-markup-header-indicator-face-6 + (text) @typst-ts-markup-header-face-6))) + (emph + "_" @typst-ts-markup-emphasis-indicator-face + (text) @typst-ts-markup-emphasis-face + "_" @typst-ts-markup-emphasis-indicator-face) + (strong + "*" @typst-ts-markup-strong-indicator-face + (text) @typst-ts-markup-strong-face + "*" @typst-ts-markup-strong-indicator-face) + (item + "-" @typst-ts-markup-item-indicator-face + (text) @typst-ts-markup-item-face) (term "/" @typst-ts-markup-term-indicator-face term: (text) @typst-ts-markup-term-term-face