Skip to content

Commit b724c64

Browse files
committed
Stop inline glossary terms needing to use exam board
1 parent f295c4d commit b724c64

File tree

4 files changed

+16
-31
lines changed

4 files changed

+16
-31
lines changed

src/app/components/elements/LaTeX.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ import React, {useContext} from "react";
22
import {useSelector} from "react-redux";
33
import {selectors} from "../../state/selectors";
44
import {AppState} from "../../state/reducers";
5-
import {useUserContext} from "../../services/userContext";
6-
import {
7-
BooleanNotation,
8-
FigureNumberingContext,
9-
FigureNumbersById,
10-
PotentialUser
11-
} from "../../../IsaacAppTypes";
12-
import {EXAM_BOARD} from "../../services/constants";
5+
import {BooleanNotation, FigureNumberingContext, FigureNumbersById, PotentialUser} from "../../../IsaacAppTypes";
136
import he from "he";
147
import {SITE, SITE_SUBJECT} from "../../services/siteConstants";
158
import katex from "katex";
@@ -230,7 +223,7 @@ const ENDREF = "==ENDREF==";
230223
const REF_REGEXP = new RegExp(REF + "(.*?)" + ENDREF, "g");
231224
const SR_REF_REGEXP = new RegExp("start text, " + REF_REGEXP.source + ", end text,", "g");
232225

233-
export function katexify(html: string, user: PotentialUser | null, examBoard: EXAM_BOARD | null, booleanNotation : BooleanNotation | null, screenReaderHoverText: boolean, figureNumbers: FigureNumbersById) {
226+
export function katexify(html: string, user: PotentialUser | null, booleanNotation : BooleanNotation | null, screenReaderHoverText: boolean, figureNumbers: FigureNumbersById) {
234227
start.lastIndex = 0;
235228
let match: RegExpExecArray | null;
236229
let output = "";
@@ -333,11 +326,10 @@ export function LaTeX({markup}: {markup: string}) {
333326
const booleanNotation = useSelector((state: AppState) => state?.userPreferences?.BOOLEAN_NOTATION || null);
334327
const screenReaderHoverText = useSelector((state: AppState) => state && state.userPreferences &&
335328
state.userPreferences.BETA_FEATURE && state.userPreferences.BETA_FEATURE.SCREENREADER_HOVERTEXT || false);
336-
const {examBoard} = useUserContext();
337329
const figureNumbers = useContext(FigureNumberingContext);
338330

339331
const escapedMarkup = escapeHtml(markup);
340-
const katexHtml = katexify(escapedMarkup, user, examBoard, booleanNotation, screenReaderHoverText, figureNumbers);
332+
const katexHtml = katexify(escapedMarkup, user, booleanNotation, screenReaderHoverText, figureNumbers);
341333

342334
return <span dangerouslySetInnerHTML={{__html: katexHtml}} />
343335
}

src/app/components/elements/TrustedHtml.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'katex/dist/contrib/mhchem.js';
33
import {FigureNumberingContext} from "../../../IsaacAppTypes";
44
import {AppState} from "../../state/reducers";
55
import {useSelector} from "react-redux";
6-
import {useUserContext} from "../../services/userContext";
76
import {selectors} from "../../state/selectors";
87
import {katexify} from "./LaTeX";
98

@@ -39,11 +38,10 @@ export const TrustedHtml = ({html, span}: {html: string; span?: boolean}) => {
3938
const booleanNotation = useSelector((state: AppState) => state?.userPreferences?.BOOLEAN_NOTATION || null);
4039
const screenReaderHoverText = useSelector((state: AppState) => state && state.userPreferences &&
4140
state.userPreferences.BETA_FEATURE && state.userPreferences.BETA_FEATURE.SCREENREADER_HOVERTEXT || false);
42-
const {examBoard} = useUserContext();
4341

4442
const figureNumbers = useContext(FigureNumberingContext);
4543

46-
html = manipulateHtml(katexify(html, user, examBoard, booleanNotation, screenReaderHoverText, figureNumbers));
44+
html = manipulateHtml(katexify(html, user, booleanNotation, screenReaderHoverText, figureNumbers));
4745

4846
const ElementType = span ? "span" : "div";
4947
return <ElementType dangerouslySetInnerHTML={{__html: html}} />;

src/app/components/elements/TrustedMarkdown.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import {Provider, useSelector, useStore} from "react-redux";
44
import * as RS from "reactstrap";
55
import {Router} from "react-router-dom";
66
import {AppState} from "../../state/reducers";
7-
import {EXAM_BOARD_NULL_OPTIONS, MARKDOWN_RENDERER} from "../../services/constants";
7+
import {MARKDOWN_RENDERER} from "../../services/constants";
88
import {TrustedHtml} from "./TrustedHtml";
99
import {IsaacGlossaryTerm} from "../content/IsaacGlossaryTerm";
1010
import {GlossaryTermDTO} from "../../../IsaacApiTypes";
1111
import {escapeHtml, replaceEntities} from "remarkable/lib/common/utils";
1212
import {Token} from "remarkable";
1313
import uuid from "uuid";
1414
import {history} from "../../services/history";
15-
import {useUserContext} from "../../services/userContext";
1615
import {SITE, SITE_SUBJECT} from "../../services/siteConstants";
1716

1817
MARKDOWN_RENDERER.renderer.rules.link_open = function(tokens: Token[], idx/* options, env */) {
@@ -39,8 +38,6 @@ function getTermFromCandidateTerms(candidateTerms: GlossaryTermDTO[]) {
3938

4039
export const TrustedMarkdown = ({markdown}: {markdown: string}) => {
4140
const store = useStore();
42-
const {examBoard} = useUserContext();
43-
const examBoardTag = !EXAM_BOARD_NULL_OPTIONS.has(examBoard) ? examBoard : "";
4441

4542
const glossaryTerms = useSelector((state: AppState) => state && state.glossaryTerms);
4643
const [componentUuid, setComponentUuid] = useState(uuid.v4().slice(0, 8));
@@ -64,14 +61,12 @@ export const TrustedMarkdown = ({markdown}: {markdown: string}) => {
6461
]));
6562

6663
if (glossaryTerms && glossaryTerms.length > 0 && glossaryIdsInMarkdown.length > 0) {
67-
const filteredTerms = glossaryTerms.filter(term => term.examBoard === "" || term.examBoard === examBoard);
68-
6964
// Markdown can't cope with React components, so we pre-render our component to static HTML, which Markdown will then ignore.
7065
// This requires a bunch of stuff to be passed down along with the component.
7166
markdown = markdown.replace(glossaryBlockRegexp, (_match, id) => {
72-
const term = getTermFromCandidateTerms(filteredTerms.filter(term => (term.id as string) === id || (term.id as string) === `${id}|${examBoardTag}`));
67+
const term = getTermFromCandidateTerms(glossaryTerms.filter(term => (term.id as string) === id));
7368
if (term === null) {
74-
console.error('No valid term for "' + id + '" found among the filtered terms: ', filteredTerms);
69+
console.error('No valid term for "' + id + '" found among the filtered terms: ', glossaryTerms);
7570
return "";
7671
}
7772

@@ -88,9 +83,9 @@ export const TrustedMarkdown = ({markdown}: {markdown: string}) => {
8883
// The tooltip components can be rendered as regular react objects, so we just add them to an array,
8984
// and return them inside the JSX.Element that is returned as TrustedMarkdown.
9085
markdown = markdown.replace(glossaryInlineRegexp, (_match, id, text, offset) => {
91-
const term = getTermFromCandidateTerms(filteredTerms.filter(term => (term.id as string) === id || (term.id as string) === `${id}|${examBoardTag}`));
86+
const term = getTermFromCandidateTerms(glossaryTerms.filter(term => (term.id as string) === id));
9287
if (term === null) {
93-
console.error('No valid term for "' + id + '" found among the filtered terms: ', filteredTerms);
88+
console.error('No valid term for "' + id + '" found among the filtered terms: ', glossaryTerms);
9489
return "";
9590
}
9691

src/test/components/TrustedHtml.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('TrustedHtml LaTeX locator', () => {
2727
it('can find basic delimiters', () => {
2828
delimiters.forEach(([open, displayMode, close]) => {
2929
const testcase = html[0] + wrapIn(open, math[0], close) + html[1];
30-
const result = katexify(testcase, null, null, null, false, {});
30+
const result = katexify(testcase, null, null, false, {});
3131

3232
expect(result).toEqual(html[0] + LATEX + html[1]);
3333
// @ts-ignore
@@ -40,7 +40,7 @@ describe('TrustedHtml LaTeX locator', () => {
4040
it("unbalanced delimiters don't break everything but instead are just skipped", () => {
4141
delimiters.forEach(([open, , ]) => {
4242
const testcase = html[0] + wrapIn(open, math[0], "") + html[1];
43-
const result = katexify(testcase, null, null, null, false, {});
43+
const result = katexify(testcase, null, null, false, {});
4444

4545
expect(result).toEqual(html[0] + open + math[0] + html[1]);
4646
expect(katex.renderToString).not.toHaveBeenCalled();
@@ -51,7 +51,7 @@ describe('TrustedHtml LaTeX locator', () => {
5151
nestedDollars.forEach((dollarMath) => {
5252
delimiters.forEach(([open, displayMode, close]) => {
5353
const testcase = html[0] + wrapIn(open, dollarMath, close) + html[1];
54-
const result = katexify(testcase, null, null, null, false, {});
54+
const result = katexify(testcase, null, null, false, {});
5555

5656
expect(result).toEqual(html[0] + LATEX + html[1]);
5757
// @ts-ignore
@@ -65,7 +65,7 @@ describe('TrustedHtml LaTeX locator', () => {
6565
it('can render environments', () => {
6666
const env = "\\begin{aligned}" + math[0] + "\\end{aligned}";
6767
const testcase = html[0] + env + html[1];
68-
const result = katexify(testcase, null, null, null, false, {});
68+
const result = katexify(testcase, null, null, false, {});
6969

7070
expect(result).toEqual(html[0] + LATEX + html[1]);
7171
// @ts-ignore
@@ -77,7 +77,7 @@ describe('TrustedHtml LaTeX locator', () => {
7777
it('missing refs show an inline error', () => {
7878
const ref = "\\ref{foo[234o89tdgfiuno34£\"$%^Y}";
7979
const testcase = html[0] + ref + html[1];
80-
const result = katexify(testcase, null, null, null, false, {});
80+
const result = katexify(testcase, null, null, false, {});
8181

8282
expect(result).toEqual(html[0] + "unknown reference " + ref + html[1]);
8383
expect(katex.renderToString).not.toHaveBeenCalled();
@@ -86,7 +86,7 @@ describe('TrustedHtml LaTeX locator', () => {
8686
it('found refs show their figure number', () => {
8787
const ref = "\\ref{foo}";
8888
const testcase = html[0] + ref + html[1];
89-
const result = katexify(testcase, null, null, null, false, {foo: 42});
89+
const result = katexify(testcase, null, null, false, {foo: 42});
9090

9191
const expectedFigureRef = "Figure" + "&nbsp;" + "42";
9292
const expectedFigureRefWithFormatting = `<strong class="text-secondary figure-reference">${expectedFigureRef}</strong>`;
@@ -98,7 +98,7 @@ describe('TrustedHtml LaTeX locator', () => {
9898
const escapedDollar = "\\$";
9999
const unescapedDollar = "$";
100100
const testcase = html[0] + escapedDollar + html[1];
101-
const result = katexify(testcase, null, null, null, false, {});
101+
const result = katexify(testcase, null, null, false, {});
102102

103103
expect(result).toEqual(html[0] + unescapedDollar + html[1]);
104104
expect(katex.renderToString).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)