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

Link to markdown title with special characters #955 #8114

Closed
2 tasks done
hoorelbeke-jimmy opened this issue Feb 8, 2024 · 8 comments
Closed
2 tasks done

Link to markdown title with special characters #955 #8114

hoorelbeke-jimmy opened this issue Feb 8, 2024 · 8 comments
Labels
feature:markdown status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working

Comments

@hoorelbeke-jimmy
Copy link

hoorelbeke-jimmy commented Feb 8, 2024

Checklist

  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.

Summary

I am displaying with streamlit some content, and I would like to display some links to markdown titles present on the streamlit page. For instance, the following is working:

import streamlit as st

st.markdown("# Introduction")
st.markdown("display some large text content")
st.markdown("[link](#introduction)") # does work

When I click on link, I return to the beginning of the section Introduction. However, this doesn't work when I use special characters in my title, for instance:

import streamlit as st

st.markdown("# Présentation")
st.markdown("display some large text content")
st.markdown("[link](#présentation)") # doesn't work
st.markdown("[link](#presentation)") # doesn't work either

To better understand the issue, I clicked on the anchor link on the left of the title "# Présentation", and I see on the URL that the link is "78e1d857" (for "# Introduction" it was "introduction").

Why?

My goal would be to be able to generate a link to the section "# Présentation" within my streamlit page, and for this I need to understand why the anchor link is "78e1d857". I tried to reverse engineer how to get this link based on the title content by looking at GitHub Flavored markdown, but I didn't find a way to do so.

How?

A method in the streamlit package that returns the anchor link based on a makdown title would be even better, for instance:

import streamlit as st

title = "Présentation"
st.markdown(f"#{title}")
st.markdown(f"[link](#{st.get_link_from_title(title)})")

Additional Context

No response

@hoorelbeke-jimmy hoorelbeke-jimmy added the type:enhancement Requests for feature enhancements or new features label Feb 8, 2024
Copy link

github-actions bot commented Feb 8, 2024

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

@snehankekre snehankekre added feature:markdown status:needs-triage Has not been triaged by the Streamlit team labels Feb 8, 2024
@sfc-gh-skekre sfc-gh-skekre added type:bug Something isn't working and removed type:enhancement Requests for feature enhancements or new features labels Feb 15, 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

@snehankekre
Copy link
Collaborator

I'm unsure if this is a bug in how we handle anchors in markdown, or if it is expected behavior. Out of caution, marking this as a bug to be triaged by Eng, who can make the determination whether this should instead be an enhancement request.

@sfc-gh-wihuang
Copy link
Contributor

Hi, This is actually expected behavior: https://www.w3.org/TR/PR-html40-971107/struct/links.html#h-12.2.1

I recommend just using regular ascii characters.

A workaround you could do is using st.title and setting an anchor and that could possibly resolve your issue but it's not recommended .

@hoorelbeke-jimmy
Copy link
Author

Actually I can't use only ascii characters. Indeed, most languages except English (French in my case) use accents which are not ascii characters. I completely understand that you can't use those characters directly in the URL, but I'm just asking how I can generate a valid URL that points to a title with special characters.
As I explained it in my original post, this URL exists, since "# Présentation" has an anchor link "78e1d857". There must be a place in streamlit source code where this title is converted into this hash to generate the link. Could please help me to find this code ?

@sfc-gh-wihuang
Copy link
Contributor

Hi @hoorelbeke-jimmy ,

Can you try using:
st.title("Présentation", anchor="Présentation")
?

@hoorelbeke-jimmy
Copy link
Author

Thanks it works, but why did you say it is not recommended ?

@sfc-gh-wihuang
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:markdown status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants