-
-
Notifications
You must be signed in to change notification settings - Fork 893
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
Plugins are not working #188
Comments
Can't get |
So, turned out this version support only parser plugins. Basically, if you take a look at this diagram only first stage (namely, Probably, it could be fixed by just running For me the workaround that did the job was to use import linker from '../src/Documentation/remark-linker'
...
astPlugins={[linker()]} Note, that function call is made to actually get the transformer from the plugin description. I'm not sure this is 100% compatible with all the plugins. In my case I wrote the plugin I needed for the dvc documentation site: function linker() {
function transformer(tree) {
visit(tree, 'inlineCode', function(node, index, parent) {
if (parent.type !== 'link' && /dvc [a-z-.]+/.test(node.value)) {
parent.children[index] = {
type: 'link',
url: 'https://dvc.org/doc/commands-reference/' + node.value.split(' ')[1],
children: [node],
position: node.position
};
}
})
return tree
}
return transformer
} |
react-markdown doesn't support transformer plugins (remarkjs/react-markdown#188), so we can't use remark-ping with it. My hand-coded @tag plugin was buggy--better to use remark-ping
@rexxars Any thoughts on a solution or workaround for this? @shcheklein 's analysis is correct--transformer plugins do not work with react-markdown. I ran into this while trying to integrate remark-ping for @mention syntax. It doesn't work with react-markdown, so I ended up using remark/rehype directly. // render-markdown.js
import remark from "remark";
import remarkPing from "remark-ping";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import rehypeHighlight from "rehype-highlight";
export default function renderMarkdown(source) {
const plugins = [
[
remarkPing,
{
//..config...
},
],
remarkRehype,
rehypeStringify,
rehypeHighlight
];
const remarkInst = remark().use(plugins);
return new Promise((resolve, reject) => {
remarkInst.process(source, (err, rendered) => {
err ? reject(err) : resolve(rendered.contents);
});
});
} // Markdown.jsx
import React from "react";
import t from "prop-types";
import renderMarkdown from "./render-markdown";
export default class Markdown extends React.Component {
constructor(props) {
super(props);
this.state = {
rendered: ""
};
}
componentDidMount() {
const { source } = this.props;
renderMarkdown(source).then(rendered => {
this.setState({ rendered });
});
}
render() {
const { source, ...rest } = this.props;
return (
<div
dangerouslySetInnerHTML={{ __html: this.state.rendered }}
{...rest}
/>
);
}
}
Markdown.propTypes = {
source: t.string.isRequired
}; This really isn't ideal, if only for the impact on bundle size (rehype-highlight alone ends up adding 190 kb to the min/gzip bundle). |
The bundle size issue is the reason why I wanted to not include the full remark suite. If we are able to come up with a solution without adding too many bytes to the mix, that would be great. I unfortunately don't have time to dig into this right now, but would be very happy if someone else were to take a stab at it. |
I needed to run a plugin for my react project so I dug into this issue a bit. @shcheklein was on the right track. I added the |
Did anyone manage to get |
I’m also having trouble getting Repro: https://codesandbox.io/s/silly-cherry-bznd3?file=/src/index.js Note that the pre-rendered output properly includes both Repro code, for posterityimport React from "react"; // v16.13.1
import {render} from "react-dom"; // v16.13.1
import ReactMarkdown from "react-markdown"; // v4.3.1
import remark from "remark"; // v12.0.0
import externalLinks from "remark-external-links"; // v6.1.0
import html from "remark-html"; // v11.0.2
const input = "Here is [an example link](https://example.com).";
async function main() {
const rendered = await new Promise((resolve, reject) => {
remark()
.use(externalLinks)
.use(html)
.process(input, (err, file) => {
if (err != null) {
reject(err);
}
resolve(file);
});
});
const App = () => (
<div>
<p>Pre-rendered:</p>
<pre>
<code>{rendered}</code>
</pre>
<p>
With <code>ReactMarkdown</code>:
</p>
<ReactMarkdown source={input} plugins={[externalLinks]} />
</div>
);
render(<App />, document.getElementById("root"));
}
main(); Perhaps this issue should be reopened? |
@shcheklein I'm trying to follow your example, I'm pretty new in AST can you point me out from where you are importing the visit(tree, 'inlineCode', function(node, index, parent) { 🙏 |
@nahumzs hi! sure here is the link - https://github.com/iterative/dvc.org/blob/7f88227d131c5fcf8eead8d7d6c62876152fb395/src/Documentation/Markdown/utils/remark-linker.js (we've updated the plugin since then). I'll edit the existing comment. |
Thanks for creating this amazing package! This is a really awesome idea.
I would like to ask for some help with plugins. For some reason the don't do anything.
My code
codesandbox: https://codesandbox.io/s/340pq1r2l6
The output:
The table of contents is not created also slugs are not added to headings.
The text was updated successfully, but these errors were encountered: