Remark Sugar High

Use Sugar High Syntax Highlighting with Remark Plugin. Source Code ↗

Usage

Install

npm install remark remark-html remark-gfm remark-sugar-high

API

remark-plugin.js

import { remark } from 'remark'
import { highlight } from 'remark-sugar-high'
import html from 'remark-html'
import gfm from 'remark-gfm'

async function renderMarkdown(input) {
  const markdown = await remark()
    .use(gfm)
    .use(highlight)
    .use(html, { sanitize: false })
    .process(input)

  return markdown.toString()
}

export default async Preview({ markdown }) {
  const html = await renderMarkdown(markdown)
  return (
    <div dangerouslySetInnerHTML={{ __html: html }} /> 
  )
}

Examples

script.js

// Here is a simple function
async function hello() {
    console.log('Hello, world from JavaScript!')
    return 123 // return a number
}

await hello()

print.py

# Here is a simple function
def hello():
    print('Hello, world from Python!')
    return 123 # return a number

styles.css

body {
  font-family: 'Geist Sans', sans-serif;
  background-color: #f0f0f0;
  color: #333; /* text color */
}

h1 {
  color: #0070f3;
}

@media (max-width: 600px) {
  body {
    font-size: 14px;
  }
}

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>Hello, world!</h1>
</body>
</html>