mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
add highlighting for other languages
This commit is contained in:
parent
0820780e73
commit
ac07ddcbaf
4 changed files with 95 additions and 15 deletions
|
@ -626,19 +626,42 @@ samp .comment,
|
||||||
code .comment {
|
code .comment {
|
||||||
color: var(--green);
|
color: var(--green);
|
||||||
}
|
}
|
||||||
/* Number, String, Tag, Type literals */
|
|
||||||
|
/* Number, String, Tag literals */
|
||||||
|
samp .storage.type,
|
||||||
|
code .storage.type,
|
||||||
|
samp .string,
|
||||||
|
code .string,
|
||||||
|
samp .string.begin,
|
||||||
|
code .string.begin,
|
||||||
|
samp .string.end,
|
||||||
|
code .string.end,
|
||||||
|
samp .constant,
|
||||||
|
code .constant,
|
||||||
samp .literal,
|
samp .literal,
|
||||||
code .literal {
|
code .literal {
|
||||||
color: var(--cyan);
|
color: var(--cyan);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keywords and punctuation */
|
/* Keywords and punctuation */
|
||||||
|
samp .keyword,
|
||||||
|
code .keyword,
|
||||||
|
samp .punctuation.section,
|
||||||
|
code .punctuation.section,
|
||||||
|
samp .punctuation.separator,
|
||||||
|
code .punctuation.separator,
|
||||||
|
samp .punctuation.terminator,
|
||||||
|
code .punctuation.terminator,
|
||||||
samp .kw,
|
samp .kw,
|
||||||
code .kw {
|
code .kw {
|
||||||
color: var(--magenta);
|
color: var(--magenta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Operators */
|
/* Operators */
|
||||||
samp .op,
|
samp .op,
|
||||||
code .op {
|
code .op,
|
||||||
|
samp .keyword.operator,
|
||||||
|
code .keyword.operator {
|
||||||
color: var(--orange);
|
color: var(--orange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,12 +672,22 @@ code .delimeter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Variables modules and field names */
|
/* Variables modules and field names */
|
||||||
|
samp .function,
|
||||||
|
code .function,
|
||||||
|
samp .meta.group,
|
||||||
|
code .meta.group,
|
||||||
|
samp .meta.block,
|
||||||
|
code .meta.block,
|
||||||
samp .lowerident,
|
samp .lowerident,
|
||||||
code .lowerident {
|
code .lowerident {
|
||||||
color: var(--blue);
|
color: var(--blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Types, Tags, and Modules */
|
/* Types, Tags, and Modules */
|
||||||
|
samp .type,
|
||||||
|
code .type,
|
||||||
|
samp .meta.path,
|
||||||
|
code .meta.path,
|
||||||
samp .upperident,
|
samp .upperident,
|
||||||
code .upperident {
|
code .upperident {
|
||||||
color: var(--green);
|
color: var(--green);
|
||||||
|
|
|
@ -18,6 +18,7 @@ path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
syntect = "5.0"
|
||||||
roc_highlight = { path = "../../../crates/highlight" }
|
roc_highlight = { path = "../../../crates/highlight" }
|
||||||
roc_std = { path = "../../../crates/roc_std" }
|
roc_std = { path = "../../../crates/roc_std" }
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,12 @@ use std::fs;
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use syntect::easy::HighlightLines;
|
||||||
|
use syntect::parsing::SyntaxSet;
|
||||||
|
use syntect::highlighting::{ThemeSet, Style};
|
||||||
|
use syntect::util::{LinesWithEndings};
|
||||||
|
use syntect::html::{ClassedHTMLGenerator, ClassStyle};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "roc__transformFileContentForHost_1_exposed"]
|
#[link_name = "roc__transformFileContentForHost_1_exposed"]
|
||||||
fn roc_transformFileContentForHost(relPath: &RocStr, content: &RocStr) -> RocStr;
|
fn roc_transformFileContentForHost(relPath: &RocStr, content: &RocStr) -> RocStr;
|
||||||
|
@ -210,6 +216,8 @@ fn process_file(input_dir: &Path, output_dir: &Path, input_file: &Path) -> Resul
|
||||||
// And track a little bit of state
|
// And track a little bit of state
|
||||||
let mut in_code_block = false;
|
let mut in_code_block = false;
|
||||||
let mut is_roc_code = false;
|
let mut is_roc_code = false;
|
||||||
|
let ps : syntect::parsing::SyntaxSet = SyntaxSet::load_defaults_newlines();
|
||||||
|
let ts : syntect::highlighting::ThemeSet = ThemeSet::load_defaults();
|
||||||
|
|
||||||
for event in parser {
|
for event in parser {
|
||||||
match event {
|
match event {
|
||||||
|
@ -235,7 +243,7 @@ fn process_file(input_dir: &Path, output_dir: &Path, input_file: &Path) -> Resul
|
||||||
in_code_block = true;
|
in_code_block = true;
|
||||||
is_roc_code = is_roc_code_block(&cbk);
|
is_roc_code = is_roc_code_block(&cbk);
|
||||||
}
|
}
|
||||||
pulldown_cmark::Event::End(pulldown_cmark::Tag::CodeBlock(_)) => {
|
pulldown_cmark::Event::End(pulldown_cmark::Tag::CodeBlock(pulldown_cmark::CodeBlockKind::Fenced(cow_str))) => {
|
||||||
if in_code_block {
|
if in_code_block {
|
||||||
match replace_code_with_static_file(&code_to_highlight, input_file) {
|
match replace_code_with_static_file(&code_to_highlight, input_file) {
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -254,6 +262,14 @@ fn process_file(input_dir: &Path, output_dir: &Path, input_file: &Path) -> Resul
|
||||||
let highlighted_html: String;
|
let highlighted_html: String;
|
||||||
if is_roc_code {
|
if is_roc_code {
|
||||||
highlighted_html = roc_highlight::highlight_roc_code(&code_to_highlight)
|
highlighted_html = roc_highlight::highlight_roc_code(&code_to_highlight)
|
||||||
|
} else if let Some(syntax) = ps.find_syntax_by_token(&cow_str) {
|
||||||
|
let mut h = HighlightLines::new(syntax, &ts.themes["base16-ocean.dark"]);
|
||||||
|
|
||||||
|
let mut html_generator = ClassedHTMLGenerator::new_with_class_style(syntax, &ps, ClassStyle::Spaced);
|
||||||
|
for line in LinesWithEndings::from(&code_to_highlight) {
|
||||||
|
html_generator.parse_html_for_line_which_includes_newline(line);
|
||||||
|
}
|
||||||
|
highlighted_html = format!("<pre><samp>{}</pre></samp>", html_generator.finalize())
|
||||||
} else {
|
} else {
|
||||||
highlighted_html = format!("<pre><samp>{}</pre></samp>", &code_to_highlight)
|
highlighted_html = format!("<pre><samp>{}</pre></samp>", &code_to_highlight)
|
||||||
}
|
}
|
||||||
|
|
|
@ -635,16 +635,34 @@ h4 {
|
||||||
/* Comments `#` and Documentation comments `##` */
|
/* Comments `#` and Documentation comments `##` */
|
||||||
samp .comment,
|
samp .comment,
|
||||||
code .comment {
|
code .comment {
|
||||||
color: var(--green);
|
color: var(--green);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Number, String, Tag, Type literals */
|
/* Number, String, Tag literals */
|
||||||
|
samp .storage.type,
|
||||||
|
code .storage.type,
|
||||||
|
samp .string,
|
||||||
|
code .string,
|
||||||
|
samp .string.begin,
|
||||||
|
code .string.begin,
|
||||||
|
samp .string.end,
|
||||||
|
code .string.end,
|
||||||
|
samp .constant,
|
||||||
|
code .constant,
|
||||||
samp .literal,
|
samp .literal,
|
||||||
code .literal {
|
code .literal {
|
||||||
color: var(--cyan);
|
color: var(--cyan);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keywords and punctuation */
|
/* Keywords and punctuation */
|
||||||
|
samp .keyword,
|
||||||
|
code .keyword,
|
||||||
|
samp .punctuation.section,
|
||||||
|
code .punctuation.section,
|
||||||
|
samp .punctuation.separator,
|
||||||
|
code .punctuation.separator,
|
||||||
|
samp .punctuation.terminator,
|
||||||
|
code .punctuation.terminator,
|
||||||
samp .kw,
|
samp .kw,
|
||||||
code .kw {
|
code .kw {
|
||||||
color: var(--magenta);
|
color: var(--magenta);
|
||||||
|
@ -652,31 +670,43 @@ code .kw {
|
||||||
|
|
||||||
/* Operators */
|
/* Operators */
|
||||||
samp .op,
|
samp .op,
|
||||||
code .op {
|
code .op,
|
||||||
color: var(--orange);
|
samp .keyword.operator,
|
||||||
|
code .keyword.operator {
|
||||||
|
color: var(--orange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delimieters */
|
/* Delimieters */
|
||||||
samp .delimeter,
|
samp .delimeter,
|
||||||
code .delimeter {
|
code .delimeter {
|
||||||
color: var(--gray);
|
color: var(--gray);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Variables modules and field names */
|
/* Variables modules and field names */
|
||||||
|
samp .function,
|
||||||
|
code .function,
|
||||||
|
samp .meta.group,
|
||||||
|
code .meta.group,
|
||||||
|
samp .meta.block,
|
||||||
|
code .meta.block,
|
||||||
samp .lowerident,
|
samp .lowerident,
|
||||||
code .lowerident {
|
code .lowerident {
|
||||||
color: var(--blue);
|
color: var(--blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Types, Tags, and Modules */
|
/* Types, Tags, and Modules */
|
||||||
|
samp .type,
|
||||||
|
code .type,
|
||||||
|
samp .meta.path,
|
||||||
|
code .meta.path,
|
||||||
samp .upperident,
|
samp .upperident,
|
||||||
code .upperident {
|
code .upperident {
|
||||||
color: var(--green);
|
color: var(--green);
|
||||||
}
|
}
|
||||||
|
|
||||||
samp .dim,
|
samp .dim,
|
||||||
code .dim {
|
code .dim {
|
||||||
opacity: 0.55;
|
opacity: 0.55;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button-container {
|
.button-container {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue