mirror of
https://github.com/bendtherules/react-to-markdown.git
synced 2026-08-18 22:03:20 +00:00
tagHandler - Handle h2 to h5 tags + tests
This commit is contained in:
@@ -38,10 +38,26 @@ 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 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');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should render plain h2 with text', () => {
|
||||||
|
expect((render(<h2>abcd</h2>) as string).trim()).toBe('## abcd');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render plain h3 with text', () => {
|
||||||
|
expect((render(<h3>abcd</h3>) as string).trim()).toBe('### abcd');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render plain h4 with text', () => {
|
||||||
|
expect((render(<h4>abcd</h4>) as string).trim()).toBe('#### abcd');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render plain h5 with text', () => {
|
||||||
|
expect((render(<h5>abcd</h5>) as string).trim()).toBe('##### abcd');
|
||||||
|
});
|
||||||
|
|
||||||
test('should render plain strong with text', () => {
|
test('should render plain strong with text', () => {
|
||||||
expect((render(<strong>abcd</strong>) as string).trim()).toBe('**abcd**');
|
expect((render(<strong>abcd</strong>) as string).trim()).toBe('**abcd**');
|
||||||
});
|
});
|
||||||
|
|||||||
+15
-1
@@ -1,4 +1,4 @@
|
|||||||
import { heading } from 'mdast-builder';
|
import { heading, strong, emphasis } from 'mdast-builder';
|
||||||
// tslint:disable-next-line: no-implicit-dependencies
|
// tslint:disable-next-line: no-implicit-dependencies
|
||||||
import { Node as MDASTNode, Parent as MDASTParent } from 'unist';
|
import { Node as MDASTNode, Parent as MDASTParent } from 'unist';
|
||||||
import { IReactElementSubset } from './helpers';
|
import { IReactElementSubset } from './helpers';
|
||||||
@@ -13,9 +13,23 @@ export default function handleTag(
|
|||||||
let newParentASTNode: MDASTParent | undefined;
|
let newParentASTNode: MDASTParent | undefined;
|
||||||
|
|
||||||
switch (tagType) {
|
switch (tagType) {
|
||||||
|
// START - Handle all headings
|
||||||
case 'h1':
|
case 'h1':
|
||||||
newParentASTNode = childASTNode = heading(1);
|
newParentASTNode = childASTNode = heading(1);
|
||||||
break;
|
break;
|
||||||
|
case 'h2':
|
||||||
|
newParentASTNode = childASTNode = heading(2);
|
||||||
|
break;
|
||||||
|
case 'h3':
|
||||||
|
newParentASTNode = childASTNode = heading(3);
|
||||||
|
break;
|
||||||
|
case 'h4':
|
||||||
|
newParentASTNode = childASTNode = heading(4);
|
||||||
|
break;
|
||||||
|
case 'h5':
|
||||||
|
newParentASTNode = childASTNode = heading(5);
|
||||||
|
break;
|
||||||
|
// END - Handle all headings
|
||||||
|
|
||||||
case 'strong':
|
case 'strong':
|
||||||
newParentASTNode = childASTNode = strong();
|
newParentASTNode = childASTNode = strong();
|
||||||
|
|||||||
Reference in New Issue
Block a user