/* eslint-disable react/display-name */ import React from 'react'; import { css } from '@emotion/core'; import styled from '@emotion/styled'; import { colors, lengths } from 'netlify-cms-ui-default'; import VoidBlock from './components/VoidBlock'; import Shortcode from './components/Shortcode'; const bottomMargin = '16px'; const headerStyles = ` font-weight: 700; line-height: 1; `; const StyledH1 = styled.h1` ${headerStyles}; font-size: 32px; margin-top: 16px; `; const StyledH2 = styled.h2` ${headerStyles}; font-size: 24px; margin-top: 12px; `; const StyledH3 = styled.h3` ${headerStyles}; font-size: 20px; `; const StyledH4 = styled.h4` ${headerStyles}; font-size: 18px; margin-top: 8px; `; const StyledH5 = styled.h5` ${headerStyles}; font-size: 16px; margin-top: 8px; `; const StyledH6 = StyledH5.withComponent('h6'); const StyledP = styled.p` margin-bottom: ${bottomMargin}; `; const StyledBlockQuote = styled.blockquote` padding-left: 16px; border-left: 3px solid ${colors.background}; margin-left: 0; margin-right: 0; margin-bottom: ${bottomMargin}; `; const StyledPre = styled.pre` margin-bottom: ${bottomMargin}; white-space: pre-wrap; & > code { display: block; width: 100%; overflow-y: auto; background-color: #000; color: #ccc; border-radius: ${lengths.borderRadius}; padding: 10px; } `; const StyledCode = styled.code` background-color: ${colors.background}; border-radius: ${lengths.borderRadius}; padding: 0 2px; font-size: 85%; `; const StyledUl = styled.ul` margin-bottom: ${bottomMargin}; padding-left: 30px; `; const StyledOl = StyledUl.withComponent('ol'); const StyledLi = styled.li` & > p:first-child { margin-top: 8px; } & > p:last-child { margin-bottom: 8px; } `; const StyledA = styled.a` text-decoration: underline; font-size: inherit; `; const StyledHr = styled.hr` border: 1px solid; margin-bottom: 16px; `; const StyledTable = styled.table` border-collapse: collapse; `; const StyledTd = styled.td` border: 2px solid black; padding: 8px; text-align: left; `; /** * Slate uses React components to render each type of node that it receives. * This is the closest thing Slate has to a schema definition. The types are set * by us when we manually deserialize from Remark's MDAST to Slate's AST. */ /** * Mark Components */ function Bold(props) { return {props.children}; } function Italic(props) { return {props.children}; } function Strikethrough(props) { return {props.children}; } function Code(props) { return {props.children}; } /** * Node Components */ function Paragraph(props) { return {props.children}; } function ListItem(props) { return {props.children}; } function Quote(props) { return {props.children}; } function CodeBlock(props) { return ( {props.children} ); } function HeadingOne(props) { return {props.children}; } function HeadingTwo(props) { return {props.children}; } function HeadingThree(props) { return {props.children}; } function HeadingFour(props) { return {props.children}; } function HeadingFive(props) { return {props.children}; } function HeadingSix(props) { return {props.children}; } function Table(props) { return ( {props.children} ); } function TableRow(props) { return {props.children}; } function TableCell(props) { return {props.children}; } function ThematicBreak(props) { return ( ); } function Break(props) { return
; } function BulletedList(props) { return {props.children}; } function NumberedList(props) { return ( {props.children} ); } function Link(props) { const data = props.node.get('data'); const url = data.get('url'); const title = data.get('title') || url; return ( {props.children} ); } function Image(props) { const data = props.node.get('data'); const marks = data.get('marks'); const url = data.get('url'); const title = data.get('title'); const alt = data.get('alt'); const image = {alt}; const result = !marks ? image : marks.reduce((acc, mark) => { return renderMark({ mark, children: acc }); }, image); return result; } export function renderMark() { return props => { switch (props.mark.type) { case 'bold': return ; case 'italic': return ; case 'strikethrough': return ; case 'code': return ; } }; } export function renderInline() { return props => { switch (props.node.type) { case 'link': return ; case 'image': return ; case 'break': return ; } }; } export function renderBlock({ classNameWrapper, codeBlockComponent }) { return props => { switch (props.node.type) { case 'paragraph': return ; case 'list-item': return ; case 'quote': return ; case 'code-block': if (codeBlockComponent) { return ( ); } return ; case 'heading-one': return ; case 'heading-two': return ; case 'heading-three': return ; case 'heading-four': return ; case 'heading-five': return ; case 'heading-six': return ; case 'table': return ; case 'table-row': return ; case 'table-cell': return ; case 'thematic-break': return ( ); case 'bulleted-list': return ; case 'numbered-list': return ; case 'shortcode': return ( ); } }; }