Skip to content

Commit

Permalink
This commit fixes markdown Sanitation as well as resolves some of the…
Browse files Browse the repository at this point in the history
… issues brought to me by nate.
  • Loading branch information
Adammatthiesen committed Feb 22, 2024
1 parent 0c3f0e6 commit 903053f
Show file tree
Hide file tree
Showing 31 changed files with 322 additions and 493 deletions.
30 changes: 16 additions & 14 deletions .changeset/shiny-dingos-remember.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
---
"astro-remote": major
"astro-remote": minor
---

This Update will bring all Dependencies to current versions as well as resolve some typing issues with new versions

Breaking:
- Markdown sanitation has been disabled due to complete removal of all custom data (Hope to resolve soon, but the current workaround is functioning)
New:
- Now Support Marked Extensions using the following example:
```tsx
---
import markedAlert from 'marked-alert'
const readme = await fetch("https://raw.githubusercontent.com/natemoo-re/astro-remote/main/packages/astro-remote/README.md").then((res) => res.text());
---
<Markdown sanitize={{ allowComponents: true }}
content={readme}
components={{ Heading, CodeBlock, CodeSpan, Note }}
marked={{extensions: [markedAlert()]}} />
```


Commit history:
Breaking:
- Node Engine Minimum required version: v18.14.1 this reflects Astro's Minimum requirements. (https://docs.astro.build/en/tutorial/1-setup/1/#nodejs)

- Initial Prep: Repo organization and Prepare for upgrade
- More Cleanup: Code Cleanup before I started Upgrading
- Some Progress: First Commit to include upgrade progress, mostly upgrading of Deps before any testing and fixing
- Code Cleanup: Initial cleanup of code errors
- Working Tests: Time to work out bugs and get things working
- Test Cleanup: Tests are working and most previous features have been fixed.
- More Cleanup: remove all deps used for testing different results and their code
- Fix Inital Type Errors left behind and lint!
- Readme update: updated readme now that all the errors are gone.
- small fix to Utils file
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"pnpm": "8.15.3"
},
"engines": {
"node": ">=18.19.0"
"node": ">=18.14.1"
},
"packageManager": "[email protected]",
"dependencies": {
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions package/README.md → packages/astro-remote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,19 @@ const content = await fetch('http://my-site.com/api/v1/post').then(res => res.te
<Markdown content={content} sanitize={{ allowComponents: true }} components={{ MyCustomComponent }} />
```

### Using Marked Extensions

If you'd like to use custom Marked Extensions it is now as easy as doing the following:

```astro
---
import { Markdown } from 'astro-remote';
import MyCustomComponent from '../components/MyCustomComponent.astro';
import markedAlert from 'marked-alert'
const content = await fetch('http://my-site.com/api/v1/post').then(res => res.text());
---
<Markdown content={content} sanitize={{ allowComponents: true }} components={{ MyCustomComponent }} marked={{ extensions: [ markedAlert() ] }} />
```
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export interface Props {
content?: string;
sanitize?: SanitizeOptions;
components?: Record<string, any>;
markedExt?: MarkedExtension[]
marked?: {
extensions?: MarkedExtension[]
}
}
const input = Astro.props.content ?? await Astro.slots.render('default');
Expand All @@ -16,7 +18,7 @@ if (!input) {
}
// @ts-ignore
const components = createComponentProxy($$result, Astro.props.components);
const content = await markdown(input, { components }, Astro.props.markedExt);
const content = await markdown(input, { sanitize: Astro.props.sanitize, components }, Astro.props.marked?.extensions);
---

<Fragment set:html={content} />
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function markdown(
const content = await marked.parse(dedent(input));
return transform(content, [
swap(opts.components),
//sanitize(opts.sanitize) //- this was causing issues with Markdown output disabled for now.
sanitize(opts.sanitize),
]);
}

Expand Down
5 changes: 2 additions & 3 deletions package/package.json → packages/astro-remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"files": [
"lib",
"index.ts",
"CHANGELOG.md",
"tsconfig.json"
"CHANGELOG.md"
],
"types": "./index.ts",
"exports": {
Expand All @@ -41,7 +40,7 @@
"pnpm": "8.14.1"
},
"engines": {
"node": ">=18.19.0"
"node": ">=18.14.1"
},
"dependencies": {
"entities": "^4.5.0",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion playground/package.json → packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"astro": "astro"
},
"volta": {
"extends": "../package.json"
"extends": "../../package.json"
},
"devDependencies": {
"astro-remote": "workspace:*"
},
"dependencies": {
"astro": "^4.4.0",
"@astrojs/check": "^0.5.4",
"marked-alert": "2.0.1",
"typescript": "^5.3.3"
}
}
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import CodeSpan from "../components/CodeSpan.astro";
import CodeBlock from "../components/CodeBlock.astro";
import Heading from "../components/Heading.astro";
import Note from "../components/Note.astro";
import markedAlert from 'marked-alert'
const readme = `
# Hello \`world\`
> [!NOTE]
> This is just a test
> **Note**
> Some note
Expand Down Expand Up @@ -41,10 +45,10 @@ const readme = `
<div class="markdown">
<h1>Test: Markdown-Internal(MD Parse and write)</h1>
<p>Test Generated from: "Internal Defined Markdown"</p>
<Markdown
content={readme}
<Markdown sanitize={{ allowComponents: true }}
content={readme}
components={{ Heading, CodeBlock, CodeSpan, Note }}
/>
marked={{extensions: [markedAlert()]}} />
</div>

</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CodeSpan from "../components/CodeSpan.astro";
import CodeBlock from "../components/CodeBlock.astro";
import Heading from "../components/Heading.astro";
import Note from "../components/Note.astro";
import markedAlert from 'marked-alert'
const readme = await fetch("https://raw.githubusercontent.com/natemoo-re/astro-remote/main/packages/astro-remote/README.md").then((res) => res.text());
---
Expand All @@ -18,9 +19,10 @@ const readme = await fetch("https://raw.githubusercontent.com/natemoo-re/astro-r
<div class="markdown">
<h1>Test: Markdown-External(MD Parse and write)</h1>
<p>Test Generated from: "https://raw.githubusercontent.com/natemoo-re/astro-remote/main/packages/astro-remote/README.md"</p>
<Markdown
content={readme}
<Markdown sanitize={{ allowComponents: true }}
content={readme}
components={{ Heading, CodeBlock, CodeSpan, Note }}
marked={{extensions: [markedAlert()]}}
/>
</div>
</body>
Expand Down
File renamed without changes.
Loading

0 comments on commit 903053f

Please sign in to comment.