Skip to content
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

How can I render the $page. excerpt to html #446

Closed
stickmy opened this issue May 14, 2018 · 15 comments
Closed

How can I render the $page. excerpt to html #446

stickmy opened this issue May 14, 2018 · 15 comments

Comments

@stickmy
Copy link
Contributor

stickmy commented May 14, 2018

I try to add @md: require('path').resolve('node_modules/vuepress/markdown') in webpack config, then I can use the vuepress md.render to render $page. excerpt, but I failed

@ulivz
Copy link
Member

ulivz commented May 15, 2018

Could you provide reproduced repo?

@stickmy
Copy link
Contributor Author

stickmy commented May 15, 2018

@ulivz
repo: https://github.com/Bloss/vuepress-issue-446
At config.js, I try to add @md alias

Then, I try to import vuepress's md.render function at ArticleCard, but I failed

So how can I render the $page.excerpt to html : )

@ulivz
Copy link
Member

ulivz commented May 15, 2018

I don't know why you need to import the lib/markdown. You cannot import it at client side since the internal markdown module depends on chalk which will check for process of node only.

If you want to render $page.excerpt, you can do:

In your markdown:

I am excerpt

<!-- more -->

I am content

In your custom component:

<div v-html="$page.excerpt"></div>

@ulivz ulivz closed this as completed May 15, 2018
@stickmy
Copy link
Contributor Author

stickmy commented May 15, 2018

@ulivz <div v-html="$page.excerpt"></div> render $page.excerpt as raw text(markdown format), but what I need is to render it to html

@tdurieux
Copy link

I confirm this behavior, I did not succeed to render the markdown.

@ulivz
Copy link
Member

ulivz commented May 15, 2018

@Bloss why $page.excerpt within v-html will be rendered as raw text? Did you really try?

@ulivz
Copy link
Member

ulivz commented May 15, 2018

FYI:

The markdown text in excerpt range will also be compiled to HTML string.

@tdurieux
Copy link

The markdown text in excerpt range will also be compiled to HTML string.

Unfortunately it is not the case, you can see here:

data.excerpt = frontmatter.excerpt

that the content of excerpt is not compiled to HTML.

@ulivz
Copy link
Member

ulivz commented May 15, 2018

Unfortunately it is not the case

So what's your case? 😅

@tdurieux
Copy link

I just told you: that the content of excerpt is not compiled to HTML.

@ulivz
Copy link
Member

ulivz commented May 15, 2018

I have said, you have to try, but I don't think you have tried.

e.g. add following code at your README:

# H1
## H2

- 1
- 2
- 3

<!-- more -->

...

Then add this in your Layout component:

<div v-html="$page.excerpt"></div>

Then you will see:

image

So, why the content of excerpt is not compiled to HTML?

@vuejs vuejs locked and limited conversation to collaborators May 15, 2018
@vuejs vuejs unlocked this conversation May 17, 2018
@ulivz
Copy link
Member

ulivz commented May 17, 2018

@Bloss Sorry, I just made a wrong judgment, it's truly not compiled to HTML...

@ulivz
Copy link
Member

ulivz commented May 17, 2018

Let's continue at #458

@tdurieux
Copy link

Surprisingly...

@stickmy
Copy link
Contributor Author

stickmy commented May 17, 2018

@ulivz It's ok, Let's continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants