Skip to content

Commit d90880e

Browse files
committedMar 6, 2023
style: support highlight-line & line-number styles.
1 parent f1733b1 commit d90880e

File tree

4 files changed

+122
-2
lines changed

4 files changed

+122
-2
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
core/README.md

‎core/README.md

+107-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
<!--rehype:ignore:start-->
12
React Markdown Preview
23
===
3-
<!--dividing-->
4+
<!--rehype:ignore:end-->
45

56
[![Build and Deploy](https://github.com/uiwjs/react-markdown-preview/actions/workflows/ci.marster.yml/badge.svg)](https://github.com/uiwjs/react-markdown-preview/actions/workflows/ci.marster.yml)
67
[![jsDelivr CDN](https://data.jsdelivr.com/v1/package/npm/@uiw/react-markdown-preview/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@uiw/react-markdown-preview)
@@ -76,6 +77,111 @@ export default function Demo() {
7677
}
7778
```
7879

80+
## highlight line
81+
82+
syntax: <code>```jsx {1,4-5}</code>
83+
84+
```jsx mdx:preview?background=#fff
85+
import React from 'react';
86+
import MarkdownPreview from '@uiw/react-markdown-preview';
87+
88+
const source = `
89+
\`\`\`js {2}
90+
function () {
91+
console.log('hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello')
92+
}
93+
\`\`\`
94+
\`\`\`js {2}
95+
function () {
96+
console.log('hello ')
97+
}
98+
\`\`\`
99+
`;
100+
101+
export default function Demo() {
102+
return (
103+
<MarkdownPreview
104+
source={source}
105+
rehypeRewrite={(node, index, parent) => {
106+
if (node.tagName === "a" && parent && /^h(1|2|3|4|5|6)/.test(parent.tagName)) {
107+
parent.children = parent.children.slice(1)
108+
}
109+
}}
110+
/>
111+
);
112+
}
113+
```
114+
115+
## Show Line Numbers
116+
117+
syntax: <code>```jsx showLineNumbers {1,4-5}</code>
118+
119+
```jsx mdx:preview?background=#fff
120+
import React from 'react';
121+
import MarkdownPreview from '@uiw/react-markdown-preview';
122+
123+
const source = `
124+
\`\`\`js showLineNumbers
125+
function () {
126+
console.log('hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello')
127+
}
128+
\`\`\`
129+
\`\`\`js showLineNumbers {2}
130+
function () {
131+
console.log('hello ')
132+
}
133+
\`\`\`
134+
`;
135+
136+
export default function Demo() {
137+
return (
138+
<MarkdownPreview
139+
source={source}
140+
rehypeRewrite={(node, index, parent) => {
141+
if (node.tagName === "a" && parent && /^h(1|2|3|4|5|6)/.test(parent.tagName)) {
142+
parent.children = parent.children.slice(1)
143+
}
144+
}}
145+
/>
146+
);
147+
}
148+
```
149+
150+
## Ignore
151+
152+
Ignore content display via HTML comments, Shown in GitHub readme, excluded in HTML.
153+
154+
```jsx mdx:preview?background=#fff
155+
import React from 'react';
156+
import MarkdownPreview from '@uiw/react-markdown-preview';
157+
158+
const source = `
159+
<!--rehype:ignore:start-->
160+
Content ignored
161+
<!--rehype:ignore:end-->
162+
Some content is ignored, please check the source code
163+
`;
164+
165+
export default function Demo() {
166+
return (
167+
<MarkdownPreview
168+
source={source}
169+
rehypeRewrite={(node, index, parent) => {
170+
if (node.tagName === "a" && parent && /^h(1|2|3|4|5|6)/.test(parent.tagName)) {
171+
parent.children = parent.children.slice(1)
172+
}
173+
}}
174+
/>
175+
);
176+
}
177+
```
178+
179+
xx
180+
181+
```md
182+
<!--rehype:ignore:start-->Ignored content<!--rehype:ignore:end-->
183+
```
184+
79185
### Options Props
80186

81187
```typescript

‎core/src/styles/markdown.less

+13
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,19 @@ body[data-color-mode*='light'] {
10531053
}
10541054
}
10551055

1056+
.highlight-line {
1057+
background-color: var(--color-neutral-muted);
1058+
}
1059+
.code-line.line-number::before {
1060+
display: inline-block;
1061+
width: 1rem;
1062+
text-align: right;
1063+
margin-right: 16px;
1064+
color: var(--color-fg-subtle);
1065+
content: attr(line);
1066+
white-space: nowrap;
1067+
}
1068+
10561069
.token.comment,
10571070
.token.prolog,
10581071
.token.doctype,

‎website/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@kkt/less-modules": "^7.4.7",
2424
"@kkt/scope-plugin-options": "^7.4.7",
2525
"kkt": "^7.4.7",
26-
"markdown-react-code-preview-loader": "^2.1.4",
26+
"markdown-react-code-preview-loader": "^2.1.5",
2727
"prettier": "^2.8.4",
2828
"pretty-quick": "^3.1.3",
2929
"react-test-renderer": "^18.2.0"

0 commit comments

Comments
 (0)
Please sign in to comment.