Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions pgml-dashboard/src/utils/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -26,17 +28,23 @@ use url::Url;
use crate::templates::docs::NavLink;
use std::fmt;

pub struct MarkdownHeadings {}
pub struct MarkdownHeadings {
counter: Arc<AtomicUsize>,
}

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#"<h1 class="h1 mb-5" id="{id}">"#),
Expand Down Expand Up @@ -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 ",
Expand Down Expand Up @@ -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#"<span class="syntax-highlight">PARTITION OF</span>"#,
r#"<span class="syntax-highlight">PARTITION BY</span>"#,
"<span class=\"syntax-highlight\">CASCADE</span>",
"<span class=\"syntax-highlight\">INNER </span>",
"<span class=\"syntax-highlight\">ON </span>",
Expand Down