Vuepress: Markdown component

Created on 23 Apr 2018  路  17Comments  路  Source: vuejs/vuepress

Hello,

I think it would be awesome if we could have a markdown vue component that could be used in the markdown pages.

This way we could module our very long markdown into smaller sections.

Thoughts?

E.g.

# My very long md

This is a freaking long md...

<vp-md src="./sectionA.md"/>

<vp-md src="./sectionB.md"/>

<vp-md src="./sectionC.md"/>
feature request next

Most helpful comment

I don't think this has to be a component, can simply be a comment-based directive:

<!-- include ./sectionA.md -->

And then parsed and handled directly inside lib/webpack/markdownLoader.js.

All 17 comments

I don't think this has to be a component, can simply be a comment-based directive:

<!-- include ./sectionA.md -->

And then parsed and handled directly inside lib/webpack/markdownLoader.js.

I will look into that tonight if I got the time.

There is already https://www.npmjs.com/package/markdown-it-include
But I see a few problems with this:

  1. no vue templating within those included markdown files.
  2. partials have to be excluded from getting rendered by vuepress

@MartinMuzatko my attempt at #227 should be able to load vue templating.

Yet, the partials are also being rendered. Maybe we could make it so that vuepress will ignore .partial.md files and not render them.

How about the convention in other template languages or SCSS where filenames with a preceding underscore are treated as partials and don't get rendered?

_layout-header.md

@eyleron I am not so sure about this as @yyx990803 and @ulivz haven't got time to advice on this.

I know this is an old Issue, but it's something I would definitely use. I did want to point out that there are already several syntaxes for this in various markdown flavors. Personally, I'm used to using Mulitmarkdown's file transclusion syntax in a lot of my markdown already:

# Parent Markdown Stuff

{{path/to/included.md}}

See also:

A lot of the content I'm including in VuePress sites exists as Markdown already, so the more it can mimic the behavior of other renderers, the better.

@davemacdo
Please see this: https://github.com/vuejs/vuepress/pull/227

There is a plan for rolling this out.

https://github.com/vuejs/vuepress/issues/421

In 1.0.0

Thanks. I missed that in my search. I'll take my comment there.

This would be EXCELLENT! We have several "technical docs" people who want to reuse markdowns as "templates" and not learn Vue. I'm really hoping that this features is added! BTW, thanks a lot of creating Vuepress!

@rajaraodv
I have got an implementation already. But I will wait until Next version is available then I will make this a plugin.

@ycmjason Awesome!! Is there any way to use it in the current version? Context: I'm showing off how cool vuepress is to folks and one question I'm getting is that the images are too small. I just a hacky solution for the time being.

In 1.x, you can use Content component. it accepts 2 arguments: pageKey and slotKey.

<!-- Include content of another page -->
<Content :page-key="..."/>

<!-- markdown slot of the selected page  -->
<Content slot-key="..."/>

For more details, please head to: https://vuepress.vuejs.org/guide/using-vue.html#content

@ulivz see https://github.com/vuejs/vuepress/issues/1173 it seems to be broken.

@ulivz I wanted to include a markdown file from another markdown file using <Content /> but I had trouble getting it to work.

I came up with a working solution by kind of exposing findPageForPath() to the markdown scope with the following mixin.

// enhanceApp.js

import { findPageForPath } from '@app/util'

export default ({
  Vue
}) => {
  Vue.mixin({
    methods: {
      getPageKey(pages, path) {
        const result = findPageForPath(pages, path)
        return result.key
      }
    }
  })
}
<!-- my-markdown-file.md -->

<Content :page-key="getPageKey($site.pages, '/path/to/my-other-markdown-file/')" />

This solution works, however I am wondering if there is a better way to achieve this.

Any recommendations appreciated. 馃檱

Is there a better way to achieve this nowadays? For now I'm forced to do:

<Content :page-key="$site.pages.find(p => p.path === '/my-page.html').key"/>

Cheers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cfjedimaster picture cfjedimaster  路  3Comments

alinnert picture alinnert  路  3Comments

herrbischoff picture herrbischoff  路  3Comments

shaodahong picture shaodahong  路  3Comments

genedronek picture genedronek  路  3Comments