Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

fix: type annotations in markdown (#1150)

Aakash4bc033babd5a
diff --git a/packages/ui/src/components/markdown.tsx b/packages/ui/src/components/markdown.tsx
index 93f0aefe..78a79fde 100644
--- a/packages/ui/src/components/markdown.tsx
+++ b/packages/ui/src/components/markdown.tsx
@@ -1,18 +1,16 @@
'use client';
import ReactMarkdown from 'react-markdown';
-import { PrismAsyncLight as SyntaxHighlighter } from 'react-syntax-highlighter';
+import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import remarkGfm from 'remark-gfm';
-import { vs, vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
+import { vscDarkPlus } from '../themes/vs-dark-plus';
+import { vs } from '../themes/vs';
import clsx from 'clsx';
import { visit, SKIP, type BuildVisitor } from 'unist-util-visit';
import type { Transformer } from 'unified';
import { useTheme } from 'next-themes';
-import typescript from 'react-syntax-highlighter/dist/esm/languages/prism/typescript';
import rehypeRaw from 'rehype-raw';
-SyntaxHighlighter.registerLanguage('typescript', typescript);
-
const HTML_COMMENT_REGEX = new RegExp('<!--([\\s\\S]*?)-->', 'g');
/**
diff --git a/packages/ui/src/themes/vs-dark-plus.ts b/packages/ui/src/themes/vs-dark-plus.ts
new file mode 100644
index 00000000..47c203ba
--- /dev/null
+++ b/packages/ui/src/themes/vs-dark-plus.ts
@@ -0,0 +1,286 @@
+export const vscDarkPlus: Record<string, React.CSSProperties> = {
+ 'pre[class*="language-"]': {
+ color: '#d4d4d4',
+ fontSize: '13px',
+ textShadow: 'none',
+ fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
+ direction: 'ltr',
+ textAlign: 'left',
+ whiteSpace: 'pre',
+ wordSpacing: 'normal',
+ wordBreak: 'normal',
+ lineHeight: '1.5',
+ MozTabSize: '4',
+ OTabSize: '4',
+ tabSize: '4',
+ WebkitHyphens: 'none',
+ MozHyphens: 'none',
+ msHyphens: 'none',
+ hyphens: 'none',
+ padding: '1em',
+ margin: '.5em 0',
+ overflow: 'auto',
+ background: '#1e1e1e',
+ },
+ 'code[class*="language-"]': {
+ color: '#d4d4d4',
+ fontSize: '13px',
+ textShadow: 'none',
+ fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
+ direction: 'ltr',
+ textAlign: 'left',
+ whiteSpace: 'pre',
+ wordSpacing: 'normal',
+ wordBreak: 'normal',
+ lineHeight: '1.5',
+ MozTabSize: '4',
+ OTabSize: '4',
+ tabSize: '4',
+ WebkitHyphens: 'none',
+ MozHyphens: 'none',
+ msHyphens: 'none',
+ hyphens: 'none',
+ },
+ 'pre[class*="language-"]::selection': {
+ textShadow: 'none',
+ background: '#264F78',
+ },
+ 'code[class*="language-"]::selection': {
+ textShadow: 'none',
+ background: '#264F78',
+ },
+ 'pre[class*="language-"] *::selection': {
+ textShadow: 'none',
+ background: '#264F78',
+ },
+ 'code[class*="language-"] *::selection': {
+ textShadow: 'none',
+ background: '#264F78',
+ },
+ ':not(pre) > code[class*="language-"]': {
+ padding: '.1em .3em',
+ borderRadius: '.3em',
+ color: '#db4c69',
+ background: '#1e1e1e',
+ },
+ '.namespace': {
+ opacity: '.7',
+ },
+ 'doctype.doctype-tag': {
+ color: '#569CD6',
+ },
+ 'doctype.name': {
+ color: '#9cdcfe',
+ },
+ comment: {
+ color: '#6a9955',
+ },
+ prolog: {
+ color: '#6a9955',
+ },
+ punctuation: {
+ color: '#d4d4d4',
+ },
+ 'type-annotation': {
+ color: '#00008b', // dark blue
+ },
+ '.language-html .language-css .token.punctuation': {
+ color: '#d4d4d4',
+ },
+ '.language-html .language-javascript .token.punctuation': {
+ color: '#d4d4d4',
+ },
+ property: {
+ color: '#9cdcfe',
+ },
+ tag: {
+ color: '#569cd6',
+ },
+ boolean: {
+ color: '#569cd6',
+ },
+ number: {
+ color: '#b5cea8',
+ },
+ constant: {
+ color: '#9cdcfe',
+ },
+ symbol: {
+ color: '#b5cea8',
+ },
+ inserted: {
+ color: '#b5cea8',
+ },
+ unit: {
+ color: '#b5cea8',
+ },
+ selector: {
+ color: '#d7ba7d',
+ },
+ 'attr-name': {
+ color: '#9cdcfe',
+ },
+ string: {
+ color: '#ce9178',
+ },
+ char: {
+ color: '#ce9178',
+ },
+ builtin: {
+ color: '#569cd6',
+ },
+ deleted: {
+ color: '#ce9178',
+ },
+ '.language-css .token.string.url': {
+ textDecoration: 'underline',
+ },
+ operator: {
+ color: '#d4d4d4',
+ },
+ entity: {
+ color: '#569cd6',
+ },
+ 'operator.arrow': {
+ color: '#569CD6',
+ },
+ atrule: {
+ color: '#ce9178',
+ },
+ 'atrule.rule': {
+ color: '#c586c0',
+ },
+ 'atrule.url': {
+ color: '#9cdcfe',
+ },
+ 'atrule.url.function': {
+ color: '#dcdcaa',
+ },
+ 'atrule.url.punctuation': {
+ color: '#d4d4d4',
+ },
+ keyword: {
+ color: '#569CD6',
+ },
+ 'keyword.module': {
+ color: '#c586c0',
+ },
+ 'keyword.control-flow': {
+ color: '#c586c0',
+ },
+ function: {
+ color: '#dcdcaa',
+ },
+ 'function.maybe-class-name': {
+ color: '#dcdcaa',
+ },
+ regex: {
+ color: '#d16969',
+ },
+ important: {
+ color: '#569cd6',
+ },
+ italic: {
+ fontStyle: 'italic',
+ },
+ 'class-name': {
+ color: '#4ec9b0',
+ },
+ 'maybe-class-name': {
+ color: '#4ec9b0',
+ },
+ console: {
+ color: '#9cdcfe',
+ },
+ parameter: {
+ color: '#9cdcfe',
+ },
+
+ interpolation: {
+ color: '#9cdcfe',
+ },
+ 'punctuation.interpolation-punctuation': {
+ color: '#569cd6',
+ },
+ variable: {
+ color: '#9cdcfe',
+ },
+ 'imports.maybe-class-name': {
+ color: '#9cdcfe',
+ },
+ 'exports.maybe-class-name': {
+ color: '#9cdcfe',
+ },
+ escape: {
+ color: '#d7ba7d',
+ },
+ 'tag.punctuation': {
+ color: '#808080',
+ },
+ cdata: {
+ color: '#808080',
+ },
+ 'attr-value': {
+ color: '#ce9178',
+ },
+ 'attr-value.punctuation': {
+ color: '#ce9178',
+ },
+ 'attr-value.punctuation.attr-equals': {
+ color: '#d4d4d4',
+ },
+ namespace: {
+ color: '#4ec9b0',
+ },
+ 'pre[class*="language-javascript"]': {
+ color: '#9cdcfe',
+ },
+ 'code[class*="language-javascript"]': {
+ color: '#9cdcfe',
+ },
+ 'pre[class*="language-jsx"]': {
+ color: '#9cdcfe',
+ },
+ 'code[class*="language-jsx"]': {
+ color: '#9cdcfe',
+ },
+ 'pre[class*="language-typescript"]': {
+ color: '#9cdcfe',
+ },
+ 'code[class*="language-typescript"]': {
+ color: '#9cdcfe',
+ },
+ 'pre[class*="language-tsx"]': {
+ color: '#9cdcfe',
+ },
+ 'code[class*="language-tsx"]': {
+ color: '#9cdcfe',
+ },
+ 'pre[class*="language-css"]': {
+ color: '#ce9178',
+ },
+ 'code[class*="language-css"]': {
+ color: '#ce9178',
+ },
+ 'pre[class*="language-html"]': {
+ color: '#d4d4d4',
+ },
+ 'code[class*="language-html"]': {
+ color: '#d4d4d4',
+ },
+ '.language-regex .token.anchor': {
+ color: '#dcdcaa',
+ },
+ '.language-html .token.punctuation': {
+ color: '#808080',
+ },
+ 'pre[class*="language-"] > code[class*="language-"]': {
+ position: 'relative',
+ zIndex: '1',
+ },
+ '.line-highlight.line-highlight': {
+ background: '#f7ebc6',
+ boxShadow: 'inset 5px 0 0 #f7d87c',
+ zIndex: '0',
+ },
+};
diff --git a/packages/ui/src/themes/vs.ts b/packages/ui/src/themes/vs.ts
new file mode 100644
index 00000000..22a72b48
--- /dev/null
+++ b/packages/ui/src/themes/vs.ts
@@ -0,0 +1,212 @@
+export const vs: Record<string, React.CSSProperties> = {
+ 'code[class*="language-"]': {
+ color: '#393A34',
+ fontFamily: '"Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace',
+ direction: 'ltr',
+ textAlign: 'left',
+ whiteSpace: 'pre',
+ wordSpacing: 'normal',
+ wordBreak: 'normal',
+ fontSize: '.9em',
+ lineHeight: '1.2em',
+ MozTabSize: '4',
+ OTabSize: '4',
+ tabSize: '4',
+ WebkitHyphens: 'none',
+ MozHyphens: 'none',
+ msHyphens: 'none',
+ hyphens: 'none',
+ },
+ 'pre[class*="language-"]': {
+ color: '#393A34',
+ fontFamily: '"Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace',
+ direction: 'ltr',
+ textAlign: 'left',
+ whiteSpace: 'pre',
+ wordSpacing: 'normal',
+ wordBreak: 'normal',
+ fontSize: '.9em',
+ lineHeight: '1.2em',
+ MozTabSize: '4',
+ OTabSize: '4',
+ tabSize: '4',
+ WebkitHyphens: 'none',
+ MozHyphens: 'none',
+ msHyphens: 'none',
+ hyphens: 'none',
+ padding: '1em',
+ margin: '.5em 0',
+ overflow: 'auto',
+ border: '1px solid #dddddd',
+ backgroundColor: 'white',
+ },
+ 'pre > code[class*="language-"]': {
+ fontSize: '1em',
+ },
+ 'pre[class*="language-"]::-moz-selection': {
+ background: '#C1DEF1',
+ },
+ 'pre[class*="language-"] ::-moz-selection': {
+ background: '#C1DEF1',
+ },
+ 'code[class*="language-"]::-moz-selection': {
+ background: '#C1DEF1',
+ },
+ 'code[class*="language-"] ::-moz-selection': {
+ background: '#C1DEF1',
+ },
+ 'pre[class*="language-"]::selection': {
+ background: '#C1DEF1',
+ },
+ 'pre[class*="language-"] ::selection': {
+ background: '#C1DEF1',
+ },
+ 'code[class*="language-"]::selection': {
+ background: '#C1DEF1',
+ },
+ 'code[class*="language-"] ::selection': {
+ background: '#C1DEF1',
+ },
+ ':not(pre) > code[class*="language-"]': {
+ padding: '.2em',
+ paddingTop: '1px',
+ paddingBottom: '1px',
+ background: '#f8f8f8',
+ border: '1px solid #dddddd',
+ },
+ comment: {
+ color: '#008000',
+ fontStyle: 'italic',
+ },
+ prolog: {
+ color: '#008000',
+ fontStyle: 'italic',
+ },
+ doctype: {
+ color: '#008000',
+ fontStyle: 'italic',
+ },
+ cdata: {
+ color: '#008000',
+ fontStyle: 'italic',
+ },
+ namespace: {
+ opacity: '.7',
+ },
+ string: {
+ color: '#A31515',
+ },
+ punctuation: {
+ color: '#393A34',
+ },
+ operator: {
+ color: '#393A34',
+ },
+ url: {
+ color: '#36acaa',
+ },
+ symbol: {
+ color: '#36acaa',
+ },
+ number: {
+ color: '#36acaa',
+ },
+ boolean: {
+ color: '#36acaa',
+ },
+ variable: {
+ color: '#36acaa',
+ },
+ constant: {
+ color: '#36acaa',
+ },
+ inserted: {
+ color: '#36acaa',
+ },
+ atrule: {
+ color: '#0000ff',
+ },
+ keyword: {
+ color: '#0000ff',
+ },
+ 'attr-value': {
+ color: '#0000ff',
+ },
+ '.language-autohotkey .token.selector': {
+ color: '#0000ff',
+ },
+ '.language-json .token.boolean': {
+ color: '#0000ff',
+ },
+ '.language-json .token.number': {
+ color: '#0000ff',
+ },
+ 'code[class*="language-css"]': {
+ color: '#0000ff',
+ },
+ function: {
+ color: '#393A34',
+ },
+ deleted: {
+ color: '#9a050f',
+ },
+ '.language-autohotkey .token.tag': {
+ color: '#9a050f',
+ },
+ selector: {
+ color: '#800000',
+ },
+ '.language-autohotkey .token.keyword': {
+ color: '#00009f',
+ },
+ important: {
+ color: '#e90',
+ fontWeight: 'bold',
+ },
+ bold: {
+ fontWeight: 'bold',
+ },
+ italic: {
+ fontStyle: 'italic',
+ },
+ 'class-name': {
+ color: '#2B91AF',
+ },
+ '.language-json .token.property': {
+ color: '#2B91AF',
+ },
+ tag: {
+ color: '#800000',
+ },
+ 'attr-name': {
+ color: '#ff0000',
+ },
+ property: {
+ color: '#ff0000',
+ },
+ regex: {
+ color: '#ff0000',
+ },
+ entity: {
+ color: '#ff0000',
+ },
+ builtin: {
+ color: '#0000ff',
+ },
+ 'directive.tag.tag': {
+ background: '#ffff00',
+ color: '#393A34',
+ },
+ '.token': {
+ color: '#008080',
+ },
+ '.line-numbers.line-numbers .line-numbers-rows': {
+ borderRightColor: '#a5a5a5',
+ },
+ '.line-numbers .line-numbers-rows > span:before': {
+ color: '#2B91AF',
+ },
+ '.line-highlight.line-highlight': {
+ background: 'linear-gradient(to right, rgba(193, 222, 241, 0.2) 70%, rgba(221, 222, 241, 0))',
+ },
+};