From 2730df919a2aa6a0b672cb3eba9322c4cdae8f50 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sun, 22 Dec 2019 19:51:25 +0530 Subject: [PATCH] tagHandler - Handle separator, brk and strike tags + test --- __tests__/renderer-spec.tsx | 34 ++++++++++++++++++++++++++++++++++ src/tagHandler.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/__tests__/renderer-spec.tsx b/__tests__/renderer-spec.tsx index 325b810..673ab33 100644 --- a/__tests__/renderer-spec.tsx +++ b/__tests__/renderer-spec.tsx @@ -207,3 +207,37 @@ test('should render pre.code tag without text', () => { ) as string).trim() ).toBe('```js\n\n```'); }); + +test('should render hr (line separator)', () => { + expect( + (render( + <> +

para 1

+
+

para 2

+ + ) as string).trim() + ).toBe('para 1\n\n---\n\npara 2'); +}); + +test('should render break (br)', () => { + expect( + (render( +

+ text 1 +
+ text 2 +

+ ) as string).trim() + ).toBe('text 1 \ntext 2'); +}); + +test('should render strike (strike, s, del)', () => { + expect( + (render( +

+ This is some text +

+ ) as string).trim() + ).toBe('This ~~is~~ some ~~text~~'); +}); diff --git a/src/tagHandler.ts b/src/tagHandler.ts index cdd1e9c..1ffa689 100644 --- a/src/tagHandler.ts +++ b/src/tagHandler.ts @@ -1,5 +1,6 @@ import { blockquote, + brk, code, emphasis, heading, @@ -9,6 +10,8 @@ import { list, listItem, paragraph, + separator, + strike, strong, } from 'mdast-builder'; import { @@ -34,6 +37,7 @@ export default function handleTag( let childASTNode: MDASTNode | undefined; let newParentASTNode: MDASTParent | undefined; + let isHandled = true; switch (tagType) { // START - Handle paragraph @@ -73,6 +77,14 @@ export default function handleTag( break; // 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 case 'ul': newParentASTNode = childASTNode = list('unordered', []); @@ -116,6 +128,20 @@ export default function handleTag( } // 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 case 'code': { // tslint:disable-next-line: no-object-literal-type-assertion