markdown-to-jsx 9.0.0 → 9.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/dist/html.cjs +66 -66
- package/dist/html.d.cts +38 -34
- package/dist/html.d.ts +38 -34
- package/dist/html.js +72 -72
- package/dist/html.js.map +5 -5
- package/dist/index.cjs +68 -68
- package/dist/index.d.cts +38 -34
- package/dist/index.d.ts +38 -34
- package/dist/index.js +74 -74
- package/dist/index.js.map +5 -5
- package/dist/markdown.cjs +81 -81
- package/dist/markdown.js +82 -82
- package/dist/markdown.js.map +5 -5
- package/dist/react.cjs +74 -74
- package/dist/react.d.cts +38 -34
- package/dist/react.d.ts +38 -34
- package/dist/react.js +68 -68
- package/dist/react.js.map +5 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ Some special features of the library:
|
|
|
43
43
|
- [options.sanitizer](#optionssanitizer)
|
|
44
44
|
- [options.slugify](#optionsslugify)
|
|
45
45
|
- [options.disableAutoLink](#optionsdisableautolink)
|
|
46
|
+
- [options.preserveFrontmatter](#optionspreservefrontmatter)
|
|
46
47
|
- [options.disableParsingRawHTML](#optionsdisableparsingrawhtml)
|
|
47
48
|
- [options.tagfilter](#optionstagfilter)
|
|
48
49
|
- [Syntax highlighting](#syntax-highlighting)
|
|
@@ -745,6 +746,61 @@ compiler(
|
|
|
745
746
|
</span>
|
|
746
747
|
```
|
|
747
748
|
|
|
749
|
+
#### options.preserveFrontmatter
|
|
750
|
+
|
|
751
|
+
By default, YAML frontmatter at the beginning of markdown documents is parsed but not rendered in the output. Set this option to `true` to include the frontmatter in the rendered output. For HTML/JSX output, frontmatter is rendered as a `<pre>` element. For markdown-to-markdown compilation, frontmatter is included in the output markdown.
|
|
752
|
+
|
|
753
|
+
| Compiler Type | Default Behavior | When `preserveFrontmatter: true` | When `preserveFrontmatter: false` |
|
|
754
|
+
| ------------------------ | --------------------------- | -------------------------------- | --------------------------------- |
|
|
755
|
+
| **React/HTML** | ❌ Don't render frontmatter | ✅ Render as `<pre>` element | ❌ Don't render frontmatter |
|
|
756
|
+
| **Markdown-to-Markdown** | ✅ Preserve frontmatter | ✅ Preserve frontmatter | ❌ Exclude frontmatter |
|
|
757
|
+
|
|
758
|
+
```tsx
|
|
759
|
+
<Markdown options={{ preserveFrontmatter: true }}>
|
|
760
|
+
{`---
|
|
761
|
+
title: My Document
|
|
762
|
+
author: John Doe
|
|
763
|
+
---
|
|
764
|
+
|
|
765
|
+
# Content
|
|
766
|
+
|
|
767
|
+
This is the main content.`
|
|
768
|
+
}
|
|
769
|
+
</Markdown>
|
|
770
|
+
|
|
771
|
+
// renders:
|
|
772
|
+
|
|
773
|
+
<div>
|
|
774
|
+
<pre>---
|
|
775
|
+
title: My Document
|
|
776
|
+
author: John Doe
|
|
777
|
+
---</pre>
|
|
778
|
+
<h1>Content</h1>
|
|
779
|
+
<p>This is the main content.</p>
|
|
780
|
+
</div>
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
For markdown-to-markdown compilation:
|
|
784
|
+
|
|
785
|
+
```tsx
|
|
786
|
+
import { compiler } from 'markdown-to-jsx/markdown'
|
|
787
|
+
|
|
788
|
+
const markdown = `---
|
|
789
|
+
title: My Document
|
|
790
|
+
author: John Doe
|
|
791
|
+
---
|
|
792
|
+
|
|
793
|
+
# Content`
|
|
794
|
+
|
|
795
|
+
// With preserveFrontmatter: true (default)
|
|
796
|
+
compiler(markdown, { preserveFrontmatter: true })
|
|
797
|
+
// returns: "---\ntitle: My Document\nauthor: John Doe\n---\n\n# Content"
|
|
798
|
+
|
|
799
|
+
// With preserveFrontmatter: false
|
|
800
|
+
compiler(markdown, { preserveFrontmatter: false })
|
|
801
|
+
// returns: "# Content"
|
|
802
|
+
```
|
|
803
|
+
|
|
748
804
|
#### options.disableParsingRawHTML
|
|
749
805
|
|
|
750
806
|
By default, raw HTML is parsed to JSX. This behavior can be disabled if desired.
|