Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
declare module "prism-react-renderer" {
import * as React from 'react';

type Language =
'markup' |
'bash' |
'clike' |
'c' |
'cpp' |
'css' |
'javascript' |
'jsx' |
'coffeescript' |
'actionscript' |
'css-extr' |
'diff' |
'docker' |
'elixir' |
'erlang' |
'git' |
'go' |
'graphql' |
'handlebars' |
'haskell' |
'java' |
'json' |
'latex' |
'less' |
'makefile' |
'markdown' |
'objectivec' |
'ocaml' |
'php' |
'php-extr' |
'python' |
'reason' |
'ruby' |
'rust' |
'sass' |
'scss' |
'sql' |
'stylus' |
'swift' |
'typescript' |
'vim' |
'yaml';

type PrismGrammar = {
[key: string]: any,
}

type LanguageDict = {
[lang in Language]: PrismGrammar
}

type PrismLib = {
languages: LanguageDict,
tokenize: (code: string, grammar: PrismGrammar, language: Language) => PrismToken[]|string[],
highlight: (code: string, grammar: PrismGrammar, language: Language) => string,
}

type PrismThemeEntry = {
color?: string,
backgroundColor?: string,
fontStyle?: "normal" | "italic",
fontWeight?:
"normal" |
"bold" |
"100" |
"200" |
"300" |
"400" |
"500" |
"600" |
"700" |
"800" |
"900",
textDecorationLine?:
"none" |
"underline" |
"line-through" |
"underline line-through",
opacity?: number,
[styleKey: string]: string | number | void,
}

type PrismTheme = {
plain: PrismThemeEntry,
styles: Array<{
types: string[],
style: PrismThemeEntry,
languages?: Language[],
}>,
}

type ThemeDict = {
root: StyleObj,
plain: StyleObj,
[type: string]: StyleObj,
}

type Token = {
types: string[],
content: string,
empty?: boolean,
}

type PrismToken = {
type: string,
content: Array<PrismToken | string> | string
}

type StyleObj = {
[key: string]: string | number | null
}

type LineInputProps = {
key?: React.Key,
style?: StyleObj,
className?: string,
line: Token[],
[otherProp: string]: any
}

type LineOutputProps = {
key?: React.Key,
style?: StyleObj,
className: string,
[otherProps: string]: any
}

type TokenInputProps = {
key?: React.Key,
style?: StyleObj,
className?: string,
token: Token,
[otherProp: string]: any
}

type TokenOutputProps = {
key?: React.Key,
style?: StyleObj,
className: string,
children: string,
[otherProp: string]: any
}

type RenderProps = {
tokens: Token[][],
className: string,
style: StyleObj,
getLineProps: (input: LineInputProps) => LineOutputProps,
getTokenProps: (input: TokenInputProps) => TokenOutputProps,
}

type DefaultProps = {
Prism: PrismLib,
theme: PrismTheme,
}

interface HighlightProps {
Prism: PrismLib,
theme?: PrismTheme,
language: Language,
code: string,
children: (props: RenderProps) => React.ReactNode,
}

export default class Highlight extends React.Component<HighlightProps> {
themeDict: ThemeDict;
getLineProps: (lineInputProps: LineInputProps) => LineOutputProps;
getStyleForToken: (token: Token) => { [inlineStyle: string]: string };
getTokenProps: (tokenInputPropsL: TokenInputProps) => TokenOutputProps;
}

export const defaultProps: DefaultProps

export const Prism: PrismLib;

export {
Language,
DefaultProps,
PrismTheme,
}
}

declare module "prism-react-renderer/themes/*" {
import { PrismTheme } from 'prism-react-renderer';
const theme: PrismTheme;
export default theme;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Renders highlighted Prism output using React",
"main": "lib/index.js",
"module": "es/index.js",
"types": "./index.d.ts",
"license": "MIT",
"repository": "git@github.com:FormidableLabs/prism-react-renderer.git",
"files": [
Expand Down