-
Notifications
You must be signed in to change notification settings - Fork 0
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
feature: HTML to Markdown (component & routes) #235
Open
jbmoelker
wants to merge
7
commits into
main
Choose a base branch
from
feat/page-to-markdown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8388967
feat: page as markdown (PoC)
jbmoelker d132354
feat: use html sub selection before markdown
jbmoelker 51c4909
feat: serve markdown with charset utf-8
jbmoelker bc73b78
fix: rename .md/index.html to .md files
jbmoelker 76ac2bb
fix: md path for seo tag & _headers
jbmoelker 10cc2e9
docs: decision log entry for ToMarkdown component
jbmoelker 9d43842
feat(ToMarkdown): Github Flavored Markdown and table support
jbmoelker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||
# Render to Markdown | ||||||
|
||||||
**Use `Astro.slots.render` to transform HTML content to Markdown both during build- and run-time.** | ||||||
|
||||||
- Date: 2024-12-27 | ||||||
- Alternatives Considered: `AstroContainer.renderToString`, to Markdown per block, post build script to transform HTML to Markdown. | ||||||
- Decision Made By: [Jasper](https://github.com/jbmoelker) | ||||||
|
||||||
## Decision | ||||||
|
||||||
Making our HTML pages available as Markdown is of interest to some people and especially suitable for software such as LLM's. Using `Astro.slots.render` seems to be the only solution that works both during build- and run-time. | ||||||
|
||||||
### Solution | ||||||
|
||||||
A componanion `.md.astro` route with a `ToMarkdown` component that leverages `Astro.slots.render` to get a usable HTML string, which can be used to transform to Markdown (and other formats): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```astro | ||||||
--- | ||||||
const html = Astro.slots.render('default'); | ||||||
const md = /* transform html to md any way you want */ | ||||||
--- | ||||||
<Fragment set:text={md} /> | ||||||
``` | ||||||
|
||||||
### Alternatives considerd | ||||||
|
||||||
These alternatives were explored and rejected: | ||||||
|
||||||
- Using `AstroContainer.renderToString` in a `.ts` route rather than a `.astro` route would give direct access to the HTML string. However this method currently relies on `node:path` which is not available in the Cloudflare runtime. | ||||||
- Using alternative render methods in each block that return a Markdown instead of an HTML output. This requires extra work for every existing and new component and is hard to keep in sync. This option is rejected because of the extra complexity. | ||||||
- Using a post build script with the same transformers used in the `ToMarkdown` component or other libraries relying on the Node.js runtime. This works only for pages statically generated during build. It's unsuitable for dynamically rendered pages and is therefore rejected. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.