Browse Source

Add source line number attribute in order to allow sync scrolls

pull/882/head
mdjfs 4 years ago
parent
commit
c5a4a53bd6
  1. 13
      lib/renderer.js

13
lib/renderer.js

@ -219,6 +219,19 @@ Renderer.prototype.renderToken = function renderToken(tokens, idx, options) {
// Add token name, e.g. `<img`
result += (token.nesting === -1 ? '</' : '<') + token.tag;
// Add source line number attribute in order to allow sync scrolls
// Idea extracted from (https://markdown-it.github.io/index.js)
if (options.lineNumber) {
if (token.map && token.level === 0) {
var attr = [ 'data-line', token.map[0] ];
if (token.attrs) {
token.attrs.push(attr);
} else {
token.attrs = [ attr ];
}
}
}
// Encode attributes, e.g. `<img src="foo"`
result += this.renderAttrs(token);

Loading…
Cancel
Save