Replies: 3 comments 15 replies
-
Howdy @reypm 🤠
What suggestion? There is none in that issue.
The Some solutions would include either of @wooorm's solutions in https://github.com/orgs/syntax-tree/discussions/104#discussioncomment-6471016 |
Beta Was this translation helpful? Give feedback.
-
@wooorm After fix the errors I was having before now I am getting a lot of errors (they are too long so I have attached them here). what has changed? Besides now I am using the suggested code a few more things: const ReactMarkDown = async ({ content, metaData }: { content: any, metaData: MetaDataModel }) => { } I need it to change this to const transformedTree = await processor.run(parseTree) // transformed hast tree. instead of return the return (
{reactNode}
) But something is not ok since everything is failing and the page does not render, any thoughts? |
Beta Was this translation helpful? Give feedback.
-
hey guys, I did manage to get things partially working, here are the new changes: const ReactMarkDown = ({ content, metaData }: { content: any, metaData: MetaDataModel }) => {
// temporary fix till AEM addresses these characters
const data = content
?.replaceAll('<', '<')
?.replaceAll('>', '>')
?.replaceAll(' ', ' ')
function rehypeRenderDirective() {
return (tree: HastRoot) =>
visit(tree, { type: 'element', tagName: 'container-directive' }, (node) => {
node.tagName = 'div'
// @ts-ignore
if (node.properties.type === 'page-include') {
processPageInclude(node).then((result) => {
node.children = result.children
// ===> this output nothing, why? is because this is never being call?
console.log('node', node)
})
}
})
}
const processor = unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkFrontmatter, ['toml', 'yaml'])
.use(remarkBreaks)
.use(remarkMermaid)
.use(remarkDirective)
.use(shortcodePlugin)
.use(remarkDirectiveCustomize, [metaData?.id])
.use(rehypeExternalLinks)
.use(rehypeSlug)
.use(rehypeRenderDirective)
const parseTree = processor.parse(toHast(fromMarkdown(data))) // mdast input tree
const [transformedTree, setTransformedTree] = useState('')
useEffect(() => {
const getTransformedTree = async () => {
return await processor.run(parseTree) // transformed hast tree.
}
getTransformedTree().then((data) => {
setTransformedTree(data)
})
}, [])
// => this output hast, but it does not contain the content coming from page-include because apparently it never gets call
console.log(transformedTree)
const reactNode = toJsxRuntime(transformedTree, { Fragment, jsx, jsxs, components: {} })
return (<></>)
}
export default ReactMarkDown I added some comments inline, thoughts? what could I be missing here? also if I try to render
Note: I'm not justifying myself but apologies for this long back and forth, I am still learning React and I am coming from PHP |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I will take this comment borrow from here:
And I am trying to follow this suggestion (taken from the same answer):
This is my solution (I have removed non-relevant code):
and this is how I am using this custom async plugin:
this is what
console.log(node)
prints out to the console:still I am not seeing any kind of content when the page render and no errors on the console. What else I am missing here?
Beta Was this translation helpful? Give feedback.
All reactions