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

Update index.tsx with enhanced changes #334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
116 changes: 38 additions & 78 deletions src/components/mathpix-markdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,47 @@

import * as React from 'react';
import {
MathpixMarkdownModel as MM,
optionsMathpixMarkdown,
TMarkdownItOptions,
ParserErrors
} from '../../mathpix-markdown-model';
import { MathpixMarkdownModel as MM, optionsMathpixMarkdown, TMarkdownItOptions, ParserErrors } from '../../mathpix-markdown-model';
import { eMmdRuleType } from "../../markdown/common/mmdRules";
import { getDisableRuleTypes } from "../../markdown/common/mmdRulesToDisable";


export interface MathpixMarkdownProps extends optionsMathpixMarkdown{
export interface MathpixMarkdownProps extends optionsMathpixMarkdown {
text: string;
}

class MathpixMarkdown extends React.Component<MathpixMarkdownProps> {
render() {
const { text, alignMathBlock='center', display='block', isCheckFormula=false, showTimeLog=false,isDisableFancy=false,
isDisableEmoji = false, isDisableEmojiShortcuts = false, isDisableRefs = false, isDisableFootnotes = false,
htmlTags=false, width=0, breaks=true, typographer=false, linkify=false, xhtmlOut=false,
outMath={}, mathJax={}, htmlSanitize = {}, smiles = {}, openLinkInNewWindow = true,
enableFileLinks = false, validateLink = null,
accessibility = null,
nonumbers = false,
showPageBreaks = false,
centerImages = true,
centerTables = true,
enableCodeBlockRuleForLatexCommands = false,
addPositionsToTokens = false,
highlights = [],
parserErrors = ParserErrors.show,
codeHighlight = {},
footnotes = {},
copyToClipboard = false,
renderOptions = null,
previewUuid = ""
} = this.props;
const disableRules = isDisableFancy ? MM.disableFancyArrayDef : this.props.disableRules || [];
const disableRuleTypes: eMmdRuleType[] = renderOptions ? getDisableRuleTypes(renderOptions) : [];
const markdownItOptions: TMarkdownItOptions = {
isDisableFancy: isDisableFancy,
isDisableEmoji: isDisableEmoji,
isDisableEmojiShortcuts: isDisableEmojiShortcuts,
isDisableRefs: isDisableRefs,
isDisableFootnotes: isDisableFootnotes,
disableRules: disableRules,
htmlTags: htmlTags && !disableRuleTypes.includes(eMmdRuleType.html),
xhtmlOut: xhtmlOut,
breaks: breaks,
typographer: typographer,
linkify: linkify,
width: width,
outMath: outMath,
mathJax: mathJax,
htmlSanitize: htmlSanitize,
smiles: smiles,
openLinkInNewWindow: openLinkInNewWindow,
enableFileLinks: enableFileLinks,
validateLink: validateLink,
accessibility: accessibility,
nonumbers: nonumbers,
showPageBreaks: showPageBreaks,
centerImages: centerImages,
centerTables: centerTables,
enableCodeBlockRuleForLatexCommands: enableCodeBlockRuleForLatexCommands,
addPositionsToTokens: addPositionsToTokens,
highlights: highlights,
parserErrors: parserErrors,
codeHighlight: codeHighlight,
footnotes: footnotes,
copyToClipboard: copyToClipboard,
renderOptions: renderOptions,
previewUuid: previewUuid
};
const MathpixMarkdown: React.FC<MathpixMarkdownProps> = ({
text,
alignMathBlock = 'center',
display = 'block',
isCheckFormula = false,
showTimeLog = false,
isDisableFancy = false,
disableRules,
renderOptions,
...rest
}) => {
const effectiveDisableRules = isDisableFancy ? MM.disableFancyArrayDef : disableRules || [];
const disableRuleTypes: eMmdRuleType[] = renderOptions ? getDisableRuleTypes(renderOptions) : [];

const markdownItOptions: TMarkdownItOptions = {
isDisableFancy,
disableRules: effectiveDisableRules,
htmlTags: rest.htmlTags && !disableRuleTypes.includes(eMmdRuleType.html),
renderOptions,
...rest
};

MM.setOptions(effectiveDisableRules, isCheckFormula, showTimeLog);

return (
<div id='preview' style={{justifyContent: alignMathBlock, padding: '10px', overflowY: 'auto', willChange: 'transform'}}>
<div id='container-ruller' />
<div
id='setText'
style={{display, justifyContent: 'inherit'}}
dangerouslySetInnerHTML={{ __html: MM.convertToHTML(text, markdownItOptions) }}
/>
</div>
);
};

MM.setOptions(disableRules, isCheckFormula, showTimeLog);
return (
<div id='preview' style={{justifyContent: alignMathBlock, padding: '10px', overflowY: 'auto', willChange: 'transform'}}>
<div id='container-ruller'></div>
<div id='setText' style={{display: display, justifyContent: 'inherit'}}
dangerouslySetInnerHTML={{ __html: MM.convertToHTML(text, markdownItOptions)}}
/>
</div>
);
}
}
export default MathpixMarkdown;