Skip to content

feat: line numbers in code blocks #34844

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Harshbansal8705
Copy link

This commit adds line numbers in the code when sent. Since hightlight.js doesn't natively support line numbers, this commit implements a custom solution to prepend the line numbers to each line of code manually.

Proposed changes (including videos or screenshots)

Since highligh.js doesn't support line numbers, this PR implements it by adding line numbers manually to each line of code. It also ensures that line numbers are not selected when someone is trying to select and copy the code.

This is the updated screenshot of new code block:
image
image

Issue(s)

Closes: #914

Copy link
Contributor

dionisio-bot bot commented Dec 29, 2024

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Dec 29, 2024

⚠️ No Changeset found

Latest commit: 4395fbb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Dec 29, 2024

CLA assistant check
All committers have signed the CLA.

This commit adds line numbers in the code when sent.
Since hightlight.js doesn't natively support line numbers,
this commit implements a custom solution to prepend the line
numbers to each line of code manually.
@reetp
Copy link

reetp commented Dec 29, 2024

Can you note that there probably should be an option of other indicators on this.

Perhaps a different way of marking up - different character sequence? Eg markup if it sees code enclosed with say @@@ or somesuch?

We frequently copy pasted sections of code and don't want to be trying to strip line numbers from it.

It break established behaviour for all users.

It would also be a massive retrograde step for me and my users.

The line numbers are largely irrelevant to us.

Case 1. We normally just paste sections of code, so line numbers may be 250-269 so numbering from say 1 would be useless/irrelevant/misleading

Case 2. If we really want line numbers we can just cat -n a file in a terminal and copy/paste.

@Harshbansal8705
Copy link
Author

I reviewed your comments and noted the concern regarding how it's handled in Slack. I couldn't find a similar feature in Slack either.

We frequently copy pasted sections of code and don't want to be trying to strip line numbers from it.

In this case, it shouldn't cause any issues, as line numbers are currently not even present. Introducing line numbers would allow users to refer to specific lines, which could be beneficial.

Perhaps a different way of marking up - different character sequence? Eg markup if it sees code enclosed with say @@@ or somesuch?

Would it be feasible to add an option to toggle the line numbers instead?

It break established behaviour for all users.

I'm not sure how this would disrupt the established behavior for users. Line numbers are merely displayed and do not interfere with copying, which aligns with the current behavior.

The line numbers are largely irrelevant to us.

If line numbers are not needed, then maybe we could resolve the linked issue by adding an option to toggle them on or off?

@reetp
Copy link

reetp commented Dec 29, 2024

I reviewed your comments and noted the concern regarding how it's handled in Slack

I never mentioned Slack. No idea how it works there.

Introducing line numbers would allow users to refer to specific lines, which could be beneficial.

It could, but as I pointed out the line numbers could cause confusion if they do not align with the line numbers in the file.

If I paste line numbers 511-520 but your code numbers them 1-10 you can see it may be an issue.

Line numbers are merely displayed and do not interfere with copying, which aligns with the current behavior.

Remember that current behaviour is no line numbers at all....

Would it be feasible to add an option to toggle the line numbers instead?

I don't know. You are the one coding, not me. I suggested it should be an option.

@Harshbansal8705
Copy link
Author

I never mentioned Slack. No idea how it works there.

Yeah, it was mentioned in the issue itself.

@reetp
Copy link

reetp commented Jan 1, 2025

I never mentioned Slack. No idea how it works there.

Yeah, it was mentioned in the issue itself.

So if you read that you will see that Slack has a key sequence to insert code with numbers.

How are you implementing that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Line numbers for code blocks
3 participants