-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
fix(v2): fix contentTitle issues when markdown h1 title contains code blocks #4882
Conversation
const Heading = (Tag: HeadingType): ((props: Props) => JSX.Element) => | ||
type HeadingComponent = (props: Props) => JSX.Element; | ||
|
||
export const MainHeading: HeadingComponent = function MainHeading({...props}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For h1 found in MDX we don't add anchors.
This is a potential side-effect for a minority of users but using multiple h1 in a doc is not something they should do in the first place
description: API reference for Docusaurus configuration file. | ||
slug: /docusaurus.config.js | ||
--- | ||
|
||
# `docusaurus.config.js` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dogfood on our site
Size Change: -37 B (0%) Total Size: 621 kB
ℹ️ View Unchanged
|
✔️ [V1] 🔨 Explore the source changes: dbe52b1 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-1/deploys/60b8ec2778d6850007300cf3 😎 Browse the preview: https://deploy-preview-4882--docusaurus-1.netlify.app |
✔️ [V2] 🔨 Explore the source changes: dbe52b1 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/60b8ec27b2b097000af49add 😎 Browse the preview: https://deploy-preview-4882--docusaurus-2.netlify.app |
What are the advantages of having it as a direct child?
That seems fixable Will think about it, I have another idea. |
@lex111 , before the recent changes regarding markdown title extraction, we already had h1 under markdown. For example, here's what a React-Redux used to look like before upgrading: I think it makes sense that an h1 in markdown appears under the markdown class and not above, and we should restore the previous behavior. We would have to handle 2 cases:
We should make them look the same I'm not sure it's a problem in terms of HTML markup/accessibility? We used to have those 2 cases before anyway, and it has never been reported as a problem. Not even sure the CSS was 100% equivalent, but quite close so users didn't notice. The most visible difference is that a h1 in markdown had an anchor (cf https://deploy-preview-1705--react-redux-docs.netlify.app/api/provider) So, my suggestion would be to:
|
I don't have too much opinion about making it separate or not, but feel it's more complicated to make it separate particularly if
Actually, it didn't use to be like that. Before #4485, a
Any ref? I'm seeing other frameworks like Vuepress or MkDocs also putting the h1 inside the content wrapper at the same level as other elements:
I agree that having to handle 2 distinct markup cases is not ideal We have 3 choices:
For now I'm going to move on, consider #4485 introduced a regression and restore 1) the previous behavior. Most users don't use Even if it creates 2 separate cases (like before), at least it fixes the issue of unability to use inline code blocks, which looks more important to users than having a perfect homogeneous markup. If you are willing to use solution 2), or can make a technical proposition for 3) without loosing the ability to use inline code blocks (looks not easy), then we could improve the markup and have only 1 case left. That can be done in another enhancement PR. |
Alright, let us choose the path of least resistance then -- always put h1 inside div.markdown. |
…eing added in the dom (not a markdown # title in content)
…ntmatter title in priority over the contentTitle
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-4882--docusaurus-2.netlify.app/ |
Motivation
We should support using inline code blocks and other fancy MD syntax in top-level titles:
This is not the case, as currently reported by @markerikson: #4868 (comment)
This is because titles are extracted as plain string, and then added back at the top of the document as separate JSX.
I think it would be better to leave h1 title as part of the MDX content in the first place, so that any MD syntax remains effective.
@lex111 I tried to make this retro compatible with the existing CSS, it looks fine to me, let me know if you see any problem with this new approach.
Some possible side-effects:
Have you read the Contributing Guidelines on pull requests?
(Write your answer here.)
Test Plan
tests + preview + dogfood
Related PRs
reduxjs/react-redux#1725