Skip to content

Commit

Permalink
Merge pull request #18 from thefrontside/tm/allow-markdown-in-readme
Browse files Browse the repository at this point in the history
Rendering markdown in readme
  • Loading branch information
taras authored Oct 6, 2024
2 parents 949d5b2 + b2dbb8f commit 48b5bf3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tinyexec/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { x } from "./tinyexec.ts";
export * from "./tinyexec.ts";
10 changes: 4 additions & 6 deletions www/components/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Punctuation,
} from "./tokens.tsx";
import { useMDX } from "../hooks/use-mdx.tsx";
import { useMarkdown } from "../hooks/use-markdown.tsx";

interface DescriptionProps {
pkg: Package;
Expand Down Expand Up @@ -147,12 +148,9 @@ function* TSInterfaceDef(
): Operation<JSXElement> {
const elements: JSXElement[] = [];
for (const property of interfaceDef.properties) {
const jsDoc = yield* call(function* (): Operation<JSXElement | undefined> {
if (property.jsDoc?.doc) {
const mod = yield* useMDX(property.jsDoc?.doc);
return mod.default();
}
});
const jsDoc = property.jsDoc?.doc
? yield* useMarkdown(property.jsDoc?.doc)
: undefined;
elements.push(
<li class={`${jsDoc ? "my-0 border-l-2 first:-mt-5" : "my-1"}`}>
{jsDoc
Expand Down
10 changes: 10 additions & 0 deletions www/hooks/use-markdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { call, type Operation } from "effection";
import type { JSXElement } from "revolution/jsx-runtime";
import { useMDX } from "./use-mdx.tsx";

export function* useMarkdown(markdown: string): Operation<JSXElement> {
return yield* call(function* (): Operation<JSXElement> {
const mod = yield* useMDX(markdown);
return mod.default();
});
}
10 changes: 5 additions & 5 deletions www/routes/package.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { RoutePath, SitemapRoute } from "effection-www/plugins/sitemap.ts";
import { usePackages } from "../hooks/use-packages.ts";
import { Exports } from "../components/exports.tsx";
import { API } from "../components/api.tsx";
import { useMarkdown } from "../hooks/use-markdown.tsx";

export function packageRoute(): SitemapRoute<JSXElement> {
return {
Expand Down Expand Up @@ -54,13 +55,12 @@ export function packageRoute(): SitemapRoute<JSXElement> {
<AppHTML>
<article class="prose">
<header>
<h1>{pkg.packageName}</h1>
<p>
<pkg.MDXDescription />
</p>
<>
{yield* useMarkdown(pkg.readme)}
</>
</header>
<Exports pkg={pkg} />
<h2 class="mb-0">Documentation</h2>
<h2 class="mb-0">API</h2>
{yield* API({ pkg })}
</article>
</AppHTML>
Expand Down

0 comments on commit 48b5bf3

Please sign in to comment.