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

st.code ignores language argument if set to 'diff' #8687

Open
3 of 4 tasks
lucasrodes opened this issue May 16, 2024 · 2 comments
Open
3 of 4 tasks

st.code ignores language argument if set to 'diff' #8687

lucasrodes opened this issue May 16, 2024 · 2 comments
Assignees
Labels
feature:st.code priority:P3 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@lucasrodes
Copy link

lucasrodes commented May 16, 2024

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

st.code should highlight the text from argument body based on what's specified by argument language. According to the documentation, the list of available languages are specified by this list (react-syntax-highlighter). However, language='diff' does not work on my end even if it appears in the aforementioned list.

Reproducible Code Example

Open in Streamlit Cloud

import streamlit as st

st.code("""
--- main
+++ develop
@@ -52,21 +52,19 @@
     "title": "Democracy index",
     "yAxis": {
         "max": 10,
-        "min": -10,
-        "facetDomain": "shared"
+        "min": -10
     },
""",
language="diff"
)

Steps To Reproduce

  1. Run the reproducible code example as a streamlit app
  2. Notice that the code syntax won't be highlighted.

Expected Behavior

The code should be highlighted. Lines starting with + should probably be green, and lines starting with - should be red.

Current Behavior

No syntax highlight happens, even if the language diff is listed in react-syntax-highlighter's list.

I am unsure if this affects other languages, but maybe does. If so, the list of languages should be edited to show the actual list of languages supported.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.34
  • Python version: 3.10.9
  • Operating System: MacOS (also tested it on Linux Ubuntu)
  • Browser: Arc (Chromium)

Additional Information

(maybe related: #5028)

@lucasrodes lucasrodes added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels May 16, 2024
Copy link

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@raethlein raethlein added status:confirmed Bug has been confirmed by the Streamlit team and removed status:needs-triage Has not been triaged by the Streamlit team labels May 16, 2024
@raethlein
Copy link
Collaborator

raethlein commented May 16, 2024

Hey @lucasrodes, I am able to confirm this! It seems like if we remove this line (style={{}}) in StreamlitSyntaxHighlighter.tsx, the syntax seems to be highlighted correctly:

Screenshot 2024-05-16 at 14 05 47

Why the style={{}} is used there and what removing it would have for side-effects requires a little bit more investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.code priority:P3 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants