Skip to content

Commit

Permalink
Merge branch 'generate-line-numbers-in-md-output'
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Jan 9, 2017
2 parents 5f73dae + 7baf789 commit de6c80e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions extensions/markdown/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ class MDDocumentContentProvider implements vscode.TextDocumentContentProvider {
return `<pre class="hljs"><code><div>${md.utils.escapeHtml(str)}</div></code></pre>`;
}
}).use(mdnh, {});

function addLineNumberRenderer(tokens: any, idx: number, options: any, env: any, self: any) {
const token = tokens[idx];
if (token.level === 0 && token.map && token.map.length) {
token.attrSet('data-line', token.map[0]);
}
return self.renderToken(tokens, idx, options, env, self);
}

md.renderer.rules.paragraph_open = addLineNumberRenderer;
md.renderer.rules.heading_open = addLineNumberRenderer;

return md;
}

Expand Down

0 comments on commit de6c80e

Please sign in to comment.