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

Interactive SICP-JS: Improve readability + minor fixes #1796

Merged
merged 16 commits into from
Jun 16, 2021
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
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