{"size": 1241, "ext": "js", "max_stars_repo_path": "src/components/markdown/index.js", "max_stars_repo_name": "razdvapoka/pattern-exhibition", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/markdown/index.js", "max_issues_repo_name": "razdvapoka/pattern-exhibition", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/markdown/index.js", "max_forks_repo_name": "razdvapoka/pattern-exhibition", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.8653846154, "max_line_length": 63, "alphanum_fraction": 0.5310233683}
import React from "react"
import ReactMarkdown from "react-markdown"
import styles from "./index.module.styl"
import remarkTypograph from "@mavrin/remark-typograf"
import cn from "classnames"

const isExternal = url => !url.startsWith("#")
const renderers = {
  link: ({ children, title, href, ...rest }) => {
    return (
      <a
        href={title || href}
        target={title ? "" : "_blank"}
        rel={title ? "" : "noopener, noreferrer"}
      >
        {children}
      </a>
    )
  },
  footnoteReference: ({ identifier, ...rest }) => {
    const [text, url] = identifier.split("|")
    return (
      <sup>
        {url ? (
          <a
            href={url}
            target={isExternal(url) ? "_blank" : ""}
            rel={isExternal(url) ? "noopener noreferrer" : ""}
          >
            {text}
          </a>
        ) : (
          text
        )}
      </sup>
    )
  },
}

const Markdown = ({ children, className, ...rest }) => (
  <ReactMarkdown
    className={cn(styles.markdown, className)}
    source={children}
    parserOptions={{ commonmark: true, footnotes: true }}
    renderers={renderers}
    plugins={[remarkTypograph, { locale: ["en-US", "ru-RU"] }]}
    {...rest}
  />
)

export default Markdown
