diff --git a/components/rendering/src/markdown.rs b/components/rendering/src/markdown.rs index ff419fbd..b60dc0ed 100644 --- a/components/rendering/src/markdown.rs +++ b/components/rendering/src/markdown.rs @@ -203,7 +203,19 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result { + let mut language = None; + match kind { + CodeBlockKind::Fenced(fence_info) => { + let fence_info = fence::FenceSettings::new(fence_info); + language = fence_info.language; + }, + _ => {} + }; if !context.config.highlight_code { + if let Some(lang) = language { + let html = format!(r#"
"#, lang);
+                                return Event::Html(html.into());
+                            }
                             return Event::Html("
".into());
                         }
 
@@ -227,7 +239,13 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result");
+                        if let Some(lang) = language {
+                            html.push_str(r#""#);
+                        } else {
+                            html.push_str("");
+                        }
                         Event::Html(html.into())
                     }
                     Event::End(Tag::CodeBlock(_)) => {
diff --git a/components/rendering/tests/markdown.rs b/components/rendering/tests/markdown.rs
index e37f9212..d1dcfdfd 100644
--- a/components/rendering/tests/markdown.rs
+++ b/components/rendering/tests/markdown.rs
@@ -53,7 +53,7 @@ fn can_highlight_code_block_with_lang() {
     let res = render_content("```python\nlist.append(1)\n```", &context).unwrap();
     assert_eq!(
         res.body,
-        "
\nlist.append(1)\n
" + "
\nlist.append(1)\n
" ); } @@ -68,7 +68,7 @@ fn can_higlight_code_block_with_unknown_lang() { // defaults to plain text assert_eq!( res.body, - "
\nlist.append(1)\n
" + "
\nlist.append(1)\n
" ); }