Skip to content

Commit

Permalink
Interactive SICP-JS: Improve readability + minor fixes (#1796)
Browse files Browse the repository at this point in the history
* Fix syntax highlighting webpack tree shaking issue

* Fix index page text alignment

* Tweak styles to increase readibility

* Fix formatting of styles page

* Change max-width

* Fix formatting of index page

* Update unit tests

* Change parsing of metaphrase tag

* Update adapters names

* Fix figure margins

* Update test snapshots

* Simplify parsing of containers

Co-authored-by: Martin Henz <henz@comp.nus.edu.sg>
  • Loading branch information
samuelfangjw and martin-henz committed Jun 16, 2021
1 parent 29e8388 commit a617212
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 255 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
20 changes: 7 additions & 13 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,7 +127,7 @@ const handleFigure = (obj: JsonType, refs: React.MutableRefObject<{}>) => (
const handleImage = (obj: JsonType, refs: React.MutableRefObject<{}>) => {
if (obj['src']) {
return (
<div className={'sicp-figure'}>
<div>
{obj['src'] && (
<img
src={Constants.interactiveSicpUrl + obj['src']}
Expand Down Expand Up @@ -175,6 +175,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 @@ -221,19 +225,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 @@ -245,17 +243,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 a617212

Please sign in to comment.