Skip to content

fix(embed): fix multiple embeds (#1078) #1324

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

Closed

Conversation

madhavarshney
Copy link

@madhavarshney madhavarshney commented Aug 1, 2020

Summary

After many hours of debugging 😅 , I found that marked mutates the tokens array that we pass directly, breaking the logic in prerenderEmbed for multiple embeds. This PR fixes #1078.

See this in marked.

prerenderEmbed(
{
compiler: this.compiler,
raw: result,
},
tokens => {
html = this.compiler.compile(tokens);
html = this.isRemoteUrl ? DOMPurify.sanitize(html) : html;
callback();
next();
}
);

Also, this may fix #791, though I haven't tested that yet.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Repo settings
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

@vercel
Copy link

vercel bot commented Aug 1, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/docsify-core/docsify-preview/b4flyaf2n
✅ Preview: https://docsify-preview-git-fork-madhavarshney-fix-embed-multiple.docsify-core.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 1, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3cca7cb:

Sandbox Source
docsify-template Configuration

Comment on lines +149 to +152
const cloned = tokens.concat();
cached[raw] = tokens.concat();
tokens.links = cached[raw].links = links;
done(tokens);
tokens.links = cloned.links = cached[raw].links = links;
done(cloned);
Copy link
Author

@madhavarshney madhavarshney Aug 1, 2020

Choose a reason for hiding this comment

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

IMO all this cloning here is a bit odd... 😄

Copy link
Member

@sy-records sy-records left a comment

Choose a reason for hiding this comment

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

Looks good, can you add some tests? 👍🏻

@madhavarshney
Copy link
Author

I'm currently a bit busy, so if anyone would like to add some tests, then go ahead! Otherwise, I'll try to do it soon (hopefully near the end of this week).

@anikethsaha
Copy link
Member

Thanks for the PR.

@madhavarshney take your time , no hurry at all. You can also convert this to draft if its ok by you in order to let others know that this is still WIP

Copy link
Member

@anikethsaha anikethsaha left a comment

Choose a reason for hiding this comment

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

Need tests for this rest its ok.

Copy link
Member

@sy-records sy-records left a comment

Choose a reason for hiding this comment

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

Waiting to add a test

@madhavarshney
Copy link
Author

This has been fixed with the upgrade to marked.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embed with :type=code replacing entire page when other embeds are present
4 participants