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

Markdown reloads when component classes change. #4185

Merged
merged 4 commits into from
Feb 27, 2024

Conversation

rodrigogiraoserrao
Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao commented Feb 19, 2024

Fixes #3464.

The reason why these component classes weren't being reloaded was that markdown blocks inherit from Static and they had their content set when markdown was first parsed, and then they would lose access to the source markdown.

This PR moves some of the logic that builds markdown blocks into a MarkdownBlock method that parses the markdown tokens into a rich.text.Text but also keeps track of the original source token.
This way, when CSS is reloaded, we can just ask the MarkdownBlock to rebuild itself.

By creating this method directly in MarkdownBlock, we only save the markup that is necessary and only reload the nodes that may have inline styles.

"""

self._token = token
style_stack: list[Style] = [Style()]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From style_stack: ... to the end of this method, I copied and pasted the code.
The only change happens when I'm getting the component classes.
Instead of getting them from self, I get them from self._markdown.

@rodrigogiraoserrao rodrigogiraoserrao marked this pull request as ready for review February 19, 2024 17:53
@rodrigogiraoserrao rodrigogiraoserrao merged commit 8e44e04 into main Feb 27, 2024
20 checks passed
@rodrigogiraoserrao rodrigogiraoserrao deleted the reload-markdown-component-classes branch February 27, 2024 13:42
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.

Some markdown component classes don't refresh on CSS update
2 participants