This guide demonstrates the advanced code block features available in the documentation, including syntax highlighting, line numbers, line highlighting, annotations, and the new line selection feature.
defhello_world():"""A simple function that prints Hello World."""message="Hello World"print(message)# This is a commentforiinrange(5):print(f"Count: {i}")returnTrue
defhello_world():"""A simple function that prints Hello World."""message="Hello World"print(message)# This is a commentforiinrange(5):print(f"Count: {i}")returnTrue
defhello_world():"""A simple function that prints Hello World."""message="Hello World"# This line is highlightedprint(message)# This comment and the next two lines are highlightedforiinrange(5):print(f"Count: {i}")returnTrue
defhello_world():"""A simple function that prints Hello World."""message="Hello World"print(message)# This is a commentforiinrange(5):print(f"Count: {i}")returnTrue
defhello_world():"""A simple function that prints Hello World."""message="Hello World"print(message)# (1)# This is a commentforiinrange(5):print(f"Count: {i}")# (2)returnTrue# (3)
The line selection feature allows you to select and share specific lines of code. Click on any line number to select that line. You'll see a "Select lines" button appear that allows you to copy a link to the selected line(s).
To enable code line selection in your code blocks, use the linenums="1" attribute to enable line numbers. The line selection feature is automatically available for all code blocks with line numbers.
When users click on a line number, the "Select lines" button appears, allowing them to copy a link that directly highlights those specific lines when shared.
This feature is particularly useful for:
Referencing specific parts of code during discussions
Creating targeted documentation links
Sharing specific implementation details
Highlighting important security controls
After selecting lines, users can copy the URL which contains a fragment identifier that will highlight those lines when the page is loaded.