npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

octopus-marked

v1.0.0

Published

Some React Components to use Markdown easily

Downloads

3

Readme

React Marked Markdown

A react components package that helps you use Markdown easily.


Writing in Markdown is an amazing experience. Setting up all components and parser is kind of a pain.

Basic Usage

  • Install with npm install --save octopus-marked
  • Import component(s) you want
import { MarkdownPreview } from "octopus-marked";

MarkdownPreview

Basic Markdown view

Display Markdown is really easy with MarkdownPreview component.

Here is a simple example :

import React from "react";

import { MarkdownPreview } from "octopus-marked";

const Post = ({ post }) => (
  <div>
    <h1>{post.title}</h1>
    <MarkdownPreview value={post.content} />
  </div>
);

export default Post;

Options

Behind the scenes, octopus-marked uses marked as Markdown parser. So all marked options are available here.

Here is an example with default options :

<MarkdownPreview
  value="# Hey !"
  markedOptions={{
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: true,
    smartLists: true,
    smartypants: false,
  }}
/>

A list of options can be found here.

Syntax highlighting

octopus-marked supports syntax highlighting with highlight.js

CSS Classes

All octopus-marked components are unstyled, meaning that you can style them as you want like every others React elements.

<MarkdownPreview className="ui post content" value="#Hey !" />

LiveMarkdownTextarea

LiveMarkdownTextarea allows you to write Markdown in a textarea and see a preview of what you are writing.

<LiveMarkdownTextarea
  placeholder="Enter your comment here."
  className="row"
  inputClassName="field column"
  previewClassName="column comment-preview"
/>

Create your own Markdown Editor

You can even create your own Markdown Editor with MarkdownPreview and MarkdownInput components.

As an example here is the code of LiveMarkdownTextarea component. Note that there is also a clear() method that we can call from parent component to clear the editor.

class LiveMarkdownTextarea extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      value: props.defaultValue ? props.defaultValue : "",
    };
  }
  handleTextChange(e) {
    this.setState({ value: e.target.value });
    if (this.props.onTextChange) {
      this.props.onTextChange(e.target.value);
    }
  }
  clear() {
    this.setState({ value: "" });
  }
  render() {
    const {
      placeholder,
      className,
      inputClassName,
      previewClassName,
    } = this.props;
    const { value } = this.state;
    return (
      <section className={className}>
        <MarkdownInput
          placeholder={placeholder}
          onChange={this.handleTextChange.bind(this)}
          value={value}
          className={inputClassName}
        />

        <MarkdownPreview value={value} className={previewClassName} />
      </section>
    );
  }
}