Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | // Copyright (c) 2015-present, salesforce.com, inc. All rights reserved // Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license const MDXC = require('mdxc'); const importPattern = /import\s+.*?\s+from\s+['"].*?['"];?/g; const getMatches = (pattern, string) => { const matches = []; let match; while ((match = pattern.exec(string)) !== null) matches.push(match); return matches; }; module.exports = code => { const md = new MDXC({ linkify: true, unwrapped: true }); const imports = getMatches(importPattern, code); const elements = md.render(code); const tags = Array.from(md.renderer.tags.values()).sort(); return ` import React, { createElement } from 'react'; import Doc, { factories, createTableOfContents } from '../../../shared/components/Doc'; ${imports.join('\n')} const { ${tags.join(',')} } = factories; export const getElement = () => createElement(Doc, {}, ${elements}); export const getContents = () => createTableOfContents(getElement()); `; }; |