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

Feature: optionally display line numbers in code blocks #799

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

snehankekre
Copy link
Contributor

@snehankekre snehankekre commented Aug 30, 2023

📚 Context

The docs can sometimes contain long code blocks. Authors may want to reference specific lines of the code block in preceding or subsequent paragraph text. Doing so without displayed line numbers can be challenging. To that end, this PR introduces a feature to optionally include line numbers in code blocks using the prism line numbers plugin. There are two ways to do:

  1. If using fenced code blocks, include showLineNumbers to the right of ```python. E.g.
```python showLineNumbers
import streamlit as st

st.write("Hello, world!")
```
  1. If using the <Code> component, set the prop showLineNumbers={true}. E.g.
<Code showLineNumbers={true}>
  <code className="language-python">
    {`
    import streamlit as st
    
    st.write("Hello, world!")
    `}
  </code>
</Code>

Since we use code blocks in many places in our docs, and some places where we might not want line numbers (API cards), line numbers are turned off by default.

🧠 Description of Changes

Revised:

image
image

Current:

image
image

💥 Impact

Size:

  • Small
  • Not small

🌐 References

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snehankekre snehankekre changed the title Feature/numbered Feature: optionally display line numbers in code blocks Aug 30, 2023
@snehankekre snehankekre marked this pull request as draft August 30, 2023 10:53
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.

2 participants