Skip to content

Commit f0257b0

Browse files
committed
Merge pull request BoostIO#28 from eschmid72/master
displaying markdown codeblocks with line numbering
2 parents f6208c1 + 084677c commit f0257b0

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules/*
77
/dist
88
/compiled
99
/secret
10+
*.log

browser/lib/markdown.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import emoji from 'markdown-it-emoji'
33
import math from '@rokt33r/markdown-it-math'
44
import hljs from 'highlight.js'
55

6+
var createGutter = function (str) {
7+
var lc = (str.match(/\n/g) || []).length;
8+
var lines = [];
9+
for (var i = 1; i <= lc; i++) {
10+
lines.push('<span>' + i + '</span>');
11+
}
12+
return '<span>' + lines.join('') + '</span>';
13+
};
14+
615
var md = markdownit({
716
typographer: true,
817
linkify: true,
@@ -11,12 +20,16 @@ var md = markdownit({
1120
highlight: function (str, lang) {
1221
if (lang && hljs.getLanguage(lang)) {
1322
try {
14-
return '<pre class="hljs"><code>' +
23+
return '<pre class="hljs">' +
24+
createGutter(str) +
25+
'<code>' +
1526
hljs.highlight(lang, str).value +
1627
'</code></pre>'
1728
} catch (e) {}
1829
}
19-
return '<pre class="hljs"><code>' +
30+
return '<pre class="hljs">' +
31+
createGutter(str) +
32+
'<code>' +
2033
str.replace(/\&/g, '&amp;').replace(/\</g, '&lt;').replace(/\>/g, '&gt;').replace(/\"/g, '&quot;') +
2134
'</code></pre>'
2235
}

browser/styles/mixins/marked.styl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ marked()
135135
&>pre
136136
border none
137137
margin -5px
138+
&>span
139+
font-family Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace
140+
display block
141+
float left
142+
margin 0 0.5em 0 -0.5em
143+
border-right 1px solid
144+
text-align right
145+
&>span
146+
display block
147+
padding 0 .5em 0 1em
148+
&>.cl
149+
display block
150+
clear both
138151
table
139152
width 100%
140153
margin 15px 0 25px

0 commit comments

Comments
 (0)