Skip to content

fix(v2): parse headings directly after h1 properly - #4641

Merged
slorber merged 1 commit into
masterfrom
lex111/iss4634
Apr 19, 2021
Merged

slorber merged 1 commit into
masterfrom
lex111/iss4634

Conversation

@lex111

@lex111 lex111 commented Apr 18, 2021

Copy link
Copy Markdown
Contributor

Motivation

Should fix #4634.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Suppose we have doc without defined title in frontmatter:

---
id: test
---

# Title

## Second heading

Results:

Before After
image image

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: bug fix This PR fixes a bug in a past release. label Apr 18, 2021
@lex111
lex111 requested a review from slorber as a code owner April 18, 2021 18:14
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 18, 2021
@netlify

netlify Bot commented Apr 18, 2021

Copy link
Copy Markdown

@netlify

netlify Bot commented Apr 18, 2021

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 57
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4641--docusaurus-2.netlify.app/

@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 630 kB

ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.5 kB 0 B
website/build/assets/js/main.********.js 453 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.3 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 27.1 kB 0 B

compressed-size-action

const content = contentUntrimmed.trim();

const regularTitleMatch = /^(?<pattern>#\s*(?<title>[^#\n]*)+\s*#*[\s\r]*?\n*?)/g.exec(
const regularTitleMatch = /^(?<pattern>#\s*(?<title>[^#\n]*)+[ \t]*#?\n*?)/g.exec(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, that seems to work but I don't understand why 😅 can you explain me?

Also, just thought about it, but we should probably do something for the {#headingId} syntax, as the cli will add it to h1 headings too

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.

Not sure if I can do it better than just showing demo link on regex101.

We are interested in first-level heading, so next h2 with explicit id will be parsed as expected.

@slorber
slorber merged commit 808b0fa into master Apr 19, 2021
@slorber
slorber deleted the lex111/iss4634 branch August 17, 2021 18:02
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

First Markdown heading directly following a h1 Markdown heading is rendered as <p>

3 participants