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

feat(n-code): adds initial-line-number props #5818

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- `n-form-item` add `feedback-vertical` prop and `feedback-crosswise` prop
- `n-split` supports setting the pixel value size.
- `n-scrollbar` adds `content-style` and `content-class` props, closes [#4497](https://github.com/tusen-ai/naive-ui/issues/4497).
- `n-code` adds `initial-line-number` props, closes [#5816](https://github.com/tusen-ai/naive-ui/issues/5816)

## 2.38.1

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- `n-form-item` 新增 `feedback-vertical` 和 `feedback-crosswise` 属性
- `n-split` 支持设置像素值大小
- `n-scrollbar` 新增 `content-style` 和 `content-class` 属性,关闭 [#4497](https://github.com/tusen-ai/naive-ui/issues/4497)
- `n-code` 新增 `initial-line-number` 属性,关闭 [#5816](https://github.com/tusen-ai/naive-ui/issues/5816)

## 2.38.1

Expand Down
1 change: 1 addition & 0 deletions src/code/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ line-numbers.vue
| hljs | `Object` | `undefined` | If you want to set hljs locally, pass it using this prop. | |
| inline | `boolean` | `false` | Whether the code is displayed as inline. | |
| language | `string` | `undefined` | Code language in highlightjs. | |
| initial-line-number | `number` | `1` | Initial line number | NEXT_VERSION |
| show-line-numbers | `boolean` | `false` | Whether to show line numbers. Won't work if `inline` or `word-wrap` is `true`. | 2.32.0 |
| trim | `boolean` | `true` | Whether to display trimmed code. | |
| word-wrap | `boolean` | `false` | Whether to display word-wrapped code. | 2.24.0 |
1 change: 1 addition & 0 deletions src/code/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ line-numbers.vue
| inline | `boolean` | `false` | 使用行内样式 | |
| hljs | `Object` | `undefined` | 如果你想局部设定 hljs,可以通过这个属性传给组件 | |
| language | `string` | `undefined` | 代码在 highlightjs 中的语言 | |
| initial-line-number | `number` | `1` | 初始行号 | NEXT_VERSION |
| show-line-numbers | `boolean` | `false` | 是否显示行号,在 `inline` 或 `word-wrap` 的情况下不生效 | 2.32.0 |
| trim | `boolean` | `true` | 是否显示 trim 后的代码 | |
| word-wrap | `boolean` | `false` | 代码过长时是否自动换行 | 2.24.0 |
6 changes: 5 additions & 1 deletion src/code/src/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export const codeProps = {
uri: Boolean,
inline: Boolean,
wordWrap: Boolean,
initialLineNumber: {
type: Number,
default: 1
},
showLineNumbers: Boolean,
// In n-log, we only need to mount code's style for highlight
internalFontSize: Number,
Expand Down Expand Up @@ -177,7 +181,7 @@ export default defineComponent({
codeRef,
mergedShowLineNumbers: mergedShowLineNumbersRef,
lineNumbers: computed(() => {
let number = 1
let number = props.initialLineNumber
const numbers: number[] = []
let lastIsLineWrap = false
for (const char of props.code) {
Expand Down