|
| 1 | +import { toHtmlWithOptions } from '../lib/index.mjs'; |
| 2 | + |
| 3 | +console.log('\n╔════════════════════════════════════════════════╗'); |
| 4 | +console.log('║ markdown-rs WASM - Options Examples ║'); |
| 5 | +console.log('╚════════════════════════════════════════════════╝\n'); |
| 6 | + |
| 7 | +// Example 1: GitHub Flavored Markdown |
| 8 | +console.log('\n┌────────────────────────────────────────────────┐'); |
| 9 | +console.log('│ Example 1: GitHub Flavored Markdown (GFM) │'); |
| 10 | +console.log('└────────────────────────────────────────────────┘\n'); |
| 11 | + |
| 12 | +const gfmMarkdown = ` |
| 13 | +## GFM Features |
| 14 | +
|
| 15 | +### Tables |
| 16 | +| Feature | Supported | |
| 17 | +|---------|-----------| |
| 18 | +| Tables | Yes | |
| 19 | +| Tasks | Yes | |
| 20 | +
|
| 21 | +### Task Lists |
| 22 | +- [x] Completed task |
| 23 | +- [ ] Pending task |
| 24 | +
|
| 25 | +### Strikethrough |
| 26 | +~strikethrough text~ |
| 27 | +
|
| 28 | +### Autolinks |
| 29 | +https://github.com/wooorm/markdown-rs |
| 30 | +`; |
| 31 | + |
| 32 | +const gfmHtml = await toHtmlWithOptions(gfmMarkdown, { gfm: true }); |
| 33 | +console.log('Input Markdown:'); |
| 34 | +console.log('```markdown'); |
| 35 | +console.log(gfmMarkdown.trim()); |
| 36 | +console.log('```\n'); |
| 37 | +console.log('Output HTML:'); |
| 38 | +console.log('```html'); |
| 39 | +console.log(gfmHtml.trim()); |
| 40 | +console.log('```'); |
| 41 | + |
| 42 | +// Example 2: MDX Support |
| 43 | +console.log('\n┌────────────────────────────────────────────────┐'); |
| 44 | +console.log('│ Example 2: MDX (JSX in Markdown) │'); |
| 45 | +console.log('└────────────────────────────────────────────────┘\n'); |
| 46 | + |
| 47 | +const mdxMarkdown = ` |
| 48 | +# MDX Example |
| 49 | +
|
| 50 | +<CustomComponent prop="value" /> |
| 51 | +
|
| 52 | +Regular markdown with **JSX** components. |
| 53 | +`; |
| 54 | + |
| 55 | +const mdxHtml = await toHtmlWithOptions(mdxMarkdown, { mdx: true }); |
| 56 | +console.log('Input Markdown:'); |
| 57 | +console.log('```mdx'); |
| 58 | +console.log(mdxMarkdown.trim()); |
| 59 | +console.log('```\n'); |
| 60 | +console.log('Output HTML:'); |
| 61 | +console.log('```html'); |
| 62 | +console.log(mdxHtml.trim()); |
| 63 | +console.log('```'); |
| 64 | + |
| 65 | +// Example 3: Frontmatter |
| 66 | +console.log('\n┌────────────────────────────────────────────────┐'); |
| 67 | +console.log('│ Example 3: Frontmatter Support │'); |
| 68 | +console.log('└────────────────────────────────────────────────┘\n'); |
| 69 | + |
| 70 | +const frontmatterMarkdown = `--- |
| 71 | +title: Example Post |
| 72 | +date: 2024-01-01 |
| 73 | +--- |
| 74 | +
|
| 75 | +# Content |
| 76 | +
|
| 77 | +This is the actual content after frontmatter. |
| 78 | +`; |
| 79 | + |
| 80 | +const frontmatterHtml = await toHtmlWithOptions(frontmatterMarkdown, { |
| 81 | + frontmatter: true |
| 82 | +}); |
| 83 | +console.log('Input Markdown:'); |
| 84 | +console.log('```markdown'); |
| 85 | +console.log(frontmatterMarkdown.trim()); |
| 86 | +console.log('```\n'); |
| 87 | +console.log('Output HTML:'); |
| 88 | +console.log('```html'); |
| 89 | +console.log(frontmatterHtml.trim()); |
| 90 | +console.log('```'); |
| 91 | + |
| 92 | +// Example 4: Security Options |
| 93 | +console.log('\n┌────────────────────────────────────────────────┐'); |
| 94 | +console.log('│ Example 4: Security Options │'); |
| 95 | +console.log('└────────────────────────────────────────────────┘\n'); |
| 96 | + |
| 97 | +const dangerousMarkdown = ` |
| 98 | +<script>console.log('This is JavaScript');</script> |
| 99 | +
|
| 100 | +[Dangerous Link](javascript:alert('XSS')) |
| 101 | +`; |
| 102 | + |
| 103 | +console.log('Input Markdown:'); |
| 104 | +console.log('```markdown'); |
| 105 | +console.log(dangerousMarkdown.trim()); |
| 106 | +console.log('```\n'); |
| 107 | + |
| 108 | +console.log('Safe mode output (default):'); |
| 109 | +console.log('```html'); |
| 110 | +const safeHtml = await toHtmlWithOptions(dangerousMarkdown, {}); |
| 111 | +console.log(safeHtml.trim()); |
| 112 | +console.log('```\n'); |
| 113 | + |
| 114 | +console.log('Dangerous mode output (be careful!):'); |
| 115 | +console.log('```html'); |
| 116 | +const dangerousHtml = await toHtmlWithOptions(dangerousMarkdown, { |
| 117 | + allowDangerousHtml: true, |
| 118 | + allowDangerousProtocol: true |
| 119 | +}); |
| 120 | +console.log(dangerousHtml.trim()); |
| 121 | +console.log('```'); |
| 122 | + |
| 123 | +// Example 5: Combined Options |
| 124 | +console.log('\n┌────────────────────────────────────────────────┐'); |
| 125 | +console.log('│ Example 5: Combined Options (GFM + MDX) │'); |
| 126 | +console.log('└────────────────────────────────────────────────┘\n'); |
| 127 | + |
| 128 | +const combinedMarkdown = ` |
| 129 | +| GFM | MDX | |
| 130 | +|-----|-----| |
| 131 | +| Yes | Yes | |
| 132 | +
|
| 133 | +~strikethrough~ and <Component /> |
| 134 | +`; |
| 135 | + |
| 136 | +const combinedHtml = await toHtmlWithOptions(combinedMarkdown, { |
| 137 | + gfm: true, |
| 138 | + mdx: true |
| 139 | +}); |
| 140 | +console.log('Input Markdown:'); |
| 141 | +console.log('```markdown'); |
| 142 | +console.log(combinedMarkdown.trim()); |
| 143 | +console.log('```\n'); |
| 144 | +console.log('Output HTML:'); |
| 145 | +console.log('```html'); |
| 146 | +console.log(combinedHtml.trim()); |
| 147 | +console.log('```'); |
| 148 | + |
| 149 | +console.log('\n╔════════════════════════════════════════════════╗'); |
| 150 | +console.log('║ Examples Completed! ║'); |
| 151 | +console.log('╚════════════════════════════════════════════════╝\n'); |
0 commit comments