-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
gatsby-transformer-remark not transforming excerpts #4459
Comments
This only happens when using: Otherwise, excerpt contains plain text with stripped markdown formatting. |
It is not so bad that you lose formatting such as bold or italics, but what's not nice is that escape slashes are preserved: |
It looks like the |
I've been digging around and I don't see anything obvious. It took me a while, but I figured out that the I can't figure out where the transformation happens and what is passed to grey-matter. Can someone point me in the right direction? This is really annoying. |
It's broken due to bug gatsbyjs/gatsby#4459 — excerpts using the separator are not transformed from Markdown to HTML.
Although not directly related to this issue, the markdown plugin doesn't parse the title or any part of the frontmatter either. |
The docs here say
However neither
|
The issue is at extend-node-type.js, line The problem is that it doesn't do anything with node.excerpt. So that just passes through the whole process. And, at line To fix this, we'd have to either add the excerpt to the cache (as its own entry, or by storing a pair of ASTs), or just assume that the excerpt will only really be parsed once and do it directly. I assume we still want to keep the async processing and all the plugins, so it seems to make sense to me to change the cached value to be a pair of ASTs, with two separate promise chains to generate them. Extracting a function that applies all the plugins, then does the remark processing, then applies all the plugins again, would make it easier to re-use the entire functionality to do both parts - especially as this is all async. I don't know this code at all, so would prefer to leave changing it to someone who knows better. Hope this helps unblock the bug - I really want it fixed! |
I just submitted PR #5586 with a possible fix for this. It implements my above-mentioned plan. However, I am not a committer, so am not sure if it works. |
I could use some help from someone who knows the code better. It seems like my change has somehow altered the type of node.excerpt (even though I didn't change its declared type from string). I have no idea where and how the schema expectations are set. I also don't know whether it is a good thing for the excerpt to now have HTML in it, or to create a new node.excerptFormatted which does. Please help! |
This is still a problem. Any chance of this PR getting merged, or can anyone share a workaround? |
@strubell, here's a workaround I've been using: node.html.split("<!--more-->")[0] 🙈 |
That works for simple things. But if you have things like anchor links in your post the URL needs to be the slug + the link of the markdown. I guess one could massage the links in the freshly split HTML but that seems nasty. |
Hey, any updates on this? I just stumbled upon this issue as well. |
This is the beginnings of a fix for #4459 Right now, the fix works when excerpt_separator is provided. I have not yet implemented a fix for when the excerpt is generated using the `pruneLength` setting, though I have thoughts on how to solve it. My plan to is do a pre-order traversal over the html AST, accumulating nodes until the pruneLength is reached. I would love some preliminary feedback to get a sense of how the contributors feel about this PR so far. Here are some of my initial thoughts: 1. The work in the `excerpt` resolve function is a little hacky. We are directly invoking a variety of functions get our HTML. I'm curious if anyone has a more streamlined approach for this. 2. We are invoking `getMarkdownAST` (previously getAST) twice, once for the excerpt and once for the entire page. I'm worried that this is going to break non-idempotent existing plugins since they will now run twice. 3. I tore apart the `getAST` function a bit and think I did a good job simplifying it. The big change is that we don't generate multiple promises anymore. i think this goes a long way towards improving readability. I'd love to hear people's thoughts.
Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open! |
not stale |
This is the beginnings of a fix for gatsbyjs#4459 Right now, the fix works when excerpt_separator is provided. I have not yet implemented a fix for when the excerpt is generated using the `pruneLength` setting, though I have thoughts on how to solve it. My plan to is do a pre-order traversal over the html AST, accumulating nodes until the pruneLength is reached. I would love some preliminary feedback to get a sense of how the contributors feel about this PR so far. Here are some of my initial thoughts: 1. The work in the `excerpt` resolve function is a little hacky. We are directly invoking a variety of functions get our HTML. I'm curious if anyone has a more streamlined approach for this. 2. We are invoking `getMarkdownAST` (previously getAST) twice, once for the excerpt and once for the entire page. I'm worried that this is going to break non-idempotent existing plugins since they will now run twice. 3. I tore apart the `getAST` function a bit and think I did a good job simplifying it. The big change is that we don't generate multiple promises anymore. i think this goes a long way towards improving readability. I'd love to hear people's thoughts.
+1 Not stale. |
Hello, any updates on this. |
Yeah! So - we added an HTML addition to the excerpt functionality relatively recently. Using this HTML excerpt functionality will transform the excerpt from plain text to HTML, if there's HTML to be transformed. For example, in the above example, the excerpt would translate italics/bold/etc. into their corresponding HTML tags. It can be used like so: {
# grab your markdownRemark node however you prefer
markdownRemark(id: "123412341234") {
excerpt(format: HTML)
}
} This still works with the excerpt_seperator functionality. Here's an example repo demonstrating this functionality Here's the Markdown file showing the separator Going to close this as answered, but please feel free to reply if we can help further. Thanks all! |
@DSchau any suggestions for if we just want the text of the excerpt as per the default |
@DSchau this still doesn't work with format:PLAIN with custom separator. I cloned [your example](Here's an example repo demonstrating this functionality) and changed format from HTML to plain in BlogIndex:
Textual excerpts don't show properly: Am I doing something wrong? |
@markvital what would you expect to happen there? That is plain text. Would you expect Markdown specific stuff to be stripped? |
@DSchau awesome, I just stumbled on this problem and I'm glad I don't have to work around it! One problem though: if I set my excerpts to |
I don't think the original issue is solved by Like @markvital mentioned, if I don't specify Both behaviours should be consistent, preferably the former, I think. |
Since this issue has been closed, do we need another issue? FYI: This is an example unit test to see how it works differently with
|
FYI: I have created a PR to fix this behavior #14723 |
I am using gatsby-transformer-remark with the following configuraton:
According to this post https://using-remark.gatsbyjs.org/excerpts/ I am querying excerpts from my articles like this:
My article in markdown uses a separater defined in config above:
However, the excerpt I am getting is plain text and not transformed from markdown:
Is this intended behavior? How can I get excerpt which is already formatted? Thank you.
Node: v9.5.0
NPM: 5.6.0
The text was updated successfully, but these errors were encountered: