diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-04 20:12:22 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-04 20:12:22 -0700 |
commit | d5bd08dcd21c838ef9da5d8a54ee5f847b737a02 (patch) | |
tree | 931d3bdea49097a6e8332ad1a19898d9f3d02eed | |
parent | 6c414ec40033bb2557d8f8598507737fd99a0f70 (diff) | |
download | gitbook-d5bd08dcd21c838ef9da5d8a54ee5f847b737a02.zip gitbook-d5bd08dcd21c838ef9da5d8a54ee5f847b737a02.tar.gz gitbook-d5bd08dcd21c838ef9da5d8a54ee5f847b737a02.tar.bz2 |
Show exercise in page format
-rw-r--r-- | lib/generate/page/index.js | 10 | ||||
-rw-r--r-- | theme/assets/print.css | 2 | ||||
-rw-r--r-- | theme/stylesheets/print.less | 5 | ||||
-rw-r--r-- | theme/templates/page.html | 13 |
4 files changed, 28 insertions, 2 deletions
diff --git a/lib/generate/page/index.js b/lib/generate/page/index.js index f2c7b60..7f730ea 100644 --- a/lib/generate/page/index.js +++ b/lib/generate/page/index.js @@ -3,11 +3,21 @@ var util = require("util"); var path = require("path"); var Q = require("q"); var swig = require('swig'); +var hljs = require('highlight.js'); var fs = require("../fs"); var parse = require("../../parse"); var BaseGenerator = require("../generator"); +// Swig filter: highlight coloration +swig.setFilter('code', function(code, lang) { + try { + return hljs.highlight(lang, code).value; + } catch(e) { + return hljs.highlightAuto(code).value; + } +}); + /* * This generator will generate a simple index.html which can be converted as a PDF diff --git a/theme/assets/print.css b/theme/assets/print.css index 978ccb7..25e9410 100644 --- a/theme/assets/print.css +++ b/theme/assets/print.css @@ -1 +1 @@ -h1,h2{page-break-after:avoid;page-break-before:auto}pre,blockquote{border:1px solid #999;page-break-inside:avoid}img{max-width:100%!important;page-break-inside:avoid}section{page-break-after:always}section#cover{padding:3cm 0;text-align:center}section#cover h1{font-size:1.5cm}section#summary{text-align:center}section#summary ul{font-size:.5cm;line-height:1.8em;padding:0;margin:0;list-style:none}section#summary>ul>li{margin-bottom:1cm}section#summary>ul>li>a{font-size:.6cm}section article{margin:1.5cm}section article.new-chapter{page-break-after:always;font-size:.6cm;text-align:center;padding:3cm 0;border-top:1px solid #ccc}@media print{section article.new-chapter{border:0}}
\ No newline at end of file +h1,h2{page-break-after:avoid;page-break-before:auto}pre,blockquote{border:1px solid #999;page-break-inside:avoid}img{max-width:100%!important;page-break-inside:avoid}section{page-break-after:always}section#cover{padding:3cm 0;text-align:center}section#cover h1{font-size:1.5cm}section#summary{text-align:center}section#summary ul{font-size:.5cm;line-height:1.8em;padding:0;margin:0;list-style:none}section#summary>ul>li{margin-bottom:1cm}section#summary>ul>li>a{font-size:.6cm}section article{margin:1.5cm}section article.new-chapter{page-break-after:always;font-size:.6cm;text-align:center;padding:3cm 0;border-top:1px solid #ccc}@media print{section article.new-chapter{border:0}}section article .exercise{border:3px solid #ddd}
\ No newline at end of file diff --git a/theme/stylesheets/print.less b/theme/stylesheets/print.less index 31b6f52..1c59ce6 100644 --- a/theme/stylesheets/print.less +++ b/theme/stylesheets/print.less @@ -63,5 +63,10 @@ section { border: none; } } + + .exercise { + border: 3px solid #ddd; + + } } }
\ No newline at end of file diff --git a/theme/templates/page.html b/theme/templates/page.html index dd36f3c..a65acaf 100644 --- a/theme/templates/page.html +++ b/theme/templates/page.html @@ -7,7 +7,7 @@ <link rel="stylesheet" href="{{ staticBase }}/print.css"> {% endblock %} - +{% set exercise = 0 %} {% block content %} {# Cover #} <section id="cover"> @@ -53,6 +53,17 @@ {% for section in pages[article.path].content %} {% if section.type == "normal" %} {% autoescape false %}{{ section.content }}{% endautoescape %} + {% elif section.type == "exercise" %} + <div class="exercise"> + <div class="exercise-header">Exercise #{{ exercise }}</div> + {% autoescape false %}{{ section.content }}{% endautoescape %} + <pre> + <code> + {% autoescape false %}{{ section.code.base|code }}{% endautoescape %} + </code> + </pre> + {% set exercise = exercise + 1 %} + </div> {% endif %} {% endfor %} </article> |