Skip to content

Expose MarkEditGetHtml as a global function#77

Merged
cyanzhong merged 1 commit into
mainfrom
develop
Mar 12, 2026
Merged

Expose MarkEditGetHtml as a global function#77
cyanzhong merged 1 commit into
mainfrom
develop

Conversation

@cyanzhong

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR exposes a new global entry point for retrieving rendered HTML from the MarkEdit Preview extension, reusing the existing “save as HTML” rendering pipeline.

Changes:

  • Add a Window.__markeditPreviewGetHtml__ global function type and assign it during initialization.
  • Refactor HTML export logic in src/view.ts into a reusable generateStaticHtml(styled) function.
  • Update the save-to-file flow to call the new shared generator.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
types/global.d.ts Adds a global __markeditPreviewGetHtml__ function type on window.
src/view.ts Extracts HTML generation into generateStaticHtml() and reuses it for save/export.
main.ts Wires generateStaticHtml onto window.__markeditPreviewGetHtml__ during init.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@cyanzhong cyanzhong changed the title Expose __markeditPreviewGetHtml__ as a global function Expose MarkEditGetHtml as a global function Mar 12, 2026
@cyanzhong cyanzhong requested a review from Copilot March 12, 2026 13:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread main.ts Outdated
Comment on lines 43 to 45
window.MarkEditGetHtml = generateStaticHtml;
}

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

window.MarkEditGetHtml is only assigned inside the else branch. If the extension/script is reloaded while __markeditPreviewInitialized__ is already true (e.g., hot reload / update in-place), this new global may never be installed, leaving it undefined at runtime. Consider assigning it unconditionally (or at least window.MarkEditGetHtml ??= generateStaticHtml) so the global is available even when setup is skipped.

Suggested change
window.MarkEditGetHtml = generateStaticHtml;
}
}
window.MarkEditGetHtml ??= generateStaticHtml;

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot Are you making things up? How is this even possible?

This function is assigned to window, how is reloading the extension removes it??

Show me an example.

Copilot AI commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

@cyanzhong I've opened a new pull request, #78, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread README.md
@cyanzhong cyanzhong merged commit df50195 into main Mar 12, 2026
5 checks passed
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.

3 participants