Skip to content

Conversation

@dlesnoff
Copy link
Contributor

@dlesnoff dlesnoff commented Nov 5, 2023

This PR is not finished yet. Attempt to fix #101.
to do:

  • addLineNumbersToHighlightedCode has to be called
  • move tests to the correct files
  • Separate numbers from code in the generated HTML so that code can be copy-pasted without the numbers.

I am not satisfied with this generated HTML but at least it renders the numbers correctly.

@@ -1,4 +1,4 @@
import std / [strutils, tables, sugar, os, strformat, sequtils]
import std / [strutils, tables, sugar, sequtils]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unused imports.


nbText: """
> This nimib document provides a brief description and example for
> This nimib document provides a brief description and example for
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, the diff contains a lot of line changes because of some automatic tool in my Vim editor to remove whitespaces at the end of lines.

Comment on lines 21 to 25
# result = """ <div>
# <code>""" & lineNumbers.join("") & """</code>
# <code>""" & code & """</code>
# </div>
# """
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should wrap the code in a table or a div container so that we can copy-paste code without the numbers.

@dlesnoff dlesnoff marked this pull request as ready for review November 10, 2023 11:07
@dlesnoff dlesnoff changed the title Add: function to add line numbers to block. Not called yet. Add: function to add line numbers to block. Dec 2, 2023
@dlesnoff dlesnoff changed the title Add: function to add line numbers to block. Add: function to add line numbers to block Dec 2, 2023
@neroist
Copy link
Contributor

neroist commented Jun 26, 2024

Why not use something like https://github.com/wcoder/highlightjs-line-numbers.js? Though I'm not sure about the impact on nimitheme...

Using it with this stylesheet works for me:

td.hljs-ln-numbers {
  text-align: center;
  color: #ccc;
  vertical-align: top;
  padding-right: 5px;

  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

td.hljs-ln-code {
  padding-left: 1em;
}

/* Fix for water.css*/
table.hljs-ln {
  width: initial;
  margin-bottom: 0;
}

table.hljs-ln tbody tr:nth-child(2n) {
  background-color: unset;
}

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.

possibility to add line numbers to code blocks

2 participants