(options)
| 212 | * React node. |
| 213 | */ |
| 214 | export function MarkdownHooks(options) { |
| 215 | const processor = createProcessor(options) |
| 216 | const [error, setError] = useState( |
| 217 | /** @type {Error | undefined} */ (undefined) |
| 218 | ) |
| 219 | const [tree, setTree] = useState(/** @type {Root | undefined} */ (undefined)) |
| 220 | |
| 221 | useEffect( |
| 222 | function () { |
| 223 | let cancelled = false |
| 224 | const file = createFile(options) |
| 225 | |
| 226 | processor.run(processor.parse(file), file, function (error, tree) { |
| 227 | if (!cancelled) { |
| 228 | setError(error) |
| 229 | setTree(tree) |
| 230 | } |
| 231 | }) |
| 232 | |
| 233 | /** |
| 234 | * @returns {undefined} |
| 235 | * Nothing. |
| 236 | */ |
| 237 | return function () { |
| 238 | cancelled = true |
| 239 | } |
| 240 | }, |
| 241 | [ |
| 242 | options.children, |
| 243 | options.rehypePlugins, |
| 244 | options.remarkPlugins, |
| 245 | options.remarkRehypeOptions |
| 246 | ] |
| 247 | ) |
| 248 | |
| 249 | if (error) throw error |
| 250 | |
| 251 | return tree ? post(tree, options) : options.fallback |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Set up the `unified` processor. |
nothing calls this directly
no test coverage detected
searching dependent graphs…