mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 19:30:21 +02:00
Custom Injector to display URL address along with link text.
When viewing potentially hostile html, it may be helpful to see what a given link was pointing to. This new injector takes the href attribute and adds the text after the link, and deletes the href attribute. Other forms of display could easily be contrived, but this seems to be a good basic way to present the information. Signed-off-by: David Morton <mortonda@dgrmm.net> Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
committed by
Edward Z. Yang
parent
ab263a0bf1
commit
0b6ae1c3c1
24
library/HTMLPurifier/Injector/DisplayLinkURI.php
Normal file
24
library/HTMLPurifier/Injector/DisplayLinkURI.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Injector that displays the URL of an anchor instead of linking to it, in addition to showing the text of the link.
|
||||
*/
|
||||
class HTMLPurifier_Injector_DisplayLinkURI extends HTMLPurifier_Injector
|
||||
{
|
||||
|
||||
public $name = 'DisplayLinkURI';
|
||||
public $needed = array('a');
|
||||
|
||||
public function handleElement(&$token) {
|
||||
}
|
||||
|
||||
public function handleEnd(&$token) {
|
||||
if (isset($token->start->attr['href'])){
|
||||
$url = $token->start->attr['href'];
|
||||
unset($token->start->attr['href']);
|
||||
$token = array($token, new HTMLPurifier_Token_Text(" ($url)"));
|
||||
} else {
|
||||
// nothing to display
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user