Skip to content

Commit

Permalink
will it work?
Browse files Browse the repository at this point in the history
  • Loading branch information
citruscai committed Jul 4, 2024
1 parent 9a5386d commit d99331c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/worksheetGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ interface SimpleTemplateProps {
includeAnswers: boolean;
}

const preprocessText = (text: string, includeAnswers: boolean) => {
return includeAnswers
? text.replace(/<mark>(.*?)<\/mark>/g, (_, p1) => p1)
: text.replace(/<mark>(.*?)<\/mark>/g, (_, p1) => '_'.repeat(p1.length));
};

const SimpleTemplate: React.FC<SimpleTemplateProps> = ({ jsonData, includeAnswers }) => (
<Page style={stylesSimple.page}>
<Text style={stylesSimple.title}>{jsonData.title || 'Guided Notes'}</Text>
Expand All @@ -50,19 +56,15 @@ const SimpleTemplate: React.FC<SimpleTemplateProps> = ({ jsonData, includeAnswer
<Text style={stylesSimple.subtitle}>{section.title}</Text>
{section.content?.map((line, contentIndex) => (
<Text key={contentIndex} style={stylesSimple.content}>
{includeAnswers
? line.replace(/<mark>(.*?)<\/mark>/g, (_, p1) => p1)
: line.replace(/<mark>(.*?)<\/mark>/g, (_, p1) => '_'.repeat(p1.length))}
{preprocessText(line, includeAnswers)}
</Text>
))}
{section.lists?.map((list, listIndex) => (
<View key={listIndex}>
<Text style={stylesSimple.listTitle}>{list.list_title}</Text>
{list.items?.map((item, itemIndex) => (
<Text key={itemIndex} style={stylesSimple.listItem}>
{includeAnswers
? item.replace(/<mark>(.*?)<\/mark>/g, (_, p1) => p1)
: item.replace(/<mark>(.*?)<\/mark>/g, (_, p1) => '_'.repeat(p1.length))}
{preprocessText(item, includeAnswers)}
</Text>
))}
</View>
Expand Down

0 comments on commit d99331c

Please sign in to comment.