yzane / vscode-markdown-pdf

Markdown converter for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=yzane.markdown-pdf
Other
1.01k stars 206 forks source link

How To Inject Line Number On This Extension #146

Open ghost opened 5 years ago

ghost commented 5 years ago

How To Inject Line Number On Code Block VsCode Yzane Markdown PDF

extension: https://github.com/yzane/vscode-markdown-pdf reference: https://codepen.io/heiswayi/pen/jyKYyg

Step By Step

<script>
(function() {
  var pre = document.getElementsByTagName('pre'), pl = pre.length;
  for (var i = 0; i < pl; i++) {
    pre[i].innerHTML = '<span class="line-number"></span>' + pre[i].innerHTML + '<span class="cl"></span>';
    var num = pre[i].innerHTML.split(/\n/).length;
    for (var j = 0; j < (num - 1); j++) {
      var line_num = pre[i].getElementsByTagName('span')[0];
      line_num.innerHTML += '<span>' + (j + 1) + '</span>';
    }
  }
})();
</script>
pre {
    display: block;
}
pre code {
    display: block;
}
pre .line-number {
    display: block;
    float: left;
    margin: 0 1em 0 -1em;
    border-right: 1px solid #aaa;
    text-align: right;
    padding:5px 0;
}
pre .line-number span {
    display: block;
    padding: 0 .5em 0 1em;
    color: #aaaaaa;
    line-height: 19px;
    font-size: 14px;
}
pre .cl {
    display: block;
    clear: both;
}

Restart your vscode, and it's just work