Content-Length: 308226 | pFad | http://github.com/postgresml/postgresml/pull/1106/files

8D Fix ToC and touch up syntax highlighting by levkk · Pull Request #1106 · postgresml/postgresml · GitHub
Skip to content

Fix ToC and touch up syntax highlighting #1106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2023
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








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgresml/postgresml/pull/1106/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy