Skip to content

Commit

Permalink
Don't render the glossary in the hero section
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh committed May 6, 2024
1 parent a28becd commit 74b2a55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,27 @@ const parseCitation = (data: string) => {
return converted
}

const parseText = (content: string | undefined | StringWithHTML, terms: Term[]) => {
const parseText = (
content: string | undefined | StringWithHTML,
terms: Term[],
options: { glossary: boolean } = { glossary: true },
) => {
const sanitizedHTML = sanitizeCourseMaterialHtml(content)
const { count, converted: parsedLatex } = convertToLatex(sanitizedHTML)
const parsedCitation = parseCitation(parsedLatex)
const parsedGlossary = parseGlossary(parsedCitation, terms ?? [])

const hasCitationsOrGlossary = parsedLatex !== parsedGlossary
let parsedText = parsedCitation
let hasCitationsOrGlossary = false

return { count, parsedText: parsedGlossary, hasCitationsOrGlossary }
if (options.glossary) {
parsedText = parseGlossary(parsedCitation, terms ?? [])
}

hasCitationsOrGlossary = parsedLatex !== parsedText

// Sanitation always needs to be the last step because otherwise we might accidentally introduce injection attacks with our custom parsing and modifications to the string
parsedText = sanitizeCourseMaterialHtml(parsedText)
return { count, parsedText, hasCitationsOrGlossary }
}

export { parseText }
10 changes: 8 additions & 2 deletions services/course-material/src/components/HeroSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@ const HeroSection: React.FC<React.PropsWithChildren<React.PropsWithChildren<Card
<span className="chapter">{label}</span>
<h1
className={INCLUDE_THIS_HEADING_IN_HEADINGS_NAVIGATION_CLASS}
dangerouslySetInnerHTML={{ __html: parseText(title, terms).parsedText }}
dangerouslySetInnerHTML={{
__html: parseText(title, terms, { glossary: false }).parsedText,
}}
/>
<span
dangerouslySetInnerHTML={{
__html: parseText(subtitle, terms, { glossary: false }).parsedText,
}}
/>
<span dangerouslySetInnerHTML={{ __html: parseText(subtitle, terms).parsedText }} />
</TextBox>
</div>
)
Expand Down

0 comments on commit 74b2a55

Please sign in to comment.