The Markdown component renders markdown content that is passed to it.
Install the component with the following command.
npm i @anakin-gbit/markdown@latestFor syntax highlighting you must include a Highlight.js theme manually in your project, eg. in the root layout.tsx.
import 'highlight.js/styles/github.css'<Markdown>{
`# H1 heading
Markdown content goes here!`
}</Markdown>This example (this page) fetches content from a flat file.
import React from 'react'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import Markdown from '@/components/Markdown'
const MarkdownDocs = () => {
const currentDir = path.dirname(fileURLToPath(import.meta.url))
const guideFilePath = path.join(currentDir, './guide.md')
const guide = fs.readFileSync(guideFilePath, 'utf-8')
return <Markdown>{guide}</Markdown>
}
export default MarkdownDocsThe remainder of this document is intended as a reference guide for writing markdown that will be supported by the Markdown component. It covers most commonly used elements, but others may also be supported by the Markdown component, which uses ReactMarkdown under the hood.
HTML-style comments do not appear in the rendered output.
<!-- This is a comment and won't be rendered in the output. -->
This text **will** be rendered.This text will be rendered.
Headings are written with repeated # to indicate the level.
# h1 Heading
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 HeadingAlternatively, for H1 and H2, equals signs or hyphens can be used to indicate a heading:
H1 heading
======
H2 heading
------Single `backticks` indicate inline code and are returned as `<code>backticks</code>`.Single backticks indicate inline code and are returned as <code>backticks</code>.
Use triple backticks for a code block, optionally specifying the language after the opening backticks.
```sql
select * from orders
```select * from ordersfunction greet(name) {
return `Hello, ${name}!`;
}
console.log(greet('World'));def greet(name):
return f"Hello, {name}!"
print(greet("World"))<!DOCTYPE html>
<html>
<head>
<title>Sample Page</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
h1 {
color: #333;
}#!/bin/bash
# Print "Hello, World!"
echo "Hello, World!"
# List files in the current directory
ls -lausing System;
class Program {
static void Main() {
Console.WriteLine("Hello, World!");
}
}Bold, Italic, and Strikethrough:
**This is bold text**
__This is bold text__
*This is italic text*
_This is italic text_
_**If you need both bold and italic, use both underscores and asterix**_
~~This is Strikethrough~~This is bold text This is bold text
This is italic text This is italic text
If you need both bold and italic, use both underscores and asterix
This is Strikethrough
Other markdown syntax is also supported, including the following, which are yet to be added to this documenattion: