Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjosephprice committed May 23, 2024
1 parent 1087523 commit 7d15b0c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 67 deletions.
12 changes: 5 additions & 7 deletions example/Doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ const Doc = () => {
render();
}, [doc, lazyImages, safeMode]);

console.log(Content, Toc);

return (
<div className="rdmd-demo--display">
<section id="hub-content">
Expand All @@ -65,13 +63,13 @@ const Doc = () => {
<RenderError error={error}>
<div className="markdown-body">{Content && <Content />}</div>
</RenderError>
{Toc && (
<div className="content-toc">
<Toc />
</div>
)}
</div>
</section>
{Toc && (
<section className="content-toc">
<Toc />
</section>
)}
</div>
);
};
Expand Down
10 changes: 6 additions & 4 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import remarkMdx from 'remark-mdx';
import remarkFrontmatter from 'remark-frontmatter';
import remarkRehype from 'remark-rehype';
import remarkGfm from 'remark-gfm';
import remarkSlug from 'remark-slug';
import rehypeSlug from 'rehype-slug';
import { VFile } from 'vfile';

import { createProcessor, compileSync, run as mdxRun, RunOptions } from '@mdx-js/mdx';
Expand All @@ -18,10 +18,9 @@ import { GlossaryContext } from './components/GlossaryItem';
import BaseUrlContext from './contexts/BaseUrl';
import { options } from './options';

import transformers, { readmeComponentsTransformer, remarkToc } from './processor/transform';
import transformers, { readmeComponentsTransformer, rehypeToc } from './processor/transform';
import compilers from './processor/compile';
import MdxSyntaxError from './errors/mdx-syntax-error';
import { MDXContent } from 'mdx/types';

const unimplemented = debug('mdx:unimplemented');

Expand Down Expand Up @@ -69,7 +68,8 @@ const makeUseMDXComponents = (more: RunOpts['components']): (() => ComponentOpts
return () => components;
};

const remarkPlugins = [remarkFrontmatter, remarkGfm, remarkSlug, remarkToc, ...transformers];
const remarkPlugins = [remarkFrontmatter, remarkGfm, ...transformers];
const rehypePlugins = [rehypeSlug, rehypeToc];

export const reactProcessor = (opts = {}) => {
return createProcessor({ remarkPlugins, ...opts });
Expand All @@ -82,6 +82,7 @@ export const compile = (text: string, opts = {}) => {
outputFormat: 'function-body',
providerImportSource: '#',
remarkPlugins,
rehypePlugins,
...opts,
});
} catch (error) {
Expand All @@ -90,6 +91,7 @@ export const compile = (text: string, opts = {}) => {
};

const vfile = exec(text);
console.log(vfile.data.toc);
if (vfile.data.toc) {
const toc = mdx(vfile.data.toc);
vfile.data.toc = toc ? exec(toc) : null;
Expand Down
76 changes: 47 additions & 29 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"lodash.escape": "^4.0.1",
"lodash.kebabcase": "^4.1.1",
"mdast-util-find-and-replace": "^3.0.1",
"mdast-util-toc": "^7.0.1",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"prop-types": "^15.8.1",
"rehype-slug": "^6.0.0",
"remark": "^15.0.1",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
Expand Down Expand Up @@ -80,6 +80,7 @@
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14",
"@testing-library/user-event": "^14.5.2",
"@types/hast": "^3.0.4",
"@types/jest": "^29.5.12",
"@types/mdast": "^4.0.3",
"@types/mdx": "^2.0.12",
Expand Down
4 changes: 2 additions & 2 deletions processor/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import codeTabsTransfromer from './code-tabs';
import embedTransformer from './embeds';
import gemojiTransformer from './gemoji+';
import readmeComponentsTransformer from './readme-components';
import remarkToc from './remark-toc';
import rehypeToc from './rehype-toc';

export { readmeComponentsTransformer, remarkToc };
export { readmeComponentsTransformer, rehypeToc };

export default [calloutTransformer, codeTabsTransfromer, embedTransformer, gemojiTransformer];
24 changes: 0 additions & 24 deletions processor/transform/remark-toc.ts

This file was deleted.

0 comments on commit 7d15b0c

Please sign in to comment.