4 * Converts <q> tags into quotation marks.
6 class XHTMLCompiler_DOMFilter_Quoter
extends XHTMLCompiler_DOMFilter
9 protected $name = 'Quoter';
11 protected $leftQuote = "\xE2\x80\x9C";
12 protected $rightQuote = "\xE2\x80\x9D";
14 protected $leftNestedQuote = "\xE2\x80\x98";
15 protected $rightNestedQuote = "\xE2\x80\x99";
17 public function __construct(
18 $left = null, $right = null,
19 $left_nest = null, $right_nest = null,
22 parent
::__construct($name);
23 if ($left) $this->leftQuote
= $left;
24 if ($right) $this->rightQuote
= $right;
25 if ($left_nest) $this->leftNestedQuote
= $left_nest;
26 if ($right_nest) $this->rightNestedQuote
= $right_nest;
29 public function process(DOMDocument
$dom, $page, $manager) {
32 // first handle single-quotes
33 $nodes = $this->query("//html:q//html:q");
34 foreach ($nodes as $node) {
36 $this->quotify($dom, $node, $this->leftNestedQuote
, $this->rightNestedQuote
);
39 // now handle double-quotes
40 $nodes = $this->query("//html:q");
41 foreach ($nodes as $node) {
43 $this->quotify($dom, $node, $this->leftQuote
, $this->rightQuote
);
45 if ($dep) $manager->addDependency(__FILE__
);
50 * Takes a node and unpacks its contents, surrounding it with
52 * @param $node Node to be unpacked
53 * @param $left New text wrapper on left
54 * @param $right New text wrapper on right
56 protected function quotify($dom, $node, $left, $right) {
57 $parent = $node->parentNode
;
58 $parent->insertBefore($dom->createTextNode($left), $node);
59 foreach ($node->childNodes
as $child) {
60 $parent->insertBefore($child->cloneNode(true), $node);
62 $parent->insertBefore($dom->createTextNode($right), $node);
63 $parent->removeChild($node);