mirror of
https://github.com/bendtherules/react-to-markdown.git
synced 2026-08-18 22:03:20 +00:00
tagHandler - Handle separator, brk and strike tags + test
This commit is contained in:
@@ -207,3 +207,37 @@ test('should render pre.code tag without text', () => {
|
|||||||
) as string).trim()
|
) as string).trim()
|
||||||
).toBe('```js\n\n```');
|
).toBe('```js\n\n```');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should render hr (line separator)', () => {
|
||||||
|
expect(
|
||||||
|
(render(
|
||||||
|
<>
|
||||||
|
<p>para 1</p>
|
||||||
|
<hr />
|
||||||
|
<p>para 2</p>
|
||||||
|
</>
|
||||||
|
) as string).trim()
|
||||||
|
).toBe('para 1\n\n---\n\npara 2');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render break (br)', () => {
|
||||||
|
expect(
|
||||||
|
(render(
|
||||||
|
<p>
|
||||||
|
text 1
|
||||||
|
<br />
|
||||||
|
text 2
|
||||||
|
</p>
|
||||||
|
) as string).trim()
|
||||||
|
).toBe('text 1 \ntext 2');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render strike (strike, s, del)', () => {
|
||||||
|
expect(
|
||||||
|
(render(
|
||||||
|
<p>
|
||||||
|
This <s>is</s> some <del>text</del>
|
||||||
|
</p>
|
||||||
|
) as string).trim()
|
||||||
|
).toBe('This ~~is~~ some ~~text~~');
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
blockquote,
|
blockquote,
|
||||||
|
brk,
|
||||||
code,
|
code,
|
||||||
emphasis,
|
emphasis,
|
||||||
heading,
|
heading,
|
||||||
@@ -9,6 +10,8 @@ import {
|
|||||||
list,
|
list,
|
||||||
listItem,
|
listItem,
|
||||||
paragraph,
|
paragraph,
|
||||||
|
separator,
|
||||||
|
strike,
|
||||||
strong,
|
strong,
|
||||||
} from 'mdast-builder';
|
} from 'mdast-builder';
|
||||||
import {
|
import {
|
||||||
@@ -34,6 +37,7 @@ export default function handleTag(
|
|||||||
|
|
||||||
let childASTNode: MDASTNode | undefined;
|
let childASTNode: MDASTNode | undefined;
|
||||||
let newParentASTNode: MDASTParent | undefined;
|
let newParentASTNode: MDASTParent | undefined;
|
||||||
|
let isHandled = true;
|
||||||
|
|
||||||
switch (tagType) {
|
switch (tagType) {
|
||||||
// START - Handle paragraph
|
// START - Handle paragraph
|
||||||
@@ -73,6 +77,14 @@ export default function handleTag(
|
|||||||
break;
|
break;
|
||||||
// END - Handle strong and em
|
// END - Handle strong and em
|
||||||
|
|
||||||
|
// START - Handle strike (tags - strike, del, s)
|
||||||
|
case 'strike':
|
||||||
|
case 'del':
|
||||||
|
case 's':
|
||||||
|
newParentASTNode = childASTNode = strike();
|
||||||
|
break;
|
||||||
|
// END - Handle strike (tags - strike, del, s)
|
||||||
|
|
||||||
// START - Handle lists - ul, ol, li
|
// START - Handle lists - ul, ol, li
|
||||||
case 'ul':
|
case 'ul':
|
||||||
newParentASTNode = childASTNode = list('unordered', []);
|
newParentASTNode = childASTNode = list('unordered', []);
|
||||||
@@ -116,6 +128,20 @@ export default function handleTag(
|
|||||||
}
|
}
|
||||||
// END - Handle blockquote
|
// END - Handle blockquote
|
||||||
|
|
||||||
|
// START - Handle horizontal separator (hr)
|
||||||
|
case 'hr': {
|
||||||
|
childASTNode = separator;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// END - Handle horizontal separator (hr)
|
||||||
|
|
||||||
|
// START - Handle line break (br)
|
||||||
|
case 'br': {
|
||||||
|
childASTNode = brk;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// END - Handle line break (br)
|
||||||
|
|
||||||
// START - Handle code
|
// START - Handle code
|
||||||
case 'code': {
|
case 'code': {
|
||||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||||
|
|||||||
Reference in New Issue
Block a user