Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: demo app
  • Loading branch information
kellyjosephprice committed Apr 10, 2024
commit d151b1d512dfb5deea00b4db3ee8b7056b5676fb
13 changes: 7 additions & 6 deletions example/Doc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { Fragment, FunctionComponent, useEffect, useState } from 'react';
import { useParams, useSearchParams } from 'react-router-dom';
import * as mdx from '../index';
import docs from './docs';
Expand All @@ -14,7 +14,7 @@ const Doc = () => {
const [name, doc] =
fixture === 'edited' ? [fixture, searchParams.get('edit') || ''] : [docs[fixture].name, docs[fixture].doc];

const [Content, setContent] = useState(null);
const [Content, setContent] = useState<FunctionComponent>(null);

useEffect(() => {
const render = async () => {
Expand All @@ -23,7 +23,10 @@ const Doc = () => {
safeMode,
};

setContent(await mdx.run(String(mdx.compile(doc, opts))));
const code = mdx.compile(doc, opts);
const content = await mdx.run(code);

setContent(() => content);
};
render();
}, [doc, lazyImages, safeMode]);
Expand All @@ -35,9 +38,7 @@ const Doc = () => {
{!ci && <h2 className="rdmd-demo--markdown-header">{name}</h2>}
<div id="content-container">
<RenderError>
<div className="markdown-body">
<Content />
</div>
<div className="markdown-body">{Content && <Content />}</div>
</RenderError>
</div>
</section>
Expand Down
15 changes: 15 additions & 0 deletions example/docs.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
// @ts-ignore
import calloutTests from '../docs/callout-tests.md';
// @ts-ignore
import callouts from '../docs/callouts.md';
// @ts-ignore
import codeBlockTests from '../docs/code-block-tests.md';
// @ts-ignore
import codeBlocks from '../docs/code-blocks.md';
// @ts-ignore
import embeds from '../docs/embeds.md';
// @ts-ignore
import features from '../docs/features.md';
// @ts-ignore
import gettingStarted from '../docs/getting-started.md';
// @ts-ignore
import headings from '../docs/headings.md';
// @ts-ignore
import images from '../docs/images.md';
// @ts-ignore
import lists from '../docs/lists.md';
// @ts-ignore
import sanitizingTests from '../docs/sanitizing-tests.md';
// @ts-ignore
import tableOfContentsTests from '../docs/table-of-contents-tests.md';
// @ts-ignore
import tablesTests from '../docs/tables-tests.md';
// @ts-ignore
import tables from '../docs/tables.md';
// @ts-ignore
import varsTest from '../docs/variable-tests.md';

const lowerCase = (str: string) =>
Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,10 @@ module.exports = {
},
},
},
{
test: /\.(txt|md)$/i,
type: 'asset/source',
},
],
},
resolve: {
extensions: ['.js', '.json', '.jsx', '.ts', '.tsx'],
extensions: ['.js', '.json', '.jsx', '.ts', '.tsx', '.md'],
fallback: { buffer: require.resolve('buffer') },
},
};
11 changes: 8 additions & 3 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ const config = merge(common, {
port: 9966,
hot: true,
},
module: {
rules: [
{
test: /\.(txt|md)$/i,
type: 'asset/source',
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
},
fallback: {
fs: require.resolve('browserify-fs'),
path: require.resolve('path-browserify'),
Expand Down