Added markdown render

This commit is contained in:
Gnarwhal 2024-09-19 19:21:58 +01:00
parent ce9a9c5915
commit 951760b619
Signed by: Gnarwhal
GPG key ID: 80DB5B37E4C96776
8 changed files with 130 additions and 47 deletions

View file

@ -5,8 +5,10 @@ import { useState, useEffect } from 'react'
import NetworkError from './types/error/network';
import ContentTypeError from './types/error/content_type';
import ImageContent from './types/image';
import MarkdownContent from './types/markdown';
import Terminal from './types/terminal';
import Text from './types/text';
import { map_to_type } from './types/text';
type ContentType<T> = {
content_type: RegExp,
@ -52,6 +54,19 @@ export default function Content({ src }: { src: string}) {
}
};
}
}, {
content_type: /application\/octet-stream/,
path: /.*\.md/i,
emit: () => {
return {
process: (response: Response) => {
return response.text();
},
postprocess: (data: string) => {
set_content(<MarkdownContent text={data} />);
}
};
}
}, {
content_type: /(text\/\w+)|(application\/octet-stream)/,
emit: () => {
@ -60,36 +75,8 @@ export default function Content({ src }: { src: string}) {
return response.text();
},
postprocess: (data: string) => {
const languages = {
// "markup",
js: "jsx",
mjs: "jsx",
jsx: "jsx",
// "js-extras",
ts: "tsx",
tsx: "tsx",
swift: "swift",
kt: "kotlin",
kts: "kotlin",
ktm: "kotlin",
// "objectivec",
// "reason",
rs: "rust",
// "graphql",
yml: "yaml",
yaml: "yaml",
go: "go",
c: "cpp",
cpp: "cpp",
cxx: "cpp",
h: "cpp",
hpp: "cpp",
hxx: "cpp",
py: "python",
json: "json",
}
const split = window.location.pathname.split('.');
set_content(<Text language={split.length == 0 ? 'none' : (languages[split[split.length - 1] as keyof typeof languages] ?? 'none')} text={data} />);
set_content(<Text language={split.length == 0 ? 'none' : map_to_type(split[split.length - 1])} text={data} line_numbers={true} />);
}
};
}