Skip to content

Commit 3403f25

Browse files
authored
Fix ToC and touch up syntax highlighting (#1106)
1 parent 55beb6b commit 3403f25

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

pgml-dashboard/src/utils/markdown.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use crate::{templates::docs::TocLink, utils::config};
33
use std::cell::RefCell;
44
use std::collections::{HashMap, HashSet};
55
use std::path::{Path, PathBuf};
6-
use std::sync::Arc;
6+
use std::sync::{
7+
atomic::{AtomicUsize, Ordering},
8+
Arc,
9+
};
710

811
use aho_corasick::{AhoCorasick, AhoCorasickBuilder, MatchKind};
912
use anyhow::Result;
@@ -13,7 +16,6 @@ use comrak::{
1316
nodes::{Ast, AstNode, NodeValue},
1417
parse_document, Arena, ComrakExtensionOptions, ComrakOptions, ComrakRenderOptions,
1518
};
16-
use convert_case::Casing;
1719
use itertools::Itertools;
1820
use lazy_static::lazy_static;
1921
use tantivy::collector::TopDocs;
@@ -26,17 +28,23 @@ use url::Url;
2628
use crate::templates::docs::NavLink;
2729
use std::fmt;
2830

29-
pub struct MarkdownHeadings {}
31+
pub struct MarkdownHeadings {
32+
counter: Arc<AtomicUsize>,
33+
}
3034

3135
impl MarkdownHeadings {
3236
pub fn new() -> Self {
33-
Self {}
37+
Self {
38+
counter: Arc::new(AtomicUsize::new(0)),
39+
}
3440
}
3541
}
3642

3743
impl HeadingAdapter for MarkdownHeadings {
3844
fn enter(&self, meta: &HeadingMeta) -> String {
39-
let id = meta.content.to_case(convert_case::Case::Kebab);
45+
// let id = meta.content.to_case(convert_case::Case::Kebab);
46+
let id = self.counter.fetch_add(1, Ordering::SeqCst);
47+
let id = format!("header-{}", id);
4048

4149
match meta.level {
4250
1 => format!(r#"<h1 class="h1 mb-5" id="{id}">"#),
@@ -217,7 +225,9 @@ impl SyntaxHighlighterAdapter for SyntaxHighlighter {
217225
let code = match options.lang {
218226
"postgresql" | "sql" | "postgresql-line-nums" => {
219227
lazy_static! {
220-
static ref SQL_KEYS: [&'static str; 66] = [
228+
static ref SQL_KEYS: [&'static str; 68] = [
229+
"PARTITION OF",
230+
"PARTITION BY",
221231
"CASCADE",
222232
"INNER ",
223233
"ON ",
@@ -285,7 +295,9 @@ impl SyntaxHighlighterAdapter for SyntaxHighlighter {
285295
"pgml.predict",
286296
"pgml.transform",
287297
];
288-
static ref SQL_KEYS_REPLACEMENTS: [&'static str; 66] = [
298+
static ref SQL_KEYS_REPLACEMENTS: [&'static str; 68] = [
299+
r#"<span class="syntax-highlight">PARTITION OF</span>"#,
300+
r#"<span class="syntax-highlight">PARTITION BY</span>"#,
289301
"<span class=\"syntax-highlight\">CASCADE</span>",
290302
"<span class=\"syntax-highlight\">INNER </span>",
291303
"<span class=\"syntax-highlight\">ON </span>",

0 commit comments

Comments
 (0)