Giter Site home page Giter Site logo

sibiraj-s / marked-react Goto Github PK

View Code? Open in Web Editor NEW
61.0 61.0 12.0 4.33 MB

⚛️ Render Markdown as React components

Home Page: https://sibiraj-s.github.io/marked-react/

License: MIT License

Shell 0.83% JavaScript 4.11% CSS 0.21% TypeScript 94.72% HTML 0.14%
markdown markedjs react react-markdown

marked-react's People

Contributors

avivahl avatar dependabot[bot] avatar diggest avatar goodpassiveman avatar kelvinhammond avatar sibiraj-s avatar vdebergue avatar wangyi12358 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

marked-react's Issues

Where do we sanitise the incoming markup? (Hooks implementation)

Writing DOM.purify inside renderer, right before returning the parsed markup leads to problems like showing [object Object] for things like bold and italics.

    const renderer = {
        paragraph(text) {
            console.log("text =", text)
            // let cleanHTML = DOMPurify.sanitize(text, { USE_PROFILES: { html: true } });
            return <MathJax key={uniqueId()}>{text}</MathJax>
            // return <span>hahah lol</span>
        },
        html(text) {
            let cleanHTML = DOMPurify.sanitize(text, { USE_PROFILES: { html: true } });
            return <span key={"title-span"} dangerouslySetInnerHTML={{ __html: cleanHTML }}></span>;
        }
    }

Where do you suggest we purify the input?

No Support for Nested List

The library doesn't Support Nested list as All List gets rendered as single li even if they are alledged as


- test1
  - test2

Property 'elementId' does not exist

When I create a custom renderer

const renderer = {
  paragraph(text: string) {
    return (
      <p key={this.elementId} className={s.paragraph}>
        {text}
      </p>
    )
  },
}

I've got an error Property 'elementId' does not exist on type '{ paragraph(text: string): Element; }'.ts(2339). What I missed to use renderer with TS?

Custom Extensions

Thx for lib.
How can i add a custom extension?
In "marked" lib i can use marked.use().

Replace html anchors with React Router Link component

I was implementing markdown parser in my project and ran into a problem where links with relative paths were redirecting to a page and clearing state (acting as standard anchors) due to page reload. React Router Link component or useNavigate() secures the page reload and keeps the state. I was suggested to use marked-react for this but it didn't solve my problem.

Could you please provide solution for replacing anchors with Link component?

Parse inline?

Neat lib, thanks 👍

What's a good way to parse inline so that parent paragraph does not appear? (eg: <p>stuff</p>stuff)

Missing src directory

Description

After installing the latest version of marked-react, I am seeing a runtime error (see "Additional Context" below). The source-map-loader package is looking for files in C:\myproject\node_modules\marked-react\src\, but the src directory is missing.

I have tried uninstalling and reinstalling the package, but the problem persists.

Steps to reproduce

  1. Install the marked-react package in a project
  2. Attempt to run the project, webpack-dev-server --mode development; see error (below)
  3. Observe that src is not in node_modules\marked-react directory

Environment

Operating system: Windows
Package manager: npm
marked-react package version: 1.3.1
source-map-loader: 3.0.2 || 4.0.1

Additional context
Here is the full runtime error:

Compiled with problems:

WARNING in ./node_modules/marked-react/dist/marked-react.js

Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'C:\myproject\node_modules\marked-react\src\Markdown.ts' file: Error: ENOENT: no such file or directory, open 'C:\myproject\node_modules\marked-react\src\Markdown.ts'


WARNING in ./node_modules/marked-react/dist/marked-react.js

Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'C:\myproject\node_modules\marked-react\src\ReactParser.ts' file: Error: ENOENT: no such file or directory, open 'C:\myproject\node_modules\marked-react\src\ReactParser.ts'


WARNING in ./node_modules/marked-react/dist/marked-react.js

Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'C:\myproject\node_modules\marked-react\src\ReactRenderer.ts' file: Error: ENOENT: no such file or directory, open 'C:\myproject\node_modules\marked-react\src\ReactRenderer.ts'


WARNING in ./node_modules/marked-react/dist/marked-react.js

Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'C:\myproject\node_modules\marked-react\src\helpers.ts' file: Error: ENOENT: no such file or directory, open 'C:\myproject\node_modules\marked-react\src\helpers.ts'

Custom parser options

Thank you for the great extension! It really helps!

So, I need to parse some custom markdown tokens from own tokenizer extension. I can add functions to custom renderer but is there an option to make parser recognize new token types?

A way to pass data to the renderer

It would be nice if there was a way to pass data to the renderer via the renderer prop.

Perhaps, instead of passing an object as a renderer, one could have the additional option of passing a function that returns the renderer object. This way I can pass in additional data from the component where I use <Markdown> component in, with maybe a data prop. This is just a suggestion of how it could work.

I find this useful if I want to style the output of a renderer token based on some data inside my component.

E.g.
If I had a <Paragraph> component that renders markdown text as a paragraph and I want to be able style that render output based on if the paragraph is supposed to be grayed out(this is passed as a prop to my component).

const Paragraph = (props) => {
 // suggested/proposed renderer function that returns renderer object
 let rendererFn = (data) => {
  let isGreyedOut = data.grey;

   return {
     paragraph(text) {
      React.createElement('p', {className: `${isGreyedOut && 'text-grey'}`}, text)
     }
   }
 }
 
  return (
    {/* data from my component is passed to the <Marked> 'renderer' prop(which now receives a function) via the proposed 'data' prop */}
    <Marked renderer={rendererFn} data={{isGreyedOut: props.isGreyedOut}} value={props.text}/>
    )
}

Don't know if this makes any sense...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.