A little app to serve my photography from my personal website

language name on code blocks

ericwood.org 0bffef79 ca11abec

Waiting for spindle ...
+41 -6
+18 -4
src/blog.rs
··· 53 53 fn write_pre_tag<'s>( 54 54 &self, 55 55 output: &mut dyn std::fmt::Write, 56 - _attributes: HashMap<&'static str, std::borrow::Cow<'s, str>>, 56 + attributes: HashMap<&'static str, std::borrow::Cow<'s, str>>, 57 57 ) -> std::fmt::Result { 58 - output.write_str("<pre class=\"highlighted\">") 58 + if attributes.contains_key("lang") { 59 + write!( 60 + output, 61 + "<pre class=\"highlighted\" data-language=\"{}\">", 62 + attributes["lang"] 63 + ) 64 + } else { 65 + output.write_str("<pre class=\"highlighted\">") 66 + } 59 67 } 60 68 61 69 fn write_code_tag<'s>( 62 70 &self, 63 71 output: &mut dyn std::fmt::Write, 64 - _attributes: HashMap<&'static str, std::borrow::Cow<'s, str>>, 72 + attributes: HashMap<&'static str, std::borrow::Cow<'s, str>>, 65 73 ) -> std::fmt::Result { 66 - output.write_str("<code>") 74 + // why doesn't it give us the actual language string????? hmmm???? 75 + if attributes.contains_key("class") { 76 + let lang = attributes["class"].replace("language-", ""); 77 + write!(output, "<code data-language=\"{}\">", lang) 78 + } else { 79 + output.write_str("<code>") 80 + } 67 81 } 68 82 } 69 83
+20 -1
src/views/blog/show/style.css
··· 3 3 margin: 0 auto; 4 4 } 5 5 6 - pre.highlighted { 6 + .blog__body pre { 7 7 padding: 20px; 8 8 border-radius: 6px; 9 9 } 10 + 11 + .blog__body pre > code { 12 + position: relative; 13 + display: block; 14 + } 15 + 16 + .blog__body pre > code:after { 17 + content: attr(data-language); 18 + position: absolute; 19 + right: 0; 20 + top: 0; 21 + color: white; 22 + opacity: 0.5; 23 + transition: opacity 0.3s; 24 + } 25 + 26 + .blog__body pre:hover > code:after { 27 + opacity: 0; 28 + }
+3 -1
src/views/blog/show/template.jinja
··· 11 11 <p> 12 12 <time datetime="{{ post.published_at }}">{{ post.published_at }}</time> 13 13 </p> 14 - {{ body }} 14 + <div class="blog__body"> 15 + {{ body }} 16 + </div> 15 17 </div> 16 18 {% endblock %}