Skip to content

feat: Add async provideParser provideLexer - #3756

Merged
UziTech merged 4 commits into
markedjs:masterfrom
UziTech:async-provide-parser-lexer
Oct 7, 2025
Merged

feat: Add async provideParser provideLexer#3756
UziTech merged 4 commits into
markedjs:masterfrom
UziTech:async-provide-parser-lexer

Conversation

@UziTech

@UziTech UziTech commented Sep 7, 2025

Copy link
Copy Markdown
Member

Marked version: 16.2.1

Description

Allow provideParser and provideLexer to be async functions.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel

vercel Bot commented Sep 7, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marked-website Ready Ready Preview Comment Sep 16, 2025 3:54am

@UziTech
UziTech force-pushed the async-provide-parser-lexer branch from 6e1c3f9 to 8f78206 Compare September 16, 2025 02:57
@UziTech
UziTech marked this pull request as ready for review September 16, 2025 03:01
@UziTech

UziTech commented Sep 16, 2025

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request successfully adds support for asynchronous provideParser and provideLexer hooks, which is a great enhancement. The implementation is correct and includes appropriate tests. My review includes a couple of suggestions to refactor parts of the asynchronous logic to use async/await. This will improve code readability and maintainability, making the code easier to understand and work with in the future.

Comment thread src/Instance.ts Outdated
Comment thread src/Instance.ts Outdated
@UziTech UziTech changed the title Async-provide-parser-lexer feat: Add async provideParser provideLexer Sep 16, 2025
@UziTech

UziTech commented Sep 16, 2025

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces asynchronous functionality for provideParser and provideLexer hooks, which is a great enhancement. The implementation correctly uses async/await to handle the new asynchronous nature of these hooks. I've made a few suggestions to improve code consistency within the new async processing block and to expand test coverage to ensure all new asynchronous paths are validated.

Comment thread src/Instance.ts
Comment thread test/unit/Hooks.test.js
Comment thread test/unit/Hooks.test.js
@UziTech

UziTech commented Sep 16, 2025

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces support for asynchronous provideParser and provideLexer hooks. The changes correctly refactor the parsing pipeline to use async/await when async mode is enabled, allowing these hooks to return promises. The implementation is sound, and new tests have been added to cover the new asynchronous functionality. I have one suggestion to improve code consistency and maintainability.

@UziTech

UziTech commented Sep 17, 2025

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request successfully adds asynchronous capabilities to provideParser and provideLexer hooks, including comprehensive tests for the new functionality. The conversion of promise chains to async/await syntax improves code readability. However, the implementation introduces significant code duplication in src/Instance.ts to handle both synchronous and asynchronous execution paths. I've left two comments highlighting these areas, with severities of 'medium' and 'high', as they impact maintainability. Addressing this duplication would greatly improve the quality of the changes.

@UziTech

UziTech commented Oct 4, 2025

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds the ability for provideParser and provideLexer hooks to be asynchronous, which is a great feature enhancement. The implementation correctly refactors the asynchronous parsing path to use async/await and handles the new async hooks.

However, I've found a critical issue in the synchronous parsing path. If a user provides an async hook for provideLexer or provideParser but does not enable the async: true option, the application will hit a runtime error because it will try to execute a Promise as a function. I've left a specific comment with more details on how to address this to make the API safer and more robust for developers.

The added tests cover the new functionality well for the asynchronous cases.

Comment thread src/Instance.ts
@UziTech
UziTech merged commit 09577e5 into markedjs:master Oct 7, 2025
8 checks passed
@UziTech
UziTech deleted the async-provide-parser-lexer branch October 7, 2025 03:22
github-actions Bot pushed a commit that referenced this pull request Oct 7, 2025
# [16.4.0](v16.3.0...v16.4.0) (2025-10-07)

### Bug Fixes

* Fix backtick and code rendering in links ([#3783](#3783)) ([302ee59](302ee59))
* fix links with square brackets in inline code break wrapping italics ([#3785](#3785)) ([e3c0d3e](e3c0d3e))
* Make `www` case-sensitive when detecting link starts ([#3770](#3770)) ([626d961](626d961))

### Features

* Add async provideParser provideLexer ([#3756](#3756)) ([09577e5](09577e5))
vaernion pushed a commit to Arbeidstilsynet/brevgen2 that referenced this pull request Dec 3, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [marked](https://marked.js.org) ([source](https://github.com/markedjs/marked)) | [`16.3.0` -> `16.4.0`](https://renovatebot.com/diffs/npm/marked/16.3.0/16.4.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/marked/16.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/marked/16.3.0/16.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>markedjs/marked (marked)</summary>

### [`v16.4.0`](https://github.com/markedjs/marked/releases/tag/v16.4.0)

[Compare Source](markedjs/marked@v16.3.0...v16.4.0)

##### Bug Fixes

- Fix backtick and code rendering in links ([#&#8203;3783](markedjs/marked#3783)) ([302ee59](markedjs/marked@302ee59))
- fix links with square brackets in inline code break wrapping italics ([#&#8203;3785](markedjs/marked#3785)) ([e3c0d3e](markedjs/marked@e3c0d3e))
- Make `www` case-sensitive when detecting link starts ([#&#8203;3770](markedjs/marked#3770)) ([626d961](markedjs/marked@626d961))

##### Features

- Add async provideParser provideLexer ([#&#8203;3756](markedjs/marked#3756)) ([09577e5](markedjs/marked@09577e5))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or PR is renamed to start with "rebase!".

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Related work items: #30372
Logiclayer1111 pushed a commit to Logiclayer1111/marked that referenced this pull request Apr 20, 2026
# [16.4.0](markedjs/marked@v16.3.0...v16.4.0) (2025-10-07)

### Bug Fixes

* Fix backtick and code rendering in links ([#3783](markedjs/marked#3783)) ([78037b8](markedjs/marked@78037b8))
* fix links with square brackets in inline code break wrapping italics ([#3785](markedjs/marked#3785)) ([dcdebc6](markedjs/marked@dcdebc6))
* Make `www` case-sensitive when detecting link starts ([#3770](markedjs/marked#3770)) ([eedf93b](markedjs/marked@eedf93b))

### Features

* Add async provideParser provideLexer ([#3756](markedjs/marked#3756)) ([e2e276c](markedjs/marked@e2e276c))
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.

1 participant