-
-
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
enable plugins with transforms #305
enable plugins with transforms #305
Conversation
I noticed that lists were not rendering as expected when I dropped remark-toc in for testing, since it was part of the original issue in #188. The renderer conditions were looking for |
@frankieali Will this also works for plugin like remark-gemoji-to-emoji ? If this is the case I might need your patch 👍 |
@callain Yes, my demo worked fine when I dropped remark-gemoji-to-emoji in. |
@frankieali Cool ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nitpicks, and the sourcePosition
case change was unintentional, I assume?
Will also want to add some tests for the plugin changes.
src/ast-to-react.js
Outdated
if(node.position === undefined) { | ||
visit(root, node, (nodeVisit, indexVisit, parentVisit) => { | ||
// just in case parent does not have position either | ||
const defaultPosition = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since defaultPosition is static, maybe hoist it to the top of the file?
src/ast-to-react.js
Outdated
|
||
function astToReact(node, options, parent = {}, index = 0) { | ||
const renderer = options.renderers[node.type] | ||
|
||
if(node.type === 'root') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but coding style wants a space between the if and the parentheses opening
src/ast-to-react.js
Outdated
@@ -47,7 +67,7 @@ function getNodeProps(node, key, opts, renderer, parent, index) { | |||
} | |||
|
|||
if (opts.rawSourcePos && !isTagRenderer) { | |||
props.sourcePosition = node.position | |||
props.sourceposition = node.position |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this accidental? Why was this changed?
I've made the requested updates. React was complaining once that As far as the tests go, I'm seeing one failure on rawSourcePos, but it seems more like a fix to me since the rawSourcePos snapshot is undefined and now the test is returning a position object.
|
@rexxars Are the changes okay to you ? |
There are still no tests for the new functionality - adding a minor plugin to the test suite to ensure that the transformation step is actually is executed would be nice. I'm not sure if there are good reasons why the nodes without a position needs one - if they do, maybe add a comment as to why, and include some tests to ensure that the position gets assigned as expected?
|
@frankieali Hello, can you take @rexxars feedback in consideration ? |
7070777
to
24caab5
Compare
I've rebased my PR to include the latest in master. I've added some dev comments to the code and added the Table of Contents plugin as a dev-dependency for testing and demo purposes. The reason for the |
Thanks, I'll have a look! |
+1 for implementing this! |
I gave this PR a try with about five different plugins last night and so far it's working fabulously. |
This pull request is working for me to get the gemoji and gemoji-to-emoji plugins working! |
Hello @rexxars , hope you're good :) Can you review/merge this PR ? 😄 |
Status? I would love to see that merged and the requested changes seem very minor. |
Sorry, just moved to another country, been quite hectic. Will take a look at PRs this weekend. |
Thanks so much for this! Released in 4.2.0 |
Allowing remark to execute
parser.runSync()
so that plugin transforms can be applied to the AST tree. Demo here: https://frankieali.github.io/react-markdown/demo/dist/Closes #188