diff --git a/lib/generate/page/index.js b/lib/generate/page/index.js index f2c7b6054..7f730eae5 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 978ccb7a7..25e941012 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 31b6f5263..1c59ce663 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 dd36f3c99..a65acafb8 100644 --- a/theme/templates/page.html +++ b/theme/templates/page.html @@ -7,7 +7,7 @@ {% endblock %} - +{% set exercise = 0 %} {% block content %} {# 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" %} +
+
Exercise #{{ exercise }}
+ {% autoescape false %}{{ section.content }}{% endautoescape %} +
+                                    
+                                    {% autoescape false %}{{ section.code.base|code }}{% endautoescape %}
+                                    
+                                
+ {% set exercise = exercise + 1 %} +
{% endif %} {% endfor %}