From 4b140aad9976095af5561fe2b33543e75f7e06f7 Mon Sep 17 00:00:00 2001 From: Lev Date: Fri, 20 Oct 2023 19:22:52 -0700 Subject: [PATCH] Fix ToC and touch up syntax highlighting --- pgml-dashboard/src/utils/markdown.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pgml-dashboard/src/utils/markdown.rs b/pgml-dashboard/src/utils/markdown.rs index ad83651d3..0533b8b6c 100644 --- a/pgml-dashboard/src/utils/markdown.rs +++ b/pgml-dashboard/src/utils/markdown.rs @@ -3,7 +3,10 @@ use crate::{templates::docs::TocLink, utils::config}; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; -use std::sync::Arc; +use std::sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, +}; use aho_corasick::{AhoCorasick, AhoCorasickBuilder, MatchKind}; use anyhow::Result; @@ -13,7 +16,6 @@ use comrak::{ nodes::{Ast, AstNode, NodeValue}, parse_document, Arena, ComrakExtensionOptions, ComrakOptions, ComrakRenderOptions, }; -use convert_case::Casing; use itertools::Itertools; use lazy_static::lazy_static; use tantivy::collector::TopDocs; @@ -26,17 +28,23 @@ use url::Url; use crate::templates::docs::NavLink; use std::fmt; -pub struct MarkdownHeadings {} +pub struct MarkdownHeadings { + counter: Arc, +} impl MarkdownHeadings { pub fn new() -> Self { - Self {} + Self { + counter: Arc::new(AtomicUsize::new(0)), + } } } impl HeadingAdapter for MarkdownHeadings { fn enter(&self, meta: &HeadingMeta) -> String { - let id = meta.content.to_case(convert_case::Case::Kebab); + // let id = meta.content.to_case(convert_case::Case::Kebab); + let id = self.counter.fetch_add(1, Ordering::SeqCst); + let id = format!("header-{}", id); match meta.level { 1 => format!(r#"

"#), @@ -217,7 +225,9 @@ impl SyntaxHighlighterAdapter for SyntaxHighlighter { let code = match options.lang { "postgresql" | "sql" | "postgresql-line-nums" => { lazy_static! { - static ref SQL_KEYS: [&'static str; 66] = [ + static ref SQL_KEYS: [&'static str; 68] = [ + "PARTITION OF", + "PARTITION BY", "CASCADE", "INNER ", "ON ", @@ -285,7 +295,9 @@ impl SyntaxHighlighterAdapter for SyntaxHighlighter { "pgml.predict", "pgml.transform", ]; - static ref SQL_KEYS_REPLACEMENTS: [&'static str; 66] = [ + static ref SQL_KEYS_REPLACEMENTS: [&'static str; 68] = [ + r#"PARTITION OF"#, + r#"PARTITION BY"#, "CASCADE", "INNER ", "ON ", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy