├── .gitignore ├── LICENSE.md ├── README.md ├── babel.config.js ├── docs ├── components │ ├── color-switcher.js │ └── content.js ├── next.config.js ├── package.json ├── pages │ ├── _app.js │ ├── _document.js │ ├── api │ │ └── md.js │ └── index.js └── yarn.lock ├── package.json ├── prettier.config.js ├── src ├── github.js ├── index.js ├── plugins │ ├── sh-to-shell.js │ └── video-link-to-details │ │ ├── index.js │ │ └── node.js └── rehype.js ├── test ├── index.js └── snapshots │ ├── index.js.md │ └── index.js.snap ├── vercel.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | coverage 4 | .next 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2020 The Hack Foundation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `@hackclub/markdown` 2 | 3 | Render Markdown to HTML, Hack Club-style. Used primarily on the [Hack Club Workshops](https://hackclub.com/workshops/) site. 4 | 5 | ```sh 6 | yarn add @hackclub/markdown 7 | # npm i @hackclub/markdown 8 | ``` 9 | 10 | [**Try the demo**](https://markdown.hackclub.com) 11 | 12 | ## Usage 13 | 14 | This package does not include any frontend code, such as React or CSS. 15 | 16 | This package is designed for rendering at build or otherwise on a server, not client-side— 17 | the bundle size is significant & it’s not been optimized for performance. 18 | 19 | Always use with `await`. 20 | 21 | ```js 22 | import fs from 'fs' 23 | import md from '@hackclub/markdown' 24 | 25 | const getReadme = async () => ( 26 | const text = fs.readFileSync('./README.md', 'utf8') 27 | return await md(text, '/README.md', '/static') 28 | ) 29 | ``` 30 | 31 | | Param | Default | Description | 32 | | ----------- | -------------- | --------------------------------------------------------------- | 33 | | input | Req’d! | String. The Markdown text to transform. | 34 | | filePath | `'/README.md'` | String. The Markdown’s path (for fixing relative image links). | 35 | | imagePrefix | `'/'` | String. A prefix for the path to relative images. | 36 | | removeTitle | `false` | Bool. Remove starting `h1` (if titles are rendered separately). | 37 | 38 | If you need to parse frontmatter, we recommend using [gray-matter](https://npm.im/gray-matter) 39 | alongside `@hackclub/markdown`, but it’s not included in this package. 40 | 41 | *** 42 | 43 | Partially based on the [Next.js documentation site](https://github.com/zeit/next-site/pull/473/files#diff-879732a0915babd1688248ad1144c2d4). 44 | 45 | MIT License 46 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [['@babel/preset-env']] 3 | } 4 | -------------------------------------------------------------------------------- /docs/components/color-switcher.js: -------------------------------------------------------------------------------- 1 | import { IconButton, useColorMode } from 'theme-ui' 2 | 3 | const ColorSwitcher = props => { 4 | const [mode, setMode] = useColorMode() 5 | return ( 6 | setMode(mode === 'dark' ? 'light' : 'dark')} 8 | title="Invert Colors" 9 | sx={{ 10 | position: 'absolute', 11 | top: 3, 12 | right: 3, 13 | color: 'primary', 14 | borderRadius: 'circle', 15 | transition: 'box-shadow .125s ease-in-out', 16 | ':hover,:focus': { 17 | boxShadow: '0 0 0 2px', 18 | outline: 'none' 19 | } 20 | }} 21 | > 22 | 23 | 31 | 32 | 33 | 34 | ) 35 | } 36 | 37 | export default ColorSwitcher 38 | -------------------------------------------------------------------------------- /docs/components/content.js: -------------------------------------------------------------------------------- 1 | import { BaseStyles } from 'theme-ui' 2 | import styled from '@emotion/styled' 3 | 4 | const StyledContent = styled(BaseStyles)` 5 | font-size: 1.25rem; 6 | 7 | a { 8 | word-break: break-word; 9 | } 10 | 11 | .heading a { 12 | color: inherit; 13 | text-decoration: none; 14 | } 15 | ` 16 | 17 | const Content = ({ html }) => ( 18 | 23 | ) 24 | 25 | export default Content 26 | -------------------------------------------------------------------------------- /docs/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = {} 2 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@hackclub/markdown-docs", 3 | "version": "0.0.3", 4 | "author": "Lachlan Campbell (https://lachlanjc.com) ", 5 | "license": "MIT", 6 | "private": true, 7 | "scripts": { 8 | "dev": "next", 9 | "build": "next build", 10 | "start": "next start" 11 | }, 12 | "dependencies": { 13 | "@hackclub/markdown": "^0.0.43", 14 | "@hackclub/meta": "^1.0.0", 15 | "@hackclub/theme": "^0.2.0", 16 | "lodash": "^4.17.19", 17 | "next": "^9.4.4", 18 | "react": "^16.13.1", 19 | "react-dom": "^16.13.1", 20 | "theme-ui": "^0.3.1" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /docs/pages/_app.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import NextApp from 'next/app' 3 | 4 | import '@hackclub/theme/fonts/reg-ital-bold.css' 5 | import theme from '@hackclub/theme' 6 | import { ThemeProvider } from 'theme-ui' 7 | 8 | export default class App extends NextApp { 9 | render() { 10 | const { Component, pageProps } = this.props 11 | return ( 12 | 13 | 14 | 15 | ) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /docs/pages/_document.js: -------------------------------------------------------------------------------- 1 | import Document, { Html,Head, Main, NextScript } from 'next/document' 2 | import { InitializeColorMode } from 'theme-ui' 3 | 4 | export default class extends Document { 5 | static async getInitialProps(ctx) { 6 | const initialProps = await Document.getInitialProps(ctx) 7 | return { ...initialProps } 8 | } 9 | 10 | render() { 11 | return ( 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /docs/pages/api/md.js: -------------------------------------------------------------------------------- 1 | import md from '@hackclub/markdown' 2 | 3 | export default async (req, res) => { 4 | const { text } = req.query 5 | const html = await md(text, 'README.md', '/', false) 6 | console.log(text, html) 7 | res.status(200).end(html) 8 | } 9 | -------------------------------------------------------------------------------- /docs/pages/index.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react' 2 | import { 3 | Container, 4 | NavLink, 5 | Heading, 6 | Text, 7 | Card, 8 | Grid, 9 | Label, 10 | Textarea 11 | } from 'theme-ui' 12 | import Head from 'next/head' 13 | import Meta from '@hackclub/meta' 14 | import ColorSwitcher from '../components/color-switcher' 15 | import Content from '../components/content' 16 | 17 | const sample = `# Hello! 18 | 19 | This is [Hack Club **Markdown**](https://github.com/hackclub/markdown). 20 | 21 | \`\`\`js 22 | const hi = () => console.log('Hello!') 23 | \`\`\` 24 | ` 25 | 26 | export default () => { 27 | const [text, setText] = useState(sample) 28 | const [html, setHtml] = useState('') 29 | useEffect(() => { 30 | fetch(`/api/md?text=${encodeURIComponent(text)}`) 31 | .then((res) => res.text()) 32 | .then((res) => setHtml(res)) 33 | }, [text]) 34 | return ( 35 | 36 | 41 | 42 | 43 | 52 | Hack Club 53 | {' '} 54 | 60 | Markdown 61 | 62 | 63 | 75 | GitHub 76 | 77 | npm 78 | 79 | 80 | 81 |
82 | 85 |