Skip to content

Commit

Permalink
Merge pull request #4224 from m7913d/fix_s_tag
Browse files Browse the repository at this point in the history
Add support for <s> tag when converting HTML to RichText
  • Loading branch information
oleibman authored Nov 10, 2024
2 parents 3e52499 + e78e7ea commit dbc2e24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Fixed

- Nothing yet.
- Add support for `<s>` tag when converting HTML to RichText. [Issue #4223](https://github.com/PHPOffice/PhpSpreadsheet/issues/4223) [PR #4224](https://github.com/PHPOffice/PhpSpreadsheet/pull/4224)

## 2024-11-10 - 3.4.0

Expand Down
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Helper/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ class Html
'u' => [self::class, 'startUnderlineTag'],
'ins' => [self::class, 'startUnderlineTag'],
'del' => [self::class, 'startStrikethruTag'],
's' => [self::class, 'startStrikethruTag'],
'sup' => [self::class, 'startSuperscriptTag'],
'sub' => [self::class, 'startSubscriptTag'],
];
Expand All @@ -575,6 +576,7 @@ class Html
'u' => [self::class, 'endUnderlineTag'],
'ins' => [self::class, 'endUnderlineTag'],
'del' => [self::class, 'endStrikethruTag'],
's' => [self::class, 'endStrikethruTag'],
'sup' => [self::class, 'endSuperscriptTag'],
'sub' => [self::class, 'endSubscriptTag'],
'br' => [self::class, 'breakTag'],
Expand Down
22 changes: 22 additions & 0 deletions tests/PhpSpreadsheetTests/Helper/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,26 @@ public function testLiTag(): void

self::assertSame($expected, $actual->getPlainText());
}

public function testSTag(): void
{
$html = new Html();
$input = 'Hello <s>test</s>world';
$richText = $html->toRichTextObject($input);
$elements = $richText->getRichTextElements();

self::assertSame(count($elements), 3);

self::assertSame($elements[0]->getText(), 'Hello ');
self::assertNotNull($elements[0]->getFont());
self::assertFalse($elements[0]->getFont()->getStrikethrough());

self::assertSame($elements[1]->getText(), 'test');
self::assertNotNull($elements[1]->getFont());
self::assertTrue($elements[1]->getFont()->getStrikethrough());

self::assertSame($elements[2]->getText(), 'world');
self::assertNotNull($elements[2]->getFont());
self::assertFalse($elements[2]->getFont()->getStrikethrough());
}
}

0 comments on commit dbc2e24

Please sign in to comment.