-
-
Notifications
You must be signed in to change notification settings - Fork 174
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
CodeBlock issues #267
Comments
I am also running into this issue. I am not able to render a custom component for javascript vs python vs unspecified codeblocks. |
You can change
But I don't know what else will happen. |
I'm also having the issue whereby a For example, if using a tab system and the following:
If the
instead of this:
The current workaround I've found is to use a class with |
Same here. But I am rendering this markdown element on text area change, and it does not render code block properly. |
Is this going to be fixed? This is quite a big issue for those that want to have custom code blocks. |
One workaround is to create your code block with a highlighter of your choice (I used prismjs) and add it to the overrides as a custom component. I did this and it a allowed me to have a custom code blocks and an inline code that work nicely together. Within markdown, All I had to do was call the codeblock like this Implementation below: import React from 'react';
import Markdown from 'markdown-to-jsx';
import { CodeBlock, InlineCode } from 'dir/to/your/component';
//Test string
const testMD = (`
#Title
This is some inline \`code\` to view.
<MyCodeBlock language="javascript">
const x = "myCodeBlock";
</MyCodeBlock
`);
<Markdown
children={testMD} //Or other prop
options={{
overrides: {
code: InlineCode
MyCodeBlock: CodeBlock,
}
}}
/> |
Bump on this issue — markdown still renders CodeBlock content for inline code elements |
What about propagating the code type as a props ? It could be used with something (not tested :)) like that : <Markdown
children={...}
options={{
overrides: {
code: CustomCode
}
}}
/>
const CustomCode = (props: CustomCodeProps): React.ReactElement => {
const { children, type } ⁼ props;
// handle inline block
if (type == 'inline') {
return <span>{children}</span>
}
// Handle block code, with highlight for example
};
CustomCode.defaultProps = {
type: 'block',
};
export type CodeProps = {
children: ReactNode;
type?: string;
}; I think it could be implemented with something like that, but I'm not accommodated with the lib code so it's probably not enough : diff --git a/index.tsx b/index.tsx
index 9dae694..4a0ca12 100644
--- a/index.tsx
+++ b/index.tsx
@@ -1110,7 +1110,7 @@ export function compiler(
react(node, output, state) {
return (
<pre key={state.key}>
- <code className={node.lang ? `lang-${node.lang}` : ''}>
+ <code type={node.type ? node.type : 'block'} className={node.lang ? `lang-${node.lang}` : ''}>
{node.content}
</code>
</pre>
@@ -1139,7 +1139,7 @@ export function compiler(
}
},
react(node, output, state) {
- return <code key={state.key}>{node.content}</code>
+ return <code key={state.key} type='inline'>{node.content}</code>
},
} as MarkdownToJSX.Rule<{ content: string }>, It probably miss some things to be good but it describes the idea. |
This issue means the library is not markdown compliant right? |
Hi there, awesome light little library :)
I've identified a few issues with code blocks, they are as follows:
code
does not differentiate between the 3 code types internally, should be able to render differently based on the type of code nodeThe text was updated successfully, but these errors were encountered: