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

Fix md highlight #6842

Merged
merged 4 commits into from Dec 19, 2023
Merged

Fix md highlight #6842

merged 4 commits into from Dec 19, 2023

Conversation

pngwn
Copy link
Member

@pngwn pngwn commented Dec 19, 2023

Description

some weird issues as we were reusing the same marked instance across multiple instances of gr.Markdown. The issues only seems to present when more than on markdown component is used.

https://marked.js.org/using_advanced#instance

The quickstart for marked is idiotic in the extreme but this should fix it.

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@@ -128,28 +127,26 @@ export function create_marked({
);

if (header_links) {
if (header_links) {
Copy link
Member Author

Choose a reason for hiding this comment

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

dno why we had this double if

@@ -110,6 +107,8 @@ export function create_marked({
header_links: boolean;
line_breaks: boolean;
}): typeof marked {
const marked = new Marked();
Copy link
Member Author

Choose a reason for hiding this comment

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

Fresh instance per 'create_marked`.

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Dec 19, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/cd6393bc3fbf084578de5a5c3f04a54af087a610/gradio-4.10.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@cd6393bc3fbf084578de5a5c3f04a54af087a610#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Dec 19, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/markdown minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix md highlight

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

Copy link
Member Author

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

We were basically adding all plugins to the same renderer for every instance of the component. So 2 instances would be 2 highlighters. And i think that basically meant that the highlighted code was being passed through the highlighter again (but at that point it was html code).

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the fix @pngwn!

@pngwn pngwn merged commit 846d52d into main Dec 19, 2023
19 of 20 checks passed
@pngwn pngwn deleted the fix-md-highlight branch December 19, 2023 20:42
@pngwn pngwn mentioned this pull request Dec 19, 2023
whitphx pushed a commit that referenced this pull request Dec 20, 2023
* ensure gr.Markdown instances have their own instance of the markdown renderer

* fix demo

* add changeset

* skopip test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
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.

None yet

3 participants