Skip to content

Commit

Permalink
Fix duplicating br tags in html (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 authored Nov 29, 2024
1 parent b63ec8b commit 31f5686
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/flat_layout/flat_html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class FlatHTML extends FlatQuestion {
}

private static correctHtmlRules: [{ searchRegExp: RegExp, replaceString: string }] = [
{ searchRegExp: /(<\/?br\s*?\/?\s*?>\s*){2,}/, replaceString: '<br>' }
{ searchRegExp: /(<\/?br\s*?\/?\s*?>\s*){2,}/g, replaceString: '<br>' }
]
protected correctHtml(html: string): string {
FlatHTML.correctHtmlRules.forEach((rule) => {
Expand Down
2 changes: 2 additions & 0 deletions tests/flat_html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ test('Check correctHtml method with multiple br tags', async () => {
const htmlFlat = new FlatHTML(survey, new QuestionHtmlModel('q1'), controller);
expect(htmlFlat['correctHtml']('<span>Test</span><br>')).toEqual('<span>Test</span><br>');
expect(htmlFlat['correctHtml']('<span>Test</span><br><br>')).toEqual('<span>Test</span><br>');
expect(htmlFlat['correctHtml']('<br><br><span>Test</span><br><br>')).toEqual('<br><span>Test</span><br>');
expect(htmlFlat['correctHtml']('<br><br><span>Test</span><br><br><br><span>Test</span><br><br>')).toEqual('<br><span>Test</span><br><span>Test</span><br>');
expect(htmlFlat['correctHtml']('<span>Test</span><br> <br>')).toEqual('<span>Test</span><br>');
expect(htmlFlat['correctHtml']('<br><span>Test</span><br>')).toEqual('<br><span>Test</span><br>');
expect(htmlFlat['correctHtml']('<br><br/>')).toEqual('<br>');
Expand Down

0 comments on commit 31f5686

Please sign in to comment.