vitepress: Markdown Style on the Homepage does not work properly
Describe the bug
Markdown on the home page does not have the correct article style
Reproduction
---
layout: home
hero:
name: VuePress
text: Vite & Vue powered static site generator.
tagline: Lorem ipsum...
actions:
- theme: brand
text: Get Started
link: /guide/what-is-vitepress
- theme: alt
text: View on GitHub
link: https://github.com/vuejs/vitepress
features:
- icon: ⚡️
title: Vite, The DX that can't be beat
details: Lorem ipsum...
- icon: 🖖
title: Power of Vue meets Markdown
details: Lorem ipsum...
- icon: 🛠️
title: Simple and minimal, always
details: Lorem ipsum...
---
# H1
hello world
## H2
hello world
### H3
hello world
```sh
npm i -g vitepress
\```
Expected behavior
HomePage markdown have the right Style Like docs
System Info
System:
OS: macOS 11.2.3
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 716.61 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.19.1 - ~/.nvm/versions/node/v14.19.1/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v14.19.1/bin/yarn
npm: 6.14.16 - ~/.nvm/versions/node/v14.19.1/bin/npm
Watchman: 2021.06.07.00 - /usr/local/bin/watchman
Browsers:
Chrome: 102.0.5005.115
Edge: 102.0.1245.41
Safari: 14.0.3
npmPackages:
vitepress: ^1.0.0-alpha.2 => 1.0.0-alpha.2
Additional context
Validations
- Follow our Code of Conduct
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 21 (10 by maintainers)
@kiaking First, thank you for the work on Vitepress. It’s very powerful!
I don’t like this approach. With a tool like this I would expect to be able to just add markdown like any other page or layout and have it just work. If I am using VP I am likely trying to bootstrap a site with minimal effort and maximum output. That seems like the objective of such a tool. But when I can’t just add markdown to the homepage without inserting custom styles this seems like an unnecessary roadblock.
I faced the same issue and created a component
HomeContent.vue
to wrap my home markdown content:How would this work? I’ve attempted this:
As I expected, markdown isn’t rendered inside the HTML tags, I see the “##” characters. What am I missing? I’m using layout: home.
EDIT: I’ve solved this, it was a matter of inserting line breaks before and after the HTML tags for markdown to be parsed. I couldn’t find any documentation on this behaviour though. I’m glad markdown isn’t supported only at top-level though.
For now, you can just wrap your markdown with
<div class="vp-doc">...</div>
to get similar styles (some styles and functions may not work as they might be scoped for example headings don’t get that anchor icon, code block doesn’t get copy button, etc). Also, you’ll have to add some container like thing too to keep it aligned with the hero section.I very much agree, the first thing the get started tells you is to create an index.md (a markdown file) so literally the first thing I tried (writting markdown), didn’t work as expected, (doesn’t render as markdown) with no instructions on how to get such expected behavior.
I think the index.md needs to have a decent out of the box styling (which seems to be the entire value of vp), else it should just have been an index.yml file with only the frontmatter.
Yes, the DOM is the same. So you get Markdown parsing, but without styles. Because there’s a good chance you want to have bigger
<h2>
font size for example.Thanks good to know! If we want to add such section, I think it’s best to wrap it inside some kind of section component.
Because for example in Homepage, the max width is set to 1152px but that’s way too large for normal texting. We should take care such section in a way that it looks perfectly beautiful 👍
Seems like it would make sense to wrap the home layout specific frontmatter content in the wider width container, and print any additional content in the normal style of every other page.
It definitely feels broken that this isn’t the default behaviour (Especially given there’s no mention of that in the docs)
if user onily need If the user just wants to add some simple descriptive language and code blocks to the front page
But now they have no style, which looks very much like a bug
If a custom component is recommended, it will increase the cost of getting started for newcomers
Users who do this generally expect their styles to remain theme defaults
But the Dom renders just like the document type
I remember that in VuePress the home page style was also the one that applied the content of the document correctly
My Case
I Want add some words and code example on the homePage,