diff --git a/book/src/themes.md b/book/src/themes.md index 9abcfe8c186c0..78b4d14bd8acb 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -166,6 +166,8 @@ We use a similar set of scopes as - `markup` - `heading` + - `marker` + - `1`, `2`, `3`, `4`, `5`, `6` - heading text for h1 through h6 - `list` - `unnumbered` - `numbered` diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index 003266d3af37a..68fc3555e7d05 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -6,14 +6,14 @@ use tui::{ use std::sync::Arc; -use pulldown_cmark::{CodeBlockKind, CowStr, Event, Options, Parser, Tag}; +use pulldown_cmark::{CodeBlockKind, CowStr, Event, HeadingLevel, Options, Parser, Tag}; use helix_core::{ syntax::{self, HighlightEvent, Syntax}, Rope, }; use helix_view::{ - graphics::{Margin, Rect}, + graphics::{Margin, Rect, Style}, Theme, }; @@ -24,7 +24,7 @@ pub struct Markdown { text_style: String, block_style: String, - heading_style: String, + heading_styles: [String; 6], } // TODO: pre-render and self reference via Pin @@ -37,14 +37,23 @@ impl Markdown { config_loader, text_style: "markup.normal".into(), block_style: "markup.raw.inline".into(), - heading_style: "markup.heading".into(), + heading_styles: [ + "markup.heading.1".into(), + "markup.heading.2".into(), + "markup.heading.3".into(), + "markup.heading.4".into(), + "markup.heading.5".into(), + "markup.heading.6".into(), + ], } } pub fn style_group(mut self, suffix: &str) -> Self { self.text_style = format!("markup.normal.{}", suffix); self.block_style = format!("markup.raw.inline.{}", suffix); - self.heading_style = format!("markup.heading.{}", suffix); + for i in 0..self.heading_styles.len() { + self.heading_styles[i] = format!("markup.heading.{}.{}", i + 1, suffix); + } self } @@ -70,17 +79,19 @@ impl Markdown { }) } - macro_rules! get_theme { - ($s1: expr) => { - theme - .map(|theme| theme.try_get($s1.as_str())) - .flatten() - .unwrap_or_default() - }; - } - let text_style = get_theme!(self.text_style); - let code_style = get_theme!(self.block_style); - let heading_style = get_theme!(self.heading_style); + let get_theme = |key: &str| { + theme + .map(|theme| theme.try_get(key)) + .flatten() + .unwrap_or_default() + }; + let text_style = get_theme(&self.text_style); + let code_style = get_theme(&self.block_style); + let heading_styles: Vec