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
21 changes: 2 additions & 19 deletions build/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,10 @@ export interface ContentOptions extends KatexOptions {
}
export declare function getKatexContent({ inlineStyle, expression, ...options }: ContentOptions): string;
export interface KatexProps extends ContentOptions {
style: StyleProp<ViewStyle>;
style?: StyleProp<ViewStyle>;
onLoad?: WebViewProps["onLoad"];
onError?: WebViewProps["onError"];
webviewProps?: WebViewProps;
}
declare function Katex({ style, onLoad, onError, webviewProps, ...options }: KatexProps): React.JSX.Element;
declare namespace Katex {
var defaultProps: {
expression: string;
displayMode: boolean;
throwOnError: boolean;
errorColor: string;
inlineStyle: string;
style: {
root: {
height: number;
};
};
macros: {};
colorIsTextColor: boolean;
};
}
export default Katex;
export default function Katex({ style, onLoad, onError, webviewProps, expression, displayMode, throwOnError, errorColor, inlineStyle, macros, colorIsTextColor, ...options }: KatexProps): React.JSX.Element;
export { KatexOptions, TrustContext };
25 changes: 13 additions & 12 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/katex-script.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/katex-script.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/katex-script.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
},
"homepage": "https://github.com/beedeez/react-native-katex#readme",
"dependencies": {
"@types/katex": "^0.16.7",
"react-native-webview": "11.23.1"
},
"peerDependencies": {
"react": ">=16",
"react-native": "*"
},
"devDependencies": {
"@types/katex": "^0.16.7",
"@types/react": "^18.0.9",
"@types/react-native": "^0.69",
"katex": "^0.16.11",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scripts/prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const KATEX_FONT_DIR = resolve(KATEX_DIR, 'fonts');
const SOURCE_DIR = resolve(__dirname, '../src');

const katexScriptFile = resolve(KATEX_DIR, 'katex.min.js');
const katexScript = readFileSync(katexScriptFile, 'utf8');
const mhchemScriptFile = resolve(KATEX_DIR, 'contrib/mhchem.min.js');
const katexScript = `${readFileSync(katexScriptFile, 'utf8')}\n${readFileSync(mhchemScriptFile, 'utf8')}`;
writeFileSync(resolve(SOURCE_DIR, 'katex-script.ts'), `export default ${JSON.stringify(katexScript)};`);

const katexStyleFile = resolve(KATEX_DIR, 'katex.min.css');
Expand Down
35 changes: 21 additions & 14 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,41 @@ body {
`;

export interface KatexProps extends ContentOptions {
style: StyleProp<ViewStyle>;
style?: StyleProp<ViewStyle>;
onLoad?: WebViewProps["onLoad"];
onError?: WebViewProps["onError"];
webviewProps?: WebViewProps;
}

export default function Katex({
style,
style = defaultStyle.root,
onLoad,
onError,
webviewProps,
expression = "",
displayMode = false,
throwOnError = false,
errorColor = "#f00",
inlineStyle = defaultInlineStyle,
macros = {},
colorIsTextColor = false,
...options
}: KatexProps) {
return (
<WebView
style={style}
source={{ html: getKatexContent(options) }}
source={{
html: getKatexContent({
expression,
displayMode,
throwOnError,
errorColor,
inlineStyle,
macros,
colorIsTextColor,
...options,
}),
}}
onLoad={onLoad}
onError={onError}
setBuiltInZoomControls={false}
Expand All @@ -86,15 +104,4 @@ export default function Katex({
);
}

Katex.defaultProps = {
expression: "",
displayMode: false,
throwOnError: false,
errorColor: "#f00",
inlineStyle: defaultInlineStyle,
style: defaultStyle,
macros: {},
colorIsTextColor: false,
};

export { KatexOptions, TrustContext };
Loading