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

code highlighting #317

Closed
GodVoid opened this issue May 5, 2023 · 1 comment
Closed

code highlighting #317

GodVoid opened this issue May 5, 2023 · 1 comment

Comments

@GodVoid
Copy link

GodVoid commented May 5, 2023

Hello, How to add highlighting to code blocks separately?

@gmsgowtham
Copy link
Owner

gmsgowtham commented May 5, 2023

Please use custom renderer

import React, { ReactNode } from "react";
import type { ViewStyle, TextStyle } from "react-native";
import Markdown, { Renderer, RendererInterface } from "react-native-marked";
import SyntaxHighlighter from "react-native-syntax-highlighter";
import { docco } from "react-syntax-highlighter/styles/hljs";

class CustomRenderer extends Renderer implements RendererInterface {
  constructor() {
    super();
  }

  code(
    text: string,
    language?: string,
    _containerStyle?: ViewStyle,
    _textStyle?: TextStyle
  ): ReactNode {
    return (
      <SyntaxHighlighter
        key={this.getKey()}
        language={language}
        style={docco}
        highlighter={"prism" || "hljs"}
      >
        {text}
      </SyntaxHighlighter>
    );
  }
}

const renderer = new CustomRenderer();

const ExampleComponent = () => {
  return (
    <Markdown
      value={"`Hello world`"}
      flatListProps={{
        initialNumToRender: 8,
      }}
      renderer={renderer}
    />
  );
};

@gmsgowtham gmsgowtham pinned this issue May 5, 2023
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