markdown-to-jsx 9.4.0 → 9.4.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 CHANGED
@@ -575,7 +575,9 @@ This approach gives you full control over which expressions are evaluated and un
575
575
 
576
576
  #### options.renderRule
577
577
 
578
- Supply your own rendering function that can selectively override how _rules_ are rendered (note, this is different than _`options.overrides`_ which operates at the HTML tag level and is more general). You can use this functionality to do pretty much anything with an established AST node; here's an example of selectively overriding the "codeBlock" rule to process LaTeX syntax using the `@matejmazur/react-katex` library:
578
+ Supply your own rendering function that can selectively override how _rules_ are rendered (note, this is different than _`options.overrides`_ which operates at the HTML tag level and is more general). The `renderRule` function always executes before any other rendering code, giving you full control over how nodes are rendered, including normally-skipped nodes like `ref`, `footnote`, and `frontmatter`.
579
+
580
+ You can use this functionality to do pretty much anything with an established AST node; here's an example of selectively overriding the "codeBlock" rule to process LaTeX syntax using the `@matejmazur/react-katex` library:
579
581
 
580
582
  ````tsx
581
583
  import Markdown, { RuleType } from 'markdown-to-jsx'
@@ -604,6 +606,29 @@ function App() {
604
606
  }
605
607
  ````
606
608
 
609
+ **Accessing parsed HTML content:** For HTML blocks marked as `verbatim` (like `<script>`, `<style>`, `<pre>`), default renderers use `rawText` for CommonMark compliance, but `renderRule` can access the fully parsed AST in `children`:
610
+
611
+ ```tsx
612
+ <Markdown
613
+ options={{
614
+ renderRule(next, node, renderChildren) {
615
+ if (node.type === RuleType.htmlBlock && node.tag === 'script') {
616
+ // Access parsed children even for verbatim blocks
617
+ const parsedContent = node.children || []
618
+ // Or use rawText for original content
619
+ const rawContent = node.rawText || ''
620
+
621
+ // Custom rendering logic here
622
+ return <CustomScript content={parsedContent} raw={rawContent} />
623
+ }
624
+ return next()
625
+ },
626
+ }}
627
+ >
628
+ <script>Hello **world**</script>
629
+ </Markdown>
630
+ ```
631
+
607
632
  #### options.sanitizer
608
633
 
609
634
  By default a lightweight URL sanitizer function is provided to avoid common attack vectors that might be placed into the `href` of an anchor tag, for example. The sanitizer receives the input, the HTML tag being targeted, and the attribute name. The original function is available as a library export called `sanitizer`.
@@ -816,11 +841,24 @@ The AST consists of the following node types (use `RuleType` to check node types
816
841
  { type: RuleType.table, header: [...], cells: [[...]], align: [...] }
817
842
  ```
818
843
  - `RuleType.htmlBlock` - HTML blocks and JSX components
844
+
819
845
  ```tsx
820
- { type: RuleType.htmlBlock, tag: "div", attrs: {}, children: [...] }
846
+ {
847
+ type: RuleType.htmlBlock,
848
+ tag: "div",
849
+ attrs: {},
850
+ rawAttrs?: string,
851
+ children?: ASTNode[],
852
+ verbatim?: boolean,
853
+ rawText?: string,
854
+ text?: string // @deprecated - use rawText instead
855
+ }
821
856
  ```
857
+
822
858
  **Note (v9.1+):** JSX components with blank lines between opening/closing tags now properly nest children instead of creating sibling nodes.
823
859
 
860
+ **HTML Block Parsing (v9.2+):** HTML blocks are always fully parsed into the `children` property, even when marked as `verbatim`. The `verbatim` flag acts as a rendering hint (default renderers use `rawText` for verbatim blocks to maintain CommonMark compliance), but `renderRule` implementations can access the fully parsed AST in `children` for all HTML blocks. The `rawText` field contains the original raw HTML content for verbatim blocks, while `rawAttrs` contains the original attribute string.
861
+
824
862
  **Inline nodes:**
825
863
 
826
864
  - `RuleType.text` - Plain text