Browse Source

LibMarkdown: Replace inline styles in HTML with CSS in <head>

Linus Groh 4 years ago
parent
commit
10c19d5207
2 changed files with 8 additions and 4 deletions
  1. 3 3
      Libraries/LibMarkdown/CodeBlock.cpp
  2. 5 1
      Libraries/LibMarkdown/Document.cpp

+ 3 - 3
Libraries/LibMarkdown/CodeBlock.cpp

@@ -55,10 +55,10 @@ String CodeBlock::render_to_html() const
     if (style.emph)
         builder.append("<i>");
 
-    if (style_language.is_null())
-        builder.append("<code style=\"white-space: pre;\">");
+    if (style_language.is_empty())
+        builder.append("<code>");
     else
-        builder.appendf("<code style=\"white-space: pre;\" class=\"%s\">", style_language.characters());
+        builder.appendff("<code class=\"{}\">", style_language);
 
     builder.append(escape_html_entities(m_code));
 

+ 5 - 1
Libraries/LibMarkdown/Document.cpp

@@ -40,7 +40,11 @@ String Document::render_to_html() const
 
     builder.append("<!DOCTYPE html>\n");
     builder.append("<html>\n");
-    builder.append("<head></head>\n");
+    builder.append("<head>\n");
+    builder.append("<style>\n");
+    builder.append("code { white-space: pre; }\n");
+    builder.append("</style>\n");
+    builder.append("</head>\n");
     builder.append("<body>\n");
 
     for (auto& block : m_blocks) {