-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Output): display markdownish text
- Loading branch information
Showing
3 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/apps/client/src/components/RundownOutput/MdDisplay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { assertNever } from '@sofie-prompter-editor/shared-lib' | ||
import React, { useMemo } from 'react' | ||
import createParser from 'src/lib/mdParser' | ||
import { Node, ParentNodeBase } from 'src/lib/mdParser/astNodes' | ||
|
||
const mdParser = createParser() | ||
|
||
export function MdDisplay({ source }: { source: string }): React.ReactNode { | ||
const rootNode = useMemo(() => mdParser(source), [source]) | ||
|
||
return <MdNode content={rootNode} /> | ||
} | ||
|
||
function MdNode({ content }: { content: Node }): React.ReactNode { | ||
switch (content.type) { | ||
case 'paragraph': | ||
return <p>{renderChildren(content)}</p> | ||
case 'root': | ||
return <>{renderChildren(content)}</> | ||
case 'emphasis': | ||
return <i>{renderChildren(content)}</i> | ||
case 'strong': | ||
return <b>{renderChildren(content)}</b> | ||
case 'reverse': | ||
return React.createElement('rev', {}, renderChildren(content)) | ||
case 'text': | ||
return content.value | ||
default: | ||
assertNever(content) | ||
return null | ||
} | ||
} | ||
|
||
function renderChildren(content: ParentNodeBase): React.ReactNode { | ||
return ( | ||
<> | ||
{content.children.map((node, index) => ( | ||
<MdNode key={index + '_' + node.type} content={node} /> | ||
))} | ||
</> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/apps/client/src/components/RundownOutput/TextDisplay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function TextDisplay({ source }: { source: string }): React.ReactNode { | ||
return source.split('\n').map((paragraph, i) => <p key={paragraph + '_' + i}>{paragraph}</p>) | ||
} |