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

Return html when render markdown content #6097

Closed
wants to merge 5 commits into from
Closed

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Feb 2, 2023

Changes

When render() a markdown file (not MDX), return the html too.

Implements this feature for better RSS composing experience.

Testing

Added new tests to make sure it renders

Docs

@bluwy bluwy requested a review from bholmesdev February 2, 2023 09:45
@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2023

🦋 Changeset detected

Latest commit: 845f308

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release labels Feb 2, 2023
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@bholmesdev
Copy link
Contributor

Thanks @bluwy! Yes, apologies for not detailing a use case on the ticket. The primary utility is RSS feeds, where you may want to the html content for each RSS feed item. This also brings content collections in-line with the compiledContent() helper present on Markdown imports today.

As for docs updates, I'd expect to:

  1. Update the RSS docs to suggest html over manual Markdown parsing (I'll take this one!)
  2. Update render() API reference to include html

I'd leave the Content Collections guide page alone looking at what it includes today. We can always update later if support tickets prove anything is unclear.

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good! Just nits on the changeset and about a potential unit test

@bluwy
Copy link
Member Author

bluwy commented Feb 2, 2023

Makes sense! Thanks for the explanation. I'll update the docs later for no2, and set up the unit test.

@delucis
Copy link
Member

delucis commented Feb 2, 2023

Is there any concern about introducing this API before we can offer something similar for MDX? Is the intention that we might one day figure this out for MDX too? Render components but exclude scripts & styles?

github-actions[bot]

This comment was marked as duplicate.

github-actions[bot]

This comment was marked as duplicate.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@bluwy
Copy link
Member Author

bluwy commented Feb 3, 2023

After further discussion with the maintainers, we decided to close this for now until we have a proper way to expose html for MDX files too. This avoids confusion when a user switches .md to .mdx that a property is missing. Closing the docs PR too.

@bluwy bluwy closed this Feb 3, 2023
@bluwy bluwy deleted the markdown-content-html branch February 3, 2023 09:25
@oliverpool
Copy link
Contributor

oliverpool commented Mar 1, 2023

I would really like to have this feature for my RSS feed (I don't use mdx at all).

Wouldn't it be reasonable to make html a function (renderResult.html = mod.compiledContent in case of .md) which throws a (nice) error in case of mdx? (maybe pointing to some issue here about proper way to expose html for MDX files).

For now I have to use import.meta.glob on the feed page (which return different objects than getCollection and without proper type)

Edit: having to introduce another dependency for markdown rendering as recommended by the docs feels wrong (since a markdown renderer is already used internally)

@OverflowCat
Copy link

So why isn't compiledContent() present in MDX? I have extensively used MDX and components in my blog, but most of the pages are static. Only a few pages contain <script> tags.

@bholmesdev
Copy link
Contributor

@OverflowCat In short, because MDX needs to be "executed" as Astro components, and we need an API to safely render Astro components to strings of HTML. This is being tracked here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants