-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Refactor: Improve createExcerpt in markdownUtils #11229
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
base: main
Are you sure you want to change the base?
Refactor: Improve createExcerpt in markdownUtils #11229
Conversation
This commit refactors the `createExcerpt` function in `packages/docusaurus-utils/src/markdownUtils.ts`. The key changes include: - The function now utilizes the `remark` and `strip-markdown` libraries to parse Markdown content and remove Markdown/HTML syntax. This replaces the previous regex-heavy approach for syntax stripping, leading to more robust and accurate excerpt generation. - The existing line-by-line processing logic for identifying the first contentful line (ignoring H1 headings, import/export statements, and code blocks) has been preserved to maintain stability and backward compatibility, especially as `createExcerpt` is deprecated. A comprehensive suite of unit tests has been added in `packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts` to ensure the refactored function behaves as expected across various scenarios. These tests cover different types of content, Markdown syntax, HTML tags, and edge cases.
Hi @priyanshscpp! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
This looks like a PR vibe coded with Jules. I'm ok to consider such PR, but please make sure they pass all our CI checks, otherwise I don't want to spend time reviewing code that you didn't even write. The general rule is: don't send AI-generated PRs if you wouldn't be able to write it on your own, and review even more thoroughly before asking me to. For this kind of code, we also care about how it performs compared to before. |
This commit refactors the
createExcerpt
function inpackages/docusaurus-utils/src/markdownUtils.ts
.The key changes include:
remark
andstrip-markdown
libraries to parse Markdown content and remove Markdown/HTML syntax. This replaces the previous regex-heavy approach for syntax stripping, leading to more robust and accurate excerpt generation.createExcerpt
is deprecated.A comprehensive suite of unit tests has been added in
packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
to ensure the refactored function behaves as expected across various scenarios. These tests cover different types of content, Markdown syntax, HTML tags, and edge cases.Pre-flight checklist
Motivation
Test Plan
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs