diff --git a/src/utils/markdown.module.scss b/src/utils/markdown.module.scss new file mode 100644 index 00000000..7bc6c1db --- /dev/null +++ b/src/utils/markdown.module.scss @@ -0,0 +1,46 @@ +@import '../layouts/variables.scss'; + +.root { + display: block; + overflow: hidden; + padding-bottom: 56.25%; + position: relative; + height: 0; +} + +.root iframe { + left: 0; + top: 0; + height: 100%; + width: 100%; + position: absolute; +} + +.image { + clear: both; + display: block; + width: 100%; + max-width: 100%; +} + +@media screen and (min-width: $CSS_BREAKPOINT_START_M) { + .image.left, + .image.right { + width: var(--block); + } + .image.left { + float: left; + margin-right: var(--gutter); + } + .image.right { + float: right; + margin-left: var(--gutter); + } +} + +@media screen and (min-width: $CSS_BREAKPOINT_START_L) { + .image.left, + .image.right { + width: calc(calc(var(--column) * 4) + calc(var(--gutter) * 3)); + } +} diff --git a/src/utils/markdown.tsx b/src/utils/markdown.tsx index 24f3aa13..502c9fc1 100644 --- a/src/utils/markdown.tsx +++ b/src/utils/markdown.tsx @@ -19,11 +19,11 @@ import Emphasis from '../components/em'; import Code from '../components/code'; import Cite from '../components/cite'; import Gallery from '../components/gallery'; -import { fixText } from './text'; import YError from 'yerror'; +import styles from './markdown.module.scss'; +import { fixText } from './text'; import { publicRuntimeConfig } from './config'; import { toASCIIString } from './ascii'; -import { CSS_BREAKPOINT_START_L, CSS_BREAKPOINT_START_M } from './constants'; import { parseYouTubeURL } from './youtube'; import { Fragment } from 'react'; import type { ReactNode } from 'react'; @@ -161,14 +161,14 @@ const headingMap: NodeToElementMapper = ( node.depth === 1 ? Heading1 : node.depth === 2 - ? Heading2 - : node.depth === 3 - ? Heading3 - : node.depth === 4 - ? Heading4 - : node.depth === 5 - ? Heading5 - : Heading6; + ? Heading2 + : node.depth === 3 + ? Heading3 + : node.depth === 4 + ? Heading4 + : node.depth === 5 + ? Heading5 + : Heading6; return node.depth === 1 ? ( @@ -186,18 +186,17 @@ const headingMap: NodeToElementMapper = ( ); }; -const textMap: NodeToElementMapper = (context, node) => ( - node.value.includes('\n') ? - fixText(node.value) - .split(/\r?\n/gm) - .map((text, i) => ( - - {i > 0 ?
: null} - {text} -
- )) - : fixText(node.value) -); +const textMap: NodeToElementMapper = (context, node) => + node.value.includes('\n') + ? fixText(node.value) + .split(/\r?\n/gm) + .map((text, i) => ( + + {i > 0 ?
: null} + {text} +
+ )) + : fixText(node.value); const boldMap: NodeToElementMapper = (context, node) => ( {node.children.map((node, index) => @@ -288,41 +287,11 @@ const imageMap: NodeToElementMapper = (context, node) => { node?.title?.startsWith('🖼➡️') ? 'right' : node?.title?.startsWith('🖼⬅️') - ? 'left' - : '' + ? 'left' + : '' + ' ' + styles.image } {...(finalTitle ? { title: finalTitle } : {})} /> - ); }; @@ -331,7 +300,7 @@ const hyperlinkMap: NodeToElementMapper = (context, node) => { const youtubeURL = parseYouTubeURL(node.url); return youtubeURL && node?.title === '📺' ? ( - + - ) : ( @@ -405,7 +357,10 @@ export function renderMarkdown( } if (elementsMapping[node.type]) { - return elementsMapping[node.type as 'root'](context, node as MarkdownRootNode); + return elementsMapping[node.type as 'root']( + context, + node as MarkdownRootNode + ); } console.warn(`Unrecognized Markdown element:`, node);