Skip to content

Question: How to apply styling to react-rendered output #111

Description

@lukewis

Hello! Thank you so much for this library! I love the focus that it has on extensibility! One thing that I've been struggling with is how to apply styling to the output from SimpleMarkdown.defaultReactOutput. I spent some time googling as well as exploring this repo looking for examples, but have come up empty so far. Any tips to point me in the right direction?

A bit of relevant info.......I'm attempting to use this in a React Native application that uses Expo.

The below renders correctly....but my particular app has a dark background that cascades down the DOM.

import React from "react";
import * as SimpleMarkdown from "simple-markdown";
import { StyleSheet } from "react-native";

export const MarkdownLuke = () => {
  const txt = `
# Summary

This is a sample markdown page with a link to [google](https://google.com)
`;
  const tree = SimpleMarkdown.defaultBlockParse(txt);
  const output = SimpleMarkdown.defaultReactOutput(tree);
  console.log(output);
  return (
    <div>
      <div>{output}</div>
    </div>
  );
};

To fix this, I'd like to change the background-color, but if I add a style to it, then the entire react tree seems to disappear (a bit hard to explain, actually)

// This does NOT work

export const MarkdownLuke = () => {
  const txt = `
# Summary

This is a sample markdown page with a link to [google](https://google.com)
`;
  const tree = SimpleMarkdown.defaultBlockParse(txt);
  const output = SimpleMarkdown.defaultReactOutput(tree);
  console.log(output);
  return (
    <div style={styles.block}>
      <div>{output}</div>
    </div>
  );
};

const styles = StyleSheet.create({
  block: {
    backgroundColor: "white",
  },
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions