Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifing the start line number on code block #2907

Closed
4 tasks done
mehm8128 opened this issue Sep 4, 2023 · 4 comments
Closed
4 tasks done

Specifing the start line number on code block #2907

mehm8128 opened this issue Sep 4, 2023 · 4 comments

Comments

@mehm8128
Copy link
Contributor

mehm8128 commented Sep 4, 2023

Is your feature request related to a problem? Please describe.

I'm writing programming learning text, and I want to specify the start line number on code block to show a part of the whole code.
The below is an example file.

index.js
```
const ddd = 'eee'
function aaa(){
const bbb = 'ccc'
console.log(bbb)
}
```

Then, when I want to show only this aaa function, I want to let vitepress show as below(I want to start the line number with 2).

2 function aaa(){
3 const bbb = 'ccc'
4 console.log(bbb)
5 }

But with current features of vitepress, we cannot realize it.

Describe the solution you'd like

I suggest below writing rule.

```js @2
function aaa(){
const bbb = 'ccc'
console.log(bbb)
}
```

or

```js:line-numbers @2
function aaa(){
const bbb = 'ccc'
console.log(bbb)
}
```

With @, I want to specify the start line number(of course, other than @ is also ok).

Describe alternatives you've considered

No response

Additional context

HackMD allows to specify the start line with below way.
https://hackmd.io/features?both#Code-Block

Validations

@ghost
Copy link

ghost commented Sep 6, 2023

Hello, maybe you try writing it like this in your markdown files:

``` js
<!--@include: ./parts/index.js{2,}-->
\```

please ignore \ before ```
The number '2' means the start line.

official docs refrence

@mehm8128
Copy link
Contributor Author

mehm8128 commented Sep 6, 2023

Thank you, it worked as I expectedly!!!
I close this issue.

@mehm8128 mehm8128 closed this as completed Sep 6, 2023
@mehm8128
Copy link
Contributor Author

mehm8128 commented Sep 6, 2023

Sorry, even though I could show specified lines of file, but line number is starting with 1...

@brc-dd
Copy link
Member

brc-dd commented Sep 10, 2023

now available in rc.12. refer #2917 for details

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants