Farmbot-Web-App/frontend/ui/markdown.tsx

28 lines
679 B
TypeScript
Raw Permalink Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
2017-08-28 05:44:37 -06:00
const emoji = require("markdown-it-emoji");
const md = require("markdown-it")({
2017-06-29 12:54:02 -06:00
/** Enable HTML tags in source */
html: true,
/** Convert '\n' in paragraphs into <br> */
breaks: true,
/** Autoconvert URL-like text to links */
linkify: true,
/** Enable some language-neutral replacement + quotes beautification */
typographer: true,
});
md.disable("heading");
2017-06-29 12:54:02 -06:00
md.use(emoji);
interface MarkdownProps {
2018-03-19 08:16:04 -06:00
children?: React.ReactNode;
2017-06-29 12:54:02 -06:00
}
export function Markdown(props: MarkdownProps) {
2017-08-28 05:44:37 -06:00
const result = md.render(props.children);
return <span
className="markdown"
dangerouslySetInnerHTML={{ __html: result }}>
</span>;
2017-06-29 12:54:02 -06:00
}