From 0620ef1f472e8242bfa411dba207d15b46a1e29f Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Tue, 29 Dec 2015 12:26:32 +0100 Subject: [PATCH] Hides rust code lines prepended with # --- src/theme/book.css | 3 +++ src/theme/book.js | 11 +++++++++-- src/theme/stylus/general.styl | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/theme/book.css b/src/theme/book.css index c73eb4a0..df72378b 100644 --- a/src/theme/book.css +++ b/src/theme/book.css @@ -9,6 +9,9 @@ body { .right { float: right; } +.hidden { + display: none; +} h2, h3 { margin-top: 2.5em; diff --git a/src/theme/book.js b/src/theme/book.js index 862cb324..b4809118 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -119,13 +119,20 @@ $( document ).ready(function() { $("code.language-rust").each(function(i, block){ var lines = $(this).html().split("\n"); + var first_non_hidden_line = false; for(var n = 0; n < lines.length; n++){ if($.trim(lines[n])[0] == hiding_character){ - lines[n] = "" + lines[n] + "" + lines[n] = "" + lines[n] + ""; + } + else if(first_non_hidden_line) { + lines[n] = "\n" + lines[n]; + } + else { + first_non_hidden_line = true; } } - $(this).html(lines.join()); + $(this).html(lines.join("")); }); diff --git a/src/theme/stylus/general.styl b/src/theme/stylus/general.styl index 13f616f6..e798e8e0 100644 --- a/src/theme/stylus/general.styl +++ b/src/theme/stylus/general.styl @@ -11,4 +11,8 @@ html, body { float: right } +.hidden { + display: none; +} + h2, h3 { margin-top: 2.5em }