|
| 1 | +<!--rehype:ignore:start--> |
1 | 2 | React Markdown Preview
|
2 | 3 | ===
|
3 |
| -<!--dividing--> |
| 4 | +<!--rehype:ignore:end--> |
4 | 5 |
|
5 | 6 | [](https://github.com/uiwjs/react-markdown-preview/actions/workflows/ci.marster.yml)
|
6 | 7 | [](https://www.jsdelivr.com/package/npm/@uiw/react-markdown-preview)
|
@@ -76,6 +77,111 @@ export default function Demo() {
|
76 | 77 | }
|
77 | 78 | ```
|
78 | 79 |
|
| 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 | + |
79 | 185 | ### Options Props
|
80 | 186 |
|
81 | 187 | ```typescript
|
|
0 commit comments