Skip to content

Commit

Permalink
Merge branch 'master' of github.com:source-academy/cadet-frontend int…
Browse files Browse the repository at this point in the history
…o urls

# Conflicts:
#	src/features/sicp/parser/ParseJson.tsx
#	src/features/sicp/parser/__tests__/__snapshots__/ParseJson.tsx.snap
  • Loading branch information
samuelfangjw committed Jun 16, 2021
2 parents bd9cf8c + a617212 commit f0ef1b6
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 259 deletions.
8 changes: 5 additions & 3 deletions src/features/sicp/SourceTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* Source Theme for use with react-syntax-highlighter.
* Tries to match the Source Theme for Ace Editor in js-slang
*/
const SourceThemeBackground = '#2c3e50';

export const SourceTheme = {
'code[class*="language-"]': {
color: 'white',
background: '#2c3e50',
background: SourceThemeBackground,
fontFamily: "'Inconsolata', 'Consolas', monospace",
textAlign: 'left',
whiteSpace: 'pre',
Expand All @@ -24,7 +26,7 @@ export const SourceTheme = {
},
'pre[class*="language-"]': {
color: 'white',
background: '#2c3e50',
background: SourceThemeBackground,
fontFamily: "'Inconsolata', 'Consolas', monospace",
textAlign: 'left',
whiteSpace: 'pre',
Expand All @@ -45,7 +47,7 @@ export const SourceTheme = {
borderRadius: '0.3em'
},
':not(pre) > code[class*="language-"]': {
background: '#2c3e50',
background: SourceThemeBackground,
padding: '0.1em',
borderRadius: '0.3em',
whiteSpace: 'normal'
Expand Down
30 changes: 11 additions & 19 deletions src/features/sicp/parser/ParseJson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const handleFigure = (obj: JsonType, refs: React.MutableRefObject<{}>) => (
<div ref={ref => (refs.current[obj['id']!] = ref)} className="sicp-figure">
{handleImage(obj, refs)}
{obj['captionName'] && (
<h5>
<h5 className="sicp-caption">
{obj['captionName']}
{parseArr(obj['captionBody']!, refs)}
</h5>
Expand All @@ -127,13 +127,11 @@ const handleFigure = (obj: JsonType, refs: React.MutableRefObject<{}>) => (
const handleImage = (obj: JsonType, refs: React.MutableRefObject<{}>) => {
if (obj['src']) {
return (
<div className={'sicp-figure'}>
<img
src={Constants.interactiveSicpDataUrl + obj['src']}
alt={obj['id']}
width={obj['scale']}
/>
</div>
<img
src={Constants.interactiveSicpDataUrl + obj['src']}
alt={obj['id']}
width={obj['scale']}
/>
);
} else if (obj['snippet']) {
return processingFunctions['SNIPPET'](obj['snippet'], refs);
Expand Down Expand Up @@ -173,6 +171,10 @@ const handleContainer = (obj: JsonType, refs: React.MutableRefObject<{}>) => {
);
};

const handleReference = (obj: JsonType, refs: React.MutableRefObject<{}>) => {
return <div>{parseArr(obj['child']!, refs)}</div>;
};

const handleText = (text: string) => {
return <p>{text}</p>;
};
Expand Down Expand Up @@ -219,19 +221,13 @@ export const processingFunctions = {

LaTeX: (_obj: JsonType, _refs: React.MutableRefObject<{}>) => handleText('LaTeX'),

MATTER: handleContainer,

META: (obj: JsonType, _refs: React.MutableRefObject<{}>) => <em>{obj['body']}</em>,

METAPHRASE: (obj: JsonType, _refs: React.MutableRefObject<{}>) => <p>&langle; &rangle;</p>,

OL: (obj: JsonType, refs: React.MutableRefObject<{}>) => <OL>{parseArr(obj['child']!, refs)}</OL>,

REF: handleRef,

REFERENCE: handleContainer,

REFERENCES: handleContainer,
REFERENCE: handleReference,

SECTION: handleContainer,

Expand All @@ -243,17 +239,13 @@ export const processingFunctions = {
</h2>
),

SUBSECTION: handleContainer,

SUBSUBHEADING: (obj: JsonType, refs: React.MutableRefObject<{}>) => (
<h4 className="bp3-heading" ref={ref => (refs.current[obj['id']!] = ref)}>
<br />
{parseArr(obj['child']!, refs)}
</h4>
),

SUBSUBSECTION: handleContainer,

TABLE: (obj: JsonType, refs: React.MutableRefObject<{}>) => (
<table>
<tbody>{obj['child']!.map((x, index) => handleTR(x, refs, index))}</tbody>
Expand Down
8 changes: 4 additions & 4 deletions src/features/sicp/parser/__tests__/ParseJson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { JsonType, parseArr, ParseJsonError, parseObj, processingFunctions } fro

// Tags to process
const headingTags = ['SUBHEADING', 'SUBSUBHEADING'];
const sectionTags = ['SECTION', 'SUBSECTION', 'SUBSUBSECTION', 'MATTER', 'CHAPTER', 'REFERENCES'];
const listTags = ['OL', 'UL'];
const symbolTags = ['BR', 'LaTeX', 'TeX'];
const stylingTags = ['B', 'EM', 'JAVASCRIPTINLINE', 'TT', 'METAPHRASE', 'META'];
const stylingTags = ['B', 'EM', 'JAVASCRIPTINLINE', 'TT', 'META'];
const latexTags = ['LATEX', 'LATEXINLINE'];
const linkTags = ['LINK', 'REF', 'FOOTNOTE_REF'];

const epigraphTag = 'EPIGRAPH';
const tableTag = 'TABLE';
const exerciseTag = 'EXERCISE';
const sectionTag = 'SECTION';
const snippetTag = 'SNIPPET';
const figureTag = 'FIGURE';
const displayFootnoteTag = 'DISPLAYFOOTNOTE';
Expand Down Expand Up @@ -79,12 +79,12 @@ describe('Parse heading', () => {
});

describe('Parse section', () => {
const tags = sectionTags;
const tag = sectionTag;
const text = { tag: 'TEXT', child: [mockData['text'], mockData['text']] };
const content = [text, text];
const obj = { body: 'Title', child: content };

tags.forEach(x => testTagSuccessful(obj, x));
testTagSuccessful(obj, tag);
});

describe('Parse list', () => {
Expand Down
Loading

0 comments on commit f0ef1b6

Please sign in to comment.