Skip to content

Commit

Permalink
Merge branch 'manage' of https://github.com/VanessaScherma/DTaaS into…
Browse files Browse the repository at this point in the history
… manage
  • Loading branch information
vanessa committed Oct 14, 2024
2 parents d75e747 + c2773a8 commit d7ee4cc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/src/preview/route/digitaltwins/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function Editor({ DTName }: EditorProps) {
padding: 2,
border: '1px solid lightgray',
marginTop: 2,
width: '800px'
}}
>
{activeTab === 0 && (
Expand Down
51 changes: 48 additions & 3 deletions client/src/preview/route/digitaltwins/editor/PreviewTab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as React from 'react';
import { Remarkable } from 'remarkable';
import 'katex/dist/katex.min.css';
// @ts-expect-error: Ignoring TypeScript error due to missing type definitions for 'remarkable-katex'.
import RemarkableKatex from 'remarkable-katex';
import SyntaxHighlighter from 'react-syntax-highlighter';

interface PreviewProps {
Expand All @@ -8,13 +11,55 @@ interface PreviewProps {
}

function PreviewTab({ fileContent, fileType }: PreviewProps) {
const md = new Remarkable();

if (fileType === 'md') {
const md = new Remarkable({
html: true,
typographer: true,
}).use(RemarkableKatex);

const renderedMarkdown = md.render(fileContent);

return <div dangerouslySetInnerHTML={{ __html: renderedMarkdown }} />;
return (
<div style={{
width: '100%',
overflowWrap: 'break-word',
wordWrap: 'break-word',
whiteSpace: 'normal',
overflow: 'hidden',
}}>
<div
dangerouslySetInnerHTML={{
__html: renderedMarkdown,
}}
style={{
maxWidth: '100%',
}}
/>
<style>{`
img {
max-width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
border: 1px solid #ccc;
padding: 8px;
text-align: left;
}
th {
background-color: #f0f0f0;
}
`}</style>
</div>
);
}

if (fileType === 'json') {
return <SyntaxHighlighter language="json">{fileContent}</SyntaxHighlighter>;
}
Expand Down

0 comments on commit d7ee4cc

Please sign in to comment.