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

Custom Renderer Option to render things like Images #183

Open
michaelkremenetsky opened this issue Feb 14, 2024 · 2 comments
Open

Custom Renderer Option to render things like Images #183

michaelkremenetsky opened this issue Feb 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@michaelkremenetsky
Copy link

michaelkremenetsky commented Feb 14, 2024

I am using this library to render some markdown as it's much faster than any markdown renderer that I have come across thanks to the native component. The only issue is that I can't find a way to render images. To render images I was just wondering if there was a way to do any custom rendering similar to what I was doing in react-native-marked which I used before. Or at least is there a way to parse just the Images and render them using something like expo-image?

I was previously doing something like:

class CustomRenderer extends Renderer implements RendererInterface {
  link(
    children: string | ReactNode[],
    href: string,
    styles?: TextStyle,
  ): ReactNode {
    return (
      <RegularText
        selectable
        accessibilityRole="link"
        accessibilityHint="Opens in a new window"
        key={this.getKey()}
        onPress={() => {
          openWeb(href);
        }}
        // style={underline}
        style={[styles, { borderBottomWidth: 10, paddingBottom: 4 }]}
        // style={styles} // Style for this is handled on the useMarkdown hook
      >
        {children}
      </RegularText>
    );
  }
  image(uri: string, _alt?: string, _style?: ImageStyle): ReactNode {
    return (
      <Image
        key={this.getKey()}
        source={{ uri: uri }}
        placeholder={blurhash}
        style={{ borderRadius: 0 }}
        className={`h-[200px] w-[${width}]}`}
      />
    );
  }
  getTextNode(children: string | ReactNode[], styles?: TextStyle): ReactNode {
    return (
      <Text selectable key={this.getKey()} style={styles}>
        {children}
      </Text>
    );
  }
  getViewNode(children: ReactNode[] | null, styles?: ViewStyle): ReactNode {
    return (
      <View key={this.getKey()} style={styles}>
        {children}
      </View>
    );
  }
  getBlockquoteNode(children: ReactNode[], styles?: ViewStyle): ReactNode {
    {
      return (
        <View key={this.getKey()} style={styles}>
          {children}
        </View>
      );
    }
  }
}
@tomekzaw
Copy link
Collaborator

Hey @michaelkremenetsky, thanks for opening this issue.

Nope, currently we don't support showing images, but this is definitely something that we will be working on in the future.

Also, MarkdownTextInput is not a regular Markdown renderer; the main difference is that it doesn't skip Markdown syntax characters so you can still edit them. This means that if you type Hello *world*, the asterisks are not removed. That's why we are also working on MarkdownText component, see #125.

@tomekzaw tomekzaw added the enhancement New feature or request label Sep 19, 2024
@tomekzaw
Copy link
Collaborator

FYI Inline image preview feature for web was added in #462; haven't started working on Android and iOS support yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants