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

Summaries break reference-style Markdown links #376

Closed
Freaky opened this Issue Aug 19, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@Freaky
Contributor

Freaky commented Aug 19, 2018

Because <!-- more --> handling is done on the raw Markdown document, this breaks:

[Foo][foo]
<!-- more -->
[foo]: http://foo.example

The reference gets split off from the content when the summary is rendered, leaving the links rendering literally.

While it's far from a satisfying fix, this works:

--- components/content/src/page.rs
+++ components/content/src/page.rs
@@ -191,13 +191,8 @@ impl Page {
         ).chain_err(|| format!("Failed to render content of {}", self.file.path.display()))?;
         self.content = res.0;
         self.toc = res.1;
-        if self.raw_content.contains("<!-- more -->") {
-            self.summary = Some({
-                let summary = self.raw_content.splitn(2, "<!-- more -->").collect::<Vec<&str>>()[0];
-                render_content(summary, &context)
-                    .chain_err(|| format!("Failed to render content of {}", self.file.path.display()))?.0
-            })
-        }
+        self.summary = self.content.find("<p><a name=\"continue-reading\"></a></p>")
+                                   .map(|pos| self.content[0..pos].to_owned());

         Ok(())
     }

Freaky added a commit to Freaky/gutenberg that referenced this issue Aug 19, 2018

Generate summaries from the full rendered Markdown.
Instead of splitting the raw on <!-- more --> and re-rendering the
summary, split on the rendered continue-reading anchor and reuse that.

This fixes getzola#376, albeit in a somewhat unsatisfying way that depends on
how Markdown is rendered.

Freaky added a commit to Freaky/gutenberg that referenced this issue Aug 19, 2018

Generate summaries from the full rendered Markdown.
Fixes summaries failing to render reference links reported in getzola#376.
@Keats

This comment has been minimized.

Collaborator

Keats commented Aug 22, 2018

What would be a satisfying fix for you? Looking at it, I don't see a much better solution than your patch

Freaky added a commit to Freaky/gutenberg that referenced this issue Aug 22, 2018

Rework summary handling.
Push summary handling into Markdown parsing, identifying the presence
of one by giving its length in the rendered markup.

Hopefully a better fix for getzola#376.
@Freaky

This comment has been minimized.

Contributor

Freaky commented Aug 22, 2018

Pushing it into rendering seems more appropriate, seeing as it's basically all about how raw content is parsed and depends on how it's rendered.

@Freaky

This comment has been minimized.

Contributor

Freaky commented Aug 22, 2018

As an aside, most of the Owned() bits in the Markdown parser should really be Borrowed(). e.g. Owned(String::new())Borrowed("").

Freaky added a commit to Freaky/gutenberg that referenced this issue Aug 24, 2018

@Keats Keats added the done label Aug 25, 2018

@Keats Keats closed this Sep 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment