Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frederic REY
committed
Dec 19, 2018
1 parent
6f367ef
commit ab734bb
Showing
2 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters