igorskyflyer / npm-astro-post-excerpt

⭐ An Astro component that renders post excerpts for your Astro blog - directly from your Markdown and MDX files! 💎 Featured on Astro's official Integrations library: https://astro.build/integrations?search=igor.dvlpr 😍
https://www.npmjs.com/package/@igor.dvlpr/astro-post-excerpt
MIT License
22 stars 2 forks source link

Markdown syntax still being rendered #41

Closed djmtype closed 4 months ago

djmtype commented 9 months ago

First, thanks for a must needed Astro integration.

I came across an issue in both .mdx and .md files.

The text I get back still has markdown formatting applied to it, at least where italics (*text* or _text_) and bold (**text**) text are concerned. I tried all 3 options for PropRenderer, and they all yielded the same result.

Using Astro 4.2.4.

<PostExcerpt post={post} words={20} addEllipsis={true} headings={PropHeadings.TextOnly} renderer={PropRenderer.Html} />

Example return:

Lorem ipsum dolor **sit amet**, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ![fpo](../../assets/uploads/blog-placeholder-1.jpg) Adipiscing enim…

djmtype commented 9 months ago

BTW, in regards to choosing the plain text render, it would probably be ideal to remove images too.

BTW, it might be worth checking out how Astroplate handles the markdown body in order to return plain text. It uses the help of marked to parse the content, among other rules.

https://github.com/zeon-studio/astroplate/blob/main/src/lib/utils/textConverter.ts#L35

igorskyflyer commented 9 months ago

@djmtype, thanks for taking your time to create the issue and providing a possible fix for it. Indeed, everything except headings is left intact because the component's behavior is inspired by a very common Markdown authoring style, i.e.:


### Some heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id elementum nunc. Morbi pharetra, sem interdum suscipit tristique, tellus mi sodales erat, id consectetur sem odio eget eros.

Aenean non laoreet quam, eget semper nisl. Suspendisse potenti. Aenean in convallis odio, id mollis neque. Vestibulum dictum, massa fringilla consectetur posuere, risus mi bibendum metus, id elementum massa libero in dolor. Phasellus mattis, nunc eu sollicitudin hendrerit, nisl eros bibendum enim, sed ultrices risus lacus vitae diam.

Nam sapien mauris, pretium nec eros et, mattis fermentum est.

### Some other heading

Etc.


Which in turn means anything else well stay as-is. Also *.mdx are quite more complex and difficult to strip of Markdown/JS code.

Either way, I can see the feature to strip all formatting as well being useful/needed and will be something I'll implement in the near future, quite possibly in the next release.

If you have any additional issues/comments feel free to post them. :)

igorskyflyer commented 4 months ago

I am happy to inform you that this issue (should) now be resolved, with the latest v3 version that was released a few minutes ago (https://github.com/igorskyflyer/npm-astro-post-excerpt/commit/93b32491e38ff214e377748b6fc4ec65c914e7ad). 😀

If there are still issues please re-open this issue or create a new one if it's unrelated to this one.