diff --git a/README.md b/README.md
index 4f641bdc..08598a98 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,8 @@ You can set options for customizing your documentations.
"title": "",
"description": "",
"keyword": ""
- }
+ },
+ "linenums": true
}
```
diff --git a/conf.json b/conf.json
index 08a9d9bf..455985dd 100644
--- a/conf.json
+++ b/conf.json
@@ -23,11 +23,12 @@
"title": "",
"description": "",
"keyword": ""
- }
+ },
+ "linenums": false
},
"markdown": {
"parser": "gfm",
"hardwrap": true,
"tags": ["examples"]
}
-}
\ No newline at end of file
+}
diff --git a/static/scripts/linenumber.js b/static/scripts/linenumber.js
index a0c570d5..0d9227a4 100644
--- a/static/scripts/linenumber.js
+++ b/static/scripts/linenumber.js
@@ -4,14 +4,26 @@
var source = document.getElementsByClassName('prettyprint source');
if (source && source[0]) {
- source = source[0].getElementsByTagName('code')[0];
+ var linenums = config.linenums;
- numbered = source.innerHTML.split('\n');
- numbered = numbered.map(function(item) {
- counter++;
- return '' + item;
- });
+ if (linenums) {
+ source = source[0].getElementsByTagName('ol')[0];
- source.innerHTML = numbered.join('\n');
+ numbered = Array.prototype.slice.apply(source.children);
+ numbered = numbered.map(function(item) {
+ counter++;
+ item.id = 'line' + counter;
+ });
+ } else {
+ source = source[0].getElementsByTagName('code')[0];
+
+ numbered = source.innerHTML.split('\n');
+ numbered = numbered.map(function(item) {
+ counter++;
+ return '' + item;
+ });
+
+ source.innerHTML = numbered.join('\n');
+ }
}
})();
diff --git a/tmpl/source.tmpl b/tmpl/source.tmpl
index e1092ef2..6e2a29fd 100644
--- a/tmpl/source.tmpl
+++ b/tmpl/source.tmpl
@@ -3,6 +3,6 @@
?>
\ No newline at end of file
+