From 87232ac4b63d8cf14b632815fb37eafce7de60a9 Mon Sep 17 00:00:00 2001 From: Jean-David Moisan Date: Mon, 18 May 2020 13:58:02 -0400 Subject: [PATCH] feat: highlight plugin add support for line start (#627) * feat: highlight plugin add support for line start * format code Co-authored-by: Kevin Titor <0x142857@gmail.com> --- packages/saber-highlight-css/default.css | 1 - .../highlight-plugin.test.js.snap | 6 +++-- .../__test__/highlight-plugin.test.js | 15 +++++++++++ .../saber/src/markdown/highlight-plugin.js | 15 ++++++++--- website/pages/docs/markdown-features.md | 26 +++++++++++++++++++ 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/packages/saber-highlight-css/default.css b/packages/saber-highlight-css/default.css index bb98186ad..57e99185d 100644 --- a/packages/saber-highlight-css/default.css +++ b/packages/saber-highlight-css/default.css @@ -71,7 +71,6 @@ text-align: right; padding-right: 0.8rem; margin-right: .8rem; - counter-reset: linenumber; } .saber-highlight-line-numbers > span { diff --git a/packages/saber/src/markdown/__test__/__snapshots__/highlight-plugin.test.js.snap b/packages/saber/src/markdown/__test__/__snapshots__/highlight-plugin.test.js.snap index 7510b15cb..43f8f6380 100644 --- a/packages/saber/src/markdown/__test__/__snapshots__/highlight-plugin.test.js.snap +++ b/packages/saber/src/markdown/__test__/__snapshots__/highlight-plugin.test.js.snap @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`code block markdown.lineNumbers = true 1`] = `"
const cry = Array(3).fill('ora').join(' ')
"`; +exports[`code block markdown.lineNumbers = true 1`] = `"
const cry = Array(3).fill('ora').join(' ')
"`; -exports[`code block with {lineNumbers:true} 1`] = `"
const cry = Array(3).fill('ora').join(' ')
"`; +exports[`code block with {lineNumbers:true} 1`] = `"
const cry = Array(3).fill('ora').join(' ')
"`; + +exports[`code block with {lineNumbers:true,lineStart:5} 1`] = `"
const cry = Array(3).fill('ora').join(' ')
"`; exports[`main 1`] = `"
<div>hehe</div>
"`; diff --git a/packages/saber/src/markdown/__test__/highlight-plugin.test.js b/packages/saber/src/markdown/__test__/highlight-plugin.test.js index b731af847..e521242f4 100644 --- a/packages/saber/src/markdown/__test__/highlight-plugin.test.js +++ b/packages/saber/src/markdown/__test__/highlight-plugin.test.js @@ -32,6 +32,21 @@ const cry = Array(3).fill('ora').join(' ') expect(html).toMatchSnapshot() }) +test('code block with {lineNumbers:true,lineStart:5}', () => { + const md = new Markdown() + const { env } = createEnv() + md.use(fenceOptionsPlugin) + const html = md.render( + ` +\`\`\`js {lineNumbers:true,lineStart:5} +const cry = Array(3).fill('ora').join(' ') +\`\`\` + `, + env + ) + expect(html).toMatchSnapshot() +}) + test('code block markdown.lineNumbers = true', () => { const md = new Markdown() const { env } = createEnv() diff --git a/packages/saber/src/markdown/highlight-plugin.js b/packages/saber/src/markdown/highlight-plugin.js index c43785eb8..f61d40e99 100644 --- a/packages/saber/src/markdown/highlight-plugin.js +++ b/packages/saber/src/markdown/highlight-plugin.js @@ -10,8 +10,8 @@ const parseOptions = str => { return fn() } -const generateLineNumbers = code => - '