Skip to content
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

Allow to use custom unified visitors. #8

Open
aexol opened this issue Oct 21, 2022 · 1 comment
Open

Allow to use custom unified visitors. #8

aexol opened this issue Oct 21, 2022 · 1 comment
Assignees

Comments

@aexol
Copy link
Contributor

aexol commented Oct 21, 2022

https://github.com/aexol-studio/mdtx/blob/main/packages/mdtx-core/src/transformers/markdown.ts
In this file and in the nextJS plugin we should have a possibility to insert our own unified plugins.

 const processedContent = await unified()
    .use(remarkParse)
    .use(remarkDirective)
    .use(() => {
      return (tree, file) => {
        visit(tree, 'containerDirective', (node) => {
          const data = node.data || (node.data = {});
          const hast = h(node.name, node.attributes);
          data.hName = hast.tagName;
          data.hProperties = hast.properties;
        });
        visit(tree, 'html', (node) => {
          if (node.value.includes('src="')) {
            node.value = node.value.replace(
              /src\=\".*\.gitbook/,
              'src="/.gitbook',
            );
            // tree.children.push({ type: '' });
          }
        });
        visit(tree, 'paragraph', (node) => {
          const image = node.children.find((child) => child.type === 'image');
          if (image && image.type === 'image') {
            const fileName = image.url.replace(/^.*\.gitbook/, '/.gitbook');
            image.url = fileName;
          }
        });
      };
    })
    .use(remarkRehype, { allowDangerousHtml: true })
    .use(rehypeRaw)
    .use(rehypeHighlight)
    .use(rehypeStringify)
    .process(replaceCustomTags);
@aexol
Copy link
Contributor Author

aexol commented Oct 21, 2022

We should add a possibility to provide array of unified plugins 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants