Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix token aliases and upgrade Prism #33

Merged
merged 5 commits into from
Apr 26, 2019
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
263 changes: 127 additions & 136 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,169 +1,164 @@
declare module "prism-react-renderer" {
import * as React from 'react';
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';
| "markup"
| "bash"
| "clike"
| "c"
| "cpp"
| "css"
| "javascript"
| "jsx"
| "coffeescript"
| "actionscript"
| "css-extr"
| "diff"
| "git"
| "go"
| "graphql"
| "handlebars"
| "json"
| "less"
| "makefile"
| "markdown"
| "objectivec"
| "ocaml"
| "python"
| "reason"
| "sass"
| "scss"
| "sql"
| "stylus"
| "typescript"
| "wasm"
| "yaml";

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

type LanguageDict = {
[lang in Language]: PrismGrammar
}
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,
}
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",
color?: string;
backgroundColor?: string;
fontStyle?: "normal" | "italic";
fontWeight?:
"normal" |
"bold" |
"100" |
"200" |
"300" |
"400" |
"500" |
"600" |
"700" |
"800" |
"900",
| "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,
}
| "none"
| "underline"
| "line-through"
| "underline line-through";
opacity?: number;
[styleKey: string]: string | number | void;
};

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

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

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

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

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

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

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

type TokenInputProps = {
key?: React.Key,
style?: StyleObj,
className?: string,
token: Token,
[otherProp: string]: any
}
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
}
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,
}
tokens: Token[][];
className: string;
style: StyleObj;
getLineProps: (input: LineInputProps) => LineOutputProps;
getTokenProps: (input: TokenInputProps) => TokenOutputProps;
};

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

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

export default class Highlight extends React.Component<HighlightProps> {
Expand All @@ -173,19 +168,15 @@ declare module "prism-react-renderer" {
getTokenProps: (tokenInputPropsL: TokenInputProps) => TokenOutputProps;
}

export const defaultProps: DefaultProps
export const defaultProps: DefaultProps;

export const Prism: PrismLib;

export {
Language,
DefaultProps,
PrismTheme,
}
export { Language, DefaultProps, PrismTheme };
}

declare module "prism-react-renderer/themes/*" {
import { PrismTheme } from 'prism-react-renderer';
import { PrismTheme } from "prism-react-renderer";
const theme: PrismTheme;
export default theme;
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
},
"lint-staged": {
"linters": {
"*.ts": [
"prettier --write",
"git add"
],
"{src,themes}/**/*.js": [
"jest --bail --findRelatedTests",
"flow focus-check",
Expand Down Expand Up @@ -59,7 +63,7 @@
"lint-staged": "^8.1.4",
"npm-run-all": "^4.1.5",
"prettier": "^1.16.4",
"prismjs": "^1.15.0",
"prismjs": "^1.16.0",
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-testing-library": "^6.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ exports[`<Highlight /> snapshots renders correctly 1`] = `
&lt;
</span>
<span
class="token tag"
class="token tag class-name"
style="color: rgb(224, 145, 66);"
>
App
Expand Down
3 changes: 2 additions & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type LanguagesDict = {
};

export type PrismToken = {
type: string,
type: string | string[],
alias: string | string[],
content: Array<PrismToken | string> | string
};

Expand Down
Loading