Skip to content

Commit db78d1b

Browse files
authored
Merge pull request #7 from mintlify/deep/eng-3060-code-blocks-line-highlighting
Deep/eng 3060 code blocks line highlighting
2 parents 488dd45 + 9994b16 commit db78d1b

27 files changed

+364
-171
lines changed

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"@mintlify/prettier-config/config.js"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
@layer base {
6+
:root {
7+
--primary-light: 85 215 153;
8+
}
9+
}

examples/app-router/app/layout.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import type { Metadata } from "next";
2-
import "@/app/globals.css";
3-
import "@mintlify/mdx/dist/styles.css";
1+
import '@mintlify/mdx/dist/styles.css';
2+
import type { Metadata } from 'next';
3+
4+
import '@/app/globals.css';
45

56
export const metadata: Metadata = {
6-
title: "Create Next App",
7-
description: "Generated by create next app",
7+
title: 'Create Next App',
8+
description: 'Generated by create next app',
89
};
910

10-
export default function RootLayout({
11-
children,
12-
}: {
13-
children: React.ReactNode;
14-
}) {
11+
export default function RootLayout({ children }: { children: React.ReactNode }) {
1512
return (
1613
<html lang="en">
1714
<body>{children}</body>

examples/app-router/app/page.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { getCompiledServerMdx } from "@mintlify/mdx";
1+
import { getCompiledServerMdx } from '@mintlify/mdx';
2+
import { promises as fs } from 'fs';
23

34
export default async function Home() {
4-
const fileContentResponse = await fetch(
5-
"https://raw.githubusercontent.com/mintlify/starter/main/essentials/code.mdx"
6-
);
7-
const fileContentData = await fileContentResponse.text();
5+
const data = await fs.readFile(process.cwd() + '/examples/highlight-example.mdx');
86

97
const { content, frontmatter } = await getCompiledServerMdx<{
108
title: string;
119
}>({
12-
source: fileContentData,
10+
source: data.toString(),
1311
});
1412

1513
return (
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: 'Line Highlighting'
3+
description: 'Highlights specific lines and/or line ranges'
4+
---
5+
6+
This MDX file demonstrates syntax highlighting for various programming languages.
7+
8+
## JavaScript
9+
10+
```js index.js {2}
11+
console.log('Hello, world!');
12+
function add(a, b) {
13+
return a + b;
14+
}
15+
16+
function subtract(a, b) {
17+
return a - b;
18+
}
19+
```
20+
21+
## Python
22+
23+
```python index.py {1-2,4-5}
24+
def add(a, b):
25+
return a + b
26+
27+
def subtract(a, b):
28+
return a - b
29+
```
30+
31+
## Java
32+
33+
```java {3}
34+
public class Main {
35+
public static void main(String[] args) {
36+
System.out.println("Hello, World!");
37+
}
38+
}
39+
```
40+
41+
## C#
42+
43+
```csharp index.cs {1,3-4}
44+
public class Program
45+
{
46+
public static void Main(string[] args)
47+
{
48+
Console.WriteLine("Hello, World!");
49+
}
50+
}
51+
```

examples/app-router/next.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {}
2+
const nextConfig = {};
33

4-
module.exports = nextConfig
4+
module.exports = nextConfig;

examples/app-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@mintlify/mdx": "^0.0.43",
12+
"@mintlify/mdx": "^0.0.44",
1313
"next": "14.0.4",
1414
"react": "^18",
1515
"react-dom": "^18"

examples/app-router/postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ module.exports = {
33
tailwindcss: {},
44
autoprefixer: {},
55
},
6-
}
6+
};

examples/app-router/readme.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ You can check out the demo of [this page](https://github.com/mintlify/mdx/blob/m
1313
1. Call the `getCompiledServerMdx` function inside your async React Server Component which will give you the `frontmatter` and `content`.
1414

1515
```tsx
16-
import { getCompiledServerMdx } from "@mintlify/mdx";
16+
import { getCompiledServerMdx } from '@mintlify/mdx';
1717

1818
export default async function Home() {
1919
const { content, frontmatter } = await getCompiledServerMdx({
@@ -38,19 +38,15 @@ You can check out the demo of [this page](https://github.com/mintlify/mdx/blob/m
3838
2. Import `@mintlify/mdx/dist/styles.css` inside your `layout.tsx` file. This file contains the styles for the code syntax highlighting.
3939

4040
```tsx
41-
import type { Metadata } from "next";
42-
import "@mintlify/mdx/dist/styles.css";
41+
import '@mintlify/mdx/dist/styles.css';
42+
import type { Metadata } from 'next';
4343

4444
export const metadata: Metadata = {
45-
title: "Create Next App",
46-
description: "Generated by create next app",
45+
title: 'Create Next App',
46+
description: 'Generated by create next app',
4747
};
4848

49-
export default function RootLayout({
50-
children,
51-
}: {
52-
children: React.ReactNode;
53-
}) {
49+
export default function RootLayout({ children }: { children: React.ReactNode }) {
5450
return (
5551
<html lang="en">
5652
<body>{children}</body>
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import type { Config } from "tailwindcss";
1+
import type { Config } from 'tailwindcss';
22

33
const config: Config = {
44
content: [
5-
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
6-
"./components/**/*.{js,ts,jsx,tsx,mdx}",
7-
"./app/**/*.{js,ts,jsx,tsx,mdx}",
5+
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
6+
'./components/**/*.{js,ts,jsx,tsx,mdx}',
7+
'./app/**/*.{js,ts,jsx,tsx,mdx}',
88
],
99
theme: {
1010
extend: {
1111
backgroundImage: {
12-
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
13-
"gradient-conic":
14-
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
12+
'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
13+
'gradient-conic': 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))',
1514
},
1615
},
1716
},
18-
plugins: [require("@tailwindcss/typography")],
17+
plugins: [require('@tailwindcss/typography')],
1918
};
2019
export default config;

0 commit comments

Comments
 (0)