aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/renderers/Code.js
blob: 12efc67418b4e5b915fcb850ba5bdfe6181136bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';
import styled from 'styled-components'
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
import { atomOneLight, ascetic, atomOneDark, dracula, ocean } from 'react-syntax-highlighter/dist/esm/styles/hljs';

export const THEMES = Object.freeze({
    'atom': atomOneLight,
    'atom dark': atomOneDark,
    'plain': ascetic,
    'dracula': dracula,
    'ocean': ocean,
})

export const LANGS = Object.freeze({
    'go': 'go',
    'python': 'python',
    'javascript': 'javascript',
    'html': 'html',
    'css': 'css',
    'c': 'c',
    'c++': 'cpp',
    'c#': 'cs',
    'ruby': 'ruby',
    'docker': 'dockerfile',
    'bash': 'bash',
    'raw': 'text',
    'java': 'java',
    'lisp': 'lisp',
    'haskell': 'haskell',
    'scala': 'scala',
    'markdown': 'markdown',
    'makefile': 'makefile',
    'php': 'php',
    'latex': 'latex',
    'yaml': 'yaml'
})

const RelPositioning = styled.div`
    position: relative; 
`

const CodeRenderer = (props) => {
    return (
        <RelPositioning>
            <SyntaxHighlighter
                className="codeBlock lt-shadow"
                language={props.lang}
                style={THEMES[props.theme]}
                showLineNumbers >
                {props.content}
            </SyntaxHighlighter>
        </RelPositioning>
    );
};

export default CodeRenderer