Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/syntax_highlighting/html.rs')
-rw-r--r--crates/ide/src/syntax_highlighting/html.rs44
1 files changed, 28 insertions, 16 deletions
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs
index 9fd807f031..75e46b8ebf 100644
--- a/crates/ide/src/syntax_highlighting/html.rs
+++ b/crates/ide/src/syntax_highlighting/html.rs
@@ -1,6 +1,7 @@
//! Renders a bit of code as HTML.
use hir::{EditionedFileId, Semantics};
+use ide_db::MiniCore;
use oorandom::Rand32;
use stdx::format_to;
use syntax::AstNode;
@@ -10,7 +11,12 @@ use crate::{
syntax_highlighting::{HighlightConfig, highlight},
};
-pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String {
+pub(crate) fn highlight_as_html_with_config(
+ db: &RootDatabase,
+ config: &HighlightConfig<'_>,
+ file_id: FileId,
+ rainbow: bool,
+) -> String {
let sema = Semantics::new(db);
let file_id = sema
.attach_first_edition(file_id)
@@ -27,21 +33,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
)
}
- let hl_ranges = highlight(
- db,
- HighlightConfig {
- strings: true,
- punctuation: true,
- specialize_punctuation: true,
- specialize_operator: true,
- operator: true,
- inject_doc_comment: true,
- macro_bang: true,
- syntactic_name_ref_highlighting: false,
- },
- file_id.file_id(db),
- None,
- );
+ let hl_ranges = highlight(db, config, file_id.file_id(db), None);
let text = file.to_string();
let mut buf = String::new();
buf.push_str(STYLE);
@@ -66,6 +58,26 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
buf
}
+pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String {
+ highlight_as_html_with_config(
+ db,
+ &HighlightConfig {
+ strings: true,
+ comments: true,
+ punctuation: true,
+ specialize_punctuation: true,
+ specialize_operator: true,
+ operator: true,
+ inject_doc_comment: true,
+ macro_bang: true,
+ syntactic_name_ref_highlighting: false,
+ minicore: MiniCore::default(),
+ },
+ file_id,
+ rainbow,
+ )
+}
+
//FIXME: like, real html escaping
fn html_escape(text: &str) -> String {
text.replace('<', "&lt;").replace('>', "&gt;")