mirror of
https://github.com/bendtherules/react-to-markdown.git
synced 2026-08-18 13:53:11 +00:00
tagHandler - Handle paragraph tag + basic test
This commit is contained in:
@@ -38,6 +38,10 @@ test('should render plain text with simple Class Component', () => {
|
|||||||
expect((render(<TestComponent />) as string).trim()).toBe('abcd');
|
expect((render(<TestComponent />) as string).trim()).toBe('abcd');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should render paragraph with plain text', () => {
|
||||||
|
expect((render(<p>abcd</p>) as string).trim()).toBe('abcd');
|
||||||
|
});
|
||||||
|
|
||||||
test('should render plain h1 with text', () => {
|
test('should render plain h1 with text', () => {
|
||||||
expect((render(<h1>abcd</h1>) as string).trim()).toBe('# abcd');
|
expect((render(<h1>abcd</h1>) as string).trim()).toBe('# abcd');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
link,
|
link,
|
||||||
list,
|
list,
|
||||||
listItem,
|
listItem,
|
||||||
|
paragraph,
|
||||||
strong,
|
strong,
|
||||||
} from 'mdast-builder';
|
} from 'mdast-builder';
|
||||||
import { AnchorHTMLAttributes, ImgHTMLAttributes } from 'react';
|
import { AnchorHTMLAttributes, ImgHTMLAttributes } from 'react';
|
||||||
@@ -24,6 +25,13 @@ export default function handleTag(
|
|||||||
let newParentASTNode: MDASTParent | undefined;
|
let newParentASTNode: MDASTParent | undefined;
|
||||||
|
|
||||||
switch (tagType) {
|
switch (tagType) {
|
||||||
|
// START - Handle paragraph
|
||||||
|
case 'p': {
|
||||||
|
newParentASTNode = childASTNode = paragraph();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// END - Handle paragraph
|
||||||
|
|
||||||
// START - Handle all headings
|
// START - Handle all headings
|
||||||
case 'h1':
|
case 'h1':
|
||||||
newParentASTNode = childASTNode = heading(1);
|
newParentASTNode = childASTNode = heading(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user