CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/components/markdown.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { HTML } from "./html";
7
import { markdown_to_html } from "../markdown";
8
import { Props as HTMLProps } from "./html";
9
10
type Props = HTMLProps & {
11
// inject data attributes with line numbers to enable reverse search:
12
line_numbers?: boolean;
13
};
14
15
export function Markdown(props: Props) {
16
function to_html() {
17
if (!props.value) {
18
return;
19
}
20
return markdown_to_html(props.value, {
21
line_numbers: props.line_numbers,
22
});
23
}
24
25
return (
26
<HTML
27
id={props.id}
28
auto_render_math={true}
29
preProcessMath={false}
30
value={to_html()}
31
style={props.style}
32
project_id={props.project_id}
33
file_path={props.file_path}
34
className={props.className}
35
href_transform={props.href_transform}
36
post_hook={props.post_hook}
37
safeHTML={props.safeHTML ?? true}
38
reload_images={props.reload_images}
39
smc_image_scaling={props.smc_image_scaling}
40
highlight_code={props.highlight_code ?? true}
41
content_editable={props.content_editable}
42
onClick={props.onClick}
43
onDoubleClick={props.onDoubleClick}
44
/>
45
);
46
}
47
48