How do I change markdown heading color by heading level in VS Code editor?
Asked Answered
G

2

11

My question is similar to this one but the answer given there is for Vim and I need one for VS Code. I'm a real newbie, and I tried to solve this myself, but these attempts failed me:

  • Markdown Preview GitHub Styling - Says it allows user-defined custom css, but it styles html preview, not the text in the editor

  • Markdown Theme Kit - Points to custom .css files, but the included ones don't tell me how to do it differently for different heading levels

  • Markdown Header Coloring - Claims to do exactly this, but when I try to put in user-defined css to give each heading level a different color, I still get color changes between headings of the same level, even after closing/restarting VS Code.

Help is very appreciated.

Gaol answered 13/4, 2020 at 3:30 Comment(0)
C
15

There is a built-in way to style text, including Markdown headings, in the editor without an extension, using VSCode's Colour Theme settings:

Open your settings.json (~/.config/Code/User/settings.json) or Ctrl+p "settings", and between the top-level {} insert for example:

"editor.tokenColorCustomizations": {
    "textMateRules": [
      {
          "scope": "heading.1.markdown entity.name.section.markdown, heading.1.markdown punctuation.definition.heading.markdown",
          "settings": {
              "foreground": "#9cecfb",
              "fontStyle": "bold",
          }
      },
      {
          "scope": "heading.2.markdown entity.name.section.markdown, heading.2.markdown punctuation.definition.heading.markdown",
          "settings": {
              "foreground": "#83a4d4",
          }
       }
    ]
}
Chungchungking answered 24/3, 2021 at 13:1 Comment(3)
Nice -- you may want to limit this color to a partular theme also, as in the "Semantic colors" example at the first link in this answer.Subkingdom
Awesome, thank you! I like these colors: colourlovers.com/palette/56122/Sweet_LollyTipi
Command+Shift+p and look for the 'Preference: Open User Settings (JSON)' option on MacOSDishabille
B
3

I faced the same issue and find a way with the VSCode extension "Markdown header coloring"

Basically you have to

  • install the extension
  • set some custom settings in settings.json. You can find examples of custom settings in the section "User defined header coloring"
  • do not forget to reload the window after each modification: open Command Palette → type Reload window
Berlyn answered 21/8, 2020 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.