-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supply the image alt text when converting images
In order to provide an accessible version of HTML content, where an alt tag has been provided, this should be used. Where text refers to an image inline (for example, an emoticon), complete removal of that image can confuse the meaning of the text. As per WCAG 2.0 guidelines (http://www.w3.org/TR/WCAG20-TECHS/H37.html), images which convey words should be provided with alt text which inclues those words. This also relates to images which convey meaning in some other fashion. We have been using this modification to Html2Text since August 2010.
- Loading branch information
1 parent
35e78a7
commit f0b207d
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Html2Text; | ||
|
||
class ImageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testImageDataProvider() { | ||
return array( | ||
'Without alt tag' => array( | ||
'html' => '<img src="http://example.com/example.jpg">', | ||
'expected' => '', | ||
), | ||
'Without alt tag, wrapped in text' => array( | ||
'html' => 'xx<img src="http://example.com/example.jpg">xx', | ||
'expected' => 'xxxx', | ||
), | ||
'With alt tag' => array( | ||
'html' => '<img src="http://example.com/example.jpg" alt="An example image">', | ||
'expected' => '[An example image]', | ||
), | ||
'With alt, and title tags' => array( | ||
'html' => '<img src="http://example.com/example.jpg" alt="An example image" title="Should be ignored">', | ||
'expected' => '[An example image]', | ||
), | ||
'With alt tag, wrapped in text' => array( | ||
'html' => 'xx<img src="http://example.com/example.jpg" alt="An example image">xx', | ||
'expected' => 'xx[An example image]xx', | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider testImageDataProvider | ||
*/ | ||
public function testImages($html, $expected) | ||
{ | ||
$html2text = new Html2Text($html); | ||
$output = $html2text->getText(); | ||
|
||
$this->assertEquals($expected, $output); | ||
} | ||
} |