Skip to content

Commit 41ca3ca

Browse files
fix(transcript): accept and render HTML string (#735)
1 parent e3629f6 commit 41ca3ca

File tree

9 files changed

+194
-78
lines changed

9 files changed

+194
-78
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"@headlessui/react": "1.7.19",
5555
"@radix-ui/react-tabs": "1.1.13",
5656
"babel-plugin-prismjs": "2.1.0",
57-
"prismjs": "1.30.0"
57+
"prismjs": "1.30.0",
58+
"sanitize-html": "2.17.0"
5859
},
5960
"peerDependencies": {
6061
"react": "^16.14.0 || ^17.0.0 || ^18.0.0",
@@ -88,6 +89,7 @@
8889
"@types/prismjs": "1.26.5",
8990
"@types/react": "16.14.68",
9091
"@types/react-dom": "16.9.25",
92+
"@types/sanitize-html": "2.16.0",
9193
"@typescript-eslint/eslint-plugin": "7.18.0",
9294
"@typescript-eslint/parser": "7.18.0",
9395
"autoprefixer": "10.4.22",

pnpm-lock.yaml

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/quiz-question/quiz-question.stories.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,8 @@ export const WithAudio: Story = {
708708
audioUrl:
709709
"https://cdn.freecodecamp.org/curriculum/english/animation-assets/sounds/1.1-1.mp3",
710710
audioAriaLabel: "Audio for question",
711-
transcript: `
712-
Maria: Hello. You're the new graphic designer, right? I'm Maria, the team lead.
713-
Tom: Hi, that's right. I'm Tom McKenzie. It's a pleasure to meet you.`,
711+
transcript: `<p><b>Maria:</b> Hello. You're the new graphic designer, right? I'm Maria, the team lead.</p>
712+
<p><b>Tom:</b> Hi, that's right. I'm Tom McKenzie. It's a pleasure to meet you.</p>`,
714713
answers: [
715714
{ label: "Option 1", value: 1 },
716715
{ label: "Option 2", value: 2 },
@@ -728,9 +727,8 @@ export const WithAudio: Story = {
728727
question="Listen to the audio and select the correct answer:"
729728
audioUrl="https://cdn.freecodecamp.org/curriculum/english/animation-assets/sounds/1.1-1.mp3"
730729
audioAriaLabel="Audio for question"
731-
transcript={\`
732-
Maria: Hello. You're the new graphic designer, right? I'm Maria, the team lead.
733-
Tom: Hi, that's right. I'm Tom McKenzie. It's a pleasure to meet you.\`}
730+
transcript={\`<p><b>Maria:</b> Hello. You're the new graphic designer, right? I'm Maria, the team lead.</p>
731+
<p><b>Tom:</b> Hi, that's right. I'm Tom McKenzie. It's a pleasure to meet you.</p>\`}
734732
answers={[
735733
{ label: "Option 1", value: 1 },
736734
{ label: "Option 2", value: 2 },

src/quiz-question/quiz-question.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ describe("<QuizQuestion />", () => {
395395
]}
396396
audioUrl="test-audio.mp3"
397397
audioAriaLabel="Audio for question"
398-
transcript="Test transcript"
398+
transcript="<p>Test transcript</p>"
399399
/>,
400400
);
401401

@@ -419,7 +419,7 @@ describe("<QuizQuestion />", () => {
419419
]}
420420
audioUrl="test-audio.mp3"
421421
audioAriaLabel="Audio for question 1"
422-
transcript="Test transcript"
422+
transcript="<p>Test transcript</p>"
423423
position={1}
424424
/>,
425425
);
@@ -518,7 +518,7 @@ describe("<QuizQuestion />", () => {
518518
{ label: "Option 2", value: 2 },
519519
]}
520520
audioUrl="https://example.com/audio.mp3"
521-
transcript="Audio transcript"
521+
transcript="<p>Audio transcript</p>"
522522
/>;
523523

524524
// QuizQuestion with audioUrl but missing transcript
@@ -552,7 +552,7 @@ describe("<QuizQuestion />", () => {
552552
{ label: "Option 1", value: 1 },
553553
{ label: "Option 2", value: 2 },
554554
]}
555-
transcript="Audio transcript"
555+
transcript="<p>Audio transcript</p>"
556556
/>;
557557

558558
// QuizQuestion with valid audio props
@@ -564,5 +564,5 @@ describe("<QuizQuestion />", () => {
564564
]}
565565
audioUrl="https://example.com/audio.mp3"
566566
audioAriaLabel="Audio for question"
567-
transcript="Audio transcript"
567+
transcript="<p>Audio transcript</p>"
568568
/>;

src/quiz-question/transcript/transcript.stories.tsx

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ type Story = StoryObj<typeof Transcript>;
1616

1717
export const WithoutSpeakers: Story = {
1818
args: {
19-
transcript: `In this lesson, we'll explore the fundamentals of JavaScript.
20-
JavaScript is a versatile programming language used for web development.
21-
It allows you to create interactive and dynamic web pages.
22-
Let's start by understanding variables and data types.`,
19+
transcript: `<p>In this lesson, we'll explore the fundamentals of JavaScript.</p>
20+
<p>JavaScript is a versatile programming language used for web development.</p>
21+
<p>It allows you to create interactive and dynamic web pages.</p>
22+
<p>Let's start by understanding variables and data types.</p>`,
2323
},
2424
parameters: {
2525
docs: {
2626
source: {
2727
code: `<Transcript
28-
transcript={\`In this lesson, we'll explore the fundamentals of JavaScript.
29-
JavaScript is a versatile programming language used for web development.
30-
It allows you to create interactive and dynamic web pages.
31-
Let's start by understanding variables and data types.\`}
28+
transcript={\`<p>In this lesson, we'll explore the fundamentals of JavaScript.</p>
29+
<p>JavaScript is a versatile programming language used for web development.</p>
30+
<p>It allows you to create interactive and dynamic web pages.</p>
31+
<p>Let's start by understanding variables and data types.</p>\`}
3232
/>`,
3333
},
3434
},
@@ -37,17 +37,36 @@ Let's start by understanding variables and data types.\`}
3737

3838
export const WithSpeakers: Story = {
3939
args: {
40-
transcript: `Tom: Hi, that's right. I'm Tom McKenzie.
41-
Maria: Welcome aboard, Tom. How do you like California so far?
42-
Tom: I like it. It's different from Texas, but I like it here.`,
40+
transcript: `<p><b>Tom:</b> Hi, that's right. I'm Tom McKenzie.</p>
41+
<p><b>Maria:</b> Welcome aboard, Tom. How do you like California so far?</p>
42+
<p><b>Tom:</b> I like it. It's different from Texas, but I like it here.</p>`,
4343
},
4444
parameters: {
4545
docs: {
4646
source: {
4747
code: `<Transcript
48-
transcript={\`Tom: Hi, that's right. I'm Tom McKenzie.
49-
Maria: Welcome aboard, Tom. How do you like California so far?
50-
Tom: I like it. It's different from Texas, but I like it here.\`}
48+
transcript={\`<p><b>Tom:</b> Hi, that's right. I'm Tom McKenzie.</p>
49+
<p><b>Maria:</b> Welcome aboard, Tom. How do you like California so far?</p>
50+
<p><b>Tom:</b> I like it. It's different from Texas, but I like it here.</p>\`}
51+
/>`,
52+
},
53+
},
54+
},
55+
};
56+
57+
export const WithChineseAndSpeakers: Story = {
58+
args: {
59+
transcript: `<p><b>Wang Hua:</b> <ruby>你好<rt>nǐ hǎo</rt></ruby>,<ruby>我是王华<rt>wǒ shì wáng huá</rt></ruby>。</p>
60+
<p><b>Wang Hua:</b> <ruby>请问你叫什么名字<rt>qǐng wèn nǐ jiào shén me míng zì</rt></ruby>?</p>
61+
<p><b>Liu Ming:</b> <ruby>你好<rt>nǐ hǎo</rt></ruby>,<ruby>我叫刘明<rt>wǒ jiào liú míng</rt></ruby>。</p>`,
62+
},
63+
parameters: {
64+
docs: {
65+
source: {
66+
code: `<Transcript
67+
transcript={\`<p><b>Wang Hua:</b> <ruby>你好<rt>nǐ hǎo</rt></ruby>,<ruby>我是王华<rt>wǒ shì wáng huá</rt></ruby>。</p>
68+
<p><b>Wang Hua:</b> <ruby>请问你叫什么名字<rt>qǐng wèn nǐ jiào shén me míng zì</rt></ruby>?</p>
69+
<p><b>Liu Ming:</b> <ruby>你好<rt>nǐ hǎo</rt></ruby>,<ruby>我叫刘明<rt>wǒ jiào liú míng</rt></ruby>。</p>\`}
5170
/>`,
5271
},
5372
},

0 commit comments

Comments
 (0)