Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jrieke
Copy link
Collaborator

@jrieke jrieke commented Dec 24, 2024

Describe your changes

This PR allows using markdown features for the caption parameter of st.image. It has the same restrictions as widget labels, e.g. no tables or horizontal rules.

GitHub Issue Link (if applicable)

Closes #6808

Testing Plan

  • Added e2e tests in label_markdown_test.py. This is obviously not a widget label, but I think it makes the most sense to test it there since that file already contains all the strings for valid or invalid Markdown. If that's not desired, I can also move the test to st_image_test.py.
  • Did not add unit tests because I think the e2e test should cover it well enough and this is a pretty small feature. Plus, I don't think we have unit tests for the other label markdown tests.
  • Had to update a lot of snapshots because of subpixel movement.

Contribution License Agreement

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

@jrieke jrieke changed the title Allow markdown in caption of st.image [WIP] Allow markdown in caption of st.image Dec 24, 2024
@jrieke jrieke added security-assessment-completed Security assessment has been completed for PR impact:users PR changes affect end users change:feature PR contains new feature or enhancement implementation labels Dec 24, 2024
}))

export const StyledCaption = styled.div(({ theme }) => ({
fontFamily: theme.genericFonts.bodyFont,
Copy link
Collaborator Author

@jrieke jrieke Dec 24, 2024

Choose a reason for hiding this comment

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

Note: We can remove these styling properties because they are handled by StreamlitMarkdown if isCaption is set.

@jrieke jrieke changed the title [WIP] Allow markdown in caption of st.image Allow markdown in caption of st.image Dec 24, 2024
@jrieke jrieke marked this pull request as ready for review December 24, 2024 22:00
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have it on my list to fully remove all snapshot tests from the label_markdown e2e test since it is a bit of a pain (huge number of snapshots based on a variety of different elements). I think it's better that every element e2e test script (st_image.py in this case) contains at least one snapshot test that demonstrates that it supports markdown (a short label with a couple of markdown aspects). And these specific details - e.g. st.image caption should not support table markdown - is something that might be better tested 1) via a non-snapshot e2e tests that just checks that a table markdown does not get converted to table HTML in the DOM or maybe 2) via an RTL unit test (-> ImageList.test.tsx)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I agree, label_markdown is really annoying. Should I already move the tests to the st.image tests, or should I just leave them in there for now, and we clean it up in one go later? Both fine with me, but doing it in one go might make it more consistent / not make us end up with 5 different ways of how we test markdown support.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, ok... I added a tech debt item here to refactor the label_markdown e2e test.

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, ok... I added a tech debt item here to refactor the label_markdown e2e test.

@jrieke jrieke merged commit 4554a1d into develop Jan 8, 2025
32 checks passed
@jrieke jrieke deleted the feature/image-caption-markdown branch January 8, 2025 22:39
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
## Describe your changes

This PR allows using markdown features for the `caption` parameter of
`st.image`. It has the same restrictions as widget labels, e.g. no
tables or horizontal rules.


## GitHub Issue Link (if applicable)

Closes streamlit#6808


## Testing Plan

- Added e2e tests in `label_markdown_test.py`. This is obviously not a
widget label, but I think it makes the most sense to test it there since
that file already contains all the strings for valid or invalid
Markdown. If that's not desired, I can also move the test to
`st_image_test.py`.
- Did not add unit tests because I think the e2e test should cover it
well enough and this is a pretty small feature. Plus, I don't think we
have unit tests for the other label markdown tests.
- Had to update a lot of snapshots because of subpixel movement. 

---

**Contribution License Agreement**

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

---------

Co-authored-by: Johannes Rieke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow markdown in image caption list

4 participants