Skip to content

Commit a1c4616

Browse files
Dan Codemirror docs (#1271)
1 parent d51f136 commit a1c4616

File tree

13 files changed

+698
-269
lines changed

13 files changed

+698
-269
lines changed

pgml-dashboard/package-lock.json

Lines changed: 234 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pgml-dashboard/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"dependencies": {
3+
"@codemirror/lang-javascript": "^6.2.1",
4+
"@codemirror/lang-python": "^6.1.3",
5+
"@codemirror/lang-rust": "^6.0.1",
6+
"@codemirror/lang-sql": "^6.5.4",
7+
"@codemirror/lang-json": "^6.0.1",
8+
"@codemirror/state": "^6.2.1",
9+
"@codemirror/view": "^6.21.0",
10+
"codemirror": "^6.0.1",
311
"autosize": "^6.0.1",
412
"dompurify": "^3.0.6",
513
"marked": "^9.1.0"

pgml-dashboard/src/api/cms.rs

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -406,32 +406,6 @@ mod test {
406406
use rocket::local::asynchronous::Client;
407407
use rocket::{Build, Rocket};
408408

409-
#[test]
410-
fn test_syntax_highlighting() {
411-
let code = r#"
412-
# Hello
413-
414-
```postgresql
415-
SELECT * FROM test;
416-
```
417-
"#;
418-
419-
let arena = Arena::new();
420-
let root = parse_document(&arena, code, &options());
421-
422-
// Style headings like we like them
423-
let mut plugins = ComrakPlugins::default();
424-
let binding = MarkdownHeadings::new();
425-
plugins.render.heading_adapter = Some(&binding);
426-
plugins.render.codefence_syntax_highlighter = Some(&SyntaxHighlighter {});
427-
428-
let mut html = vec![];
429-
format_html_with_plugins(root, &options(), &mut html, &plugins).unwrap();
430-
let html = String::from_utf8(html).unwrap();
431-
432-
assert!(html.contains("<span class=\"syntax-highlight\">SELECT</span>"));
433-
}
434-
435409
#[test]
436410
fn test_wrapping_tables() {
437411
let markdown = r#"
@@ -574,4 +548,77 @@ This is the end of the markdown
574548
rsp.status()
575549
);
576550
}
551+
552+
// Test backend for line highlights and line numbers added
553+
#[test]
554+
fn gitbook_codeblock_test() {
555+
let contents = r#"
556+
{% code title="Test name for html" lineNumbers="true" %}
557+
```javascript-highlightGreen="1"
558+
import something
559+
let a = 1
560+
```
561+
{% endcode %}
562+
"#;
563+
564+
let expected = r#"
565+
<div class="code-block with-title line-numbers">
566+
<div class="title">
567+
Test name for html
568+
</div>
569+
<pre data-controller="copy">
570+
<div class="code-toolbar">
571+
<span data-action="click->copy#codeCopy" class="material-symbols-outlined btn-code-toolbar">content_copy</span>
572+
<span class="material-symbols-outlined btn-code-toolbar" disabled>link</span>
573+
<span class="material-symbols-outlined btn-code-toolbar" disabled>edit</span>
574+
</div>
575+
<code language='javascript' data-controller="code-block">
576+
<div class="highlight code-line-highlight-green">importsomething</div>
577+
<div class="highlight code-line-highlight-none">leta=1</div>
578+
<div class="highlight code-line-highlight-none"></div>
579+
</code>
580+
</pre>
581+
</div>"#;
582+
583+
// Parse Markdown
584+
let arena = Arena::new();
585+
let spaced_contents = crate::utils::markdown::gitbook_preprocess(contents);
586+
let root = parse_document(&arena, &spaced_contents, &crate::utils::markdown::options());
587+
588+
crate::utils::markdown::wrap_tables(root, &arena).unwrap();
589+
590+
// MkDocs, gitbook syntax support, e.g. tabs, notes, alerts, etc.
591+
crate::utils::markdown::mkdocs(root, &arena).unwrap();
592+
593+
// Style headings like we like them
594+
let mut plugins = ComrakPlugins::default();
595+
let headings = crate::utils::markdown::MarkdownHeadings::new();
596+
plugins.render.heading_adapter = Some(&headings);
597+
plugins.render.codefence_syntax_highlighter =
598+
Some(&crate::utils::markdown::SyntaxHighlighter {});
599+
600+
let mut html = vec![];
601+
format_html_with_plugins(
602+
root,
603+
&crate::utils::markdown::options(),
604+
&mut html,
605+
&plugins,
606+
)
607+
.unwrap();
608+
let html = String::from_utf8(html).unwrap();
609+
610+
println!("expected: {}", expected);
611+
612+
println!("response: {}", html);
613+
614+
assert!(
615+
html.chars()
616+
.filter(|c| !c.is_whitespace())
617+
.collect::<String>()
618+
== expected
619+
.chars()
620+
.filter(|c| !c.is_whitespace())
621+
.collect::<String>()
622+
)
623+
}
577624
}

0 commit comments

Comments
 (0)