From c05ed93513f09a6da81e21ce12b59aaf610fdb9d Mon Sep 17 00:00:00 2001 From: Sean Goresht Date: Fri, 22 Jul 2022 16:54:47 -0600 Subject: [PATCH 1/3] feat: allow @start arg to override start line --- addon/components/code-block.hbs | 1 + tests/integration/components/code-block-test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/addon/components/code-block.hbs b/addon/components/code-block.hbs index 428ff0c8..759d83f7 100644 --- a/addon/components/code-block.hbs +++ b/addon/components/code-block.hbs @@ -1,5 +1,6 @@
   {{~! ~}}
    .tag').hasText('

'); }); + + test('takes a @start param to apply on the

 element ', async function (assert) {
+    const code =
+      '

line 1

\n

line 2

\n

line 3

\n

line 4

\n

line 5

\n'; + const lineStartNumber = 1000; + this.set('code', code); + this.set('start', lineStartNumber); + await render(hbs` + + `); + + assert.dom('pre').hasAttribute('data-start', `${lineStartNumber}`); + assert.dom('.line-numbers').hasStyle({ + 'counter-reset': `linenumber ${lineStartNumber - 1}`, + }); + }); }); From 877bbefb6d02d7d07ea4904245280fc4befd4441 Mon Sep 17 00:00:00 2001 From: Sean Goresht Date: Fri, 22 Jul 2022 17:03:26 -0600 Subject: [PATCH 2/3] doc: add documentation for overriding line numbers --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index e2bdc672..be80b254 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,29 @@ For the latter you may need to use `<`, and `>` html attributes to escape The `@language` argument is optional, and if passed should match one of Prism's [supported languages](https://prismjs.com/#supported-languages). +#### Overriding Line Numbers + +If you have opted to use the `line-numbers` plugin within your `ember-cli-build.js`, then you can optionally pass in `@start` to `` to set a custom starting line. This is particularly useful when showing "contiguous" *hunks* of code (while not showing the *entire* code file). + +(within `ember-cli-build.js`): +```js +module.exports = function (defaults) { + let app = new EmberAddon(defaults, { + // other options + 'ember-prism': { + plugins: ['line-numbers'] + }, + }); +}; +``` + +(in your component that renders a ``) +```hbs + +``` + +This will result in the code block starting its line numbering from `this.vulnerability.startLineNumber`, instead of `1`. + ### Configuration You can set which theme, components, and plugins you'd like to use from Prism. From 82f254d20605eb9fd2802349b85439f5649da7ad Mon Sep 17 00:00:00 2001 From: Sean Goresht Date: Sun, 24 Jul 2022 20:22:53 -0600 Subject: [PATCH 3/3] doc(refactor): provide more generic example of custom `@start` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index be80b254..b7b84640 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,10 @@ module.exports = function (defaults) { (in your component that renders a ``) ```hbs - + ``` -This will result in the code block starting its line numbering from `this.vulnerability.startLineNumber`, instead of `1`. +This will result in the code block starting its line numbering from `2`, instead of `1`. ### Configuration