diff --git a/include/html2text.php b/include/html2text.php index 713b449274a062328f64d45f52da8b91412002c0..09cbda2a2cd7165cdcfe73e2e7ae8e7edc004540 100644 --- a/include/html2text.php +++ b/include/html2text.php @@ -151,6 +151,7 @@ class HtmlInlineElement { var $children = array(); var $style = false; var $stylesheets = array(); + var $footnotes = array(); var $ws = false; function __construct($node, $parent) { @@ -200,6 +201,11 @@ class HtmlInlineElement { elseif (is_string($more)) $output .= $more; } + if ($this->footnotes) { + $output .= "\n\n" . str_repeat('-', $width/2) . "\n"; + foreach ($this->footnotes as $name=>$content) + $output .= "[$name] ".$content."\n"; + } return $output; } @@ -253,6 +259,10 @@ class HtmlInlineElement { function addStylesheet(&$s) { $this->stylesheets[] = $s; } + + function addFootNote($name, $content) { + $this->footnotes[$name] = $content; + } } class HtmlBlockElement extends HtmlInlineElement { @@ -397,7 +407,9 @@ class HtmlImgElement extends HtmlInlineElement { $alt = $this->node->getAttribute("alt"); return "[image:$alt$title] "; } - function getWeight() { return parent::getWeight() + 4; } + function getWeight() { + return strlen($this->node->getAttribute("alt")) + 8; + } } class HtmlAElement extends HtmlInlineElement { @@ -410,6 +422,10 @@ class HtmlAElement extends HtmlInlineElement { if ($this->node->getAttribute("name") != null) { $output = "[$output]"; } + } elseif (strlen($href) > $width / 2) { + $output = "[$output][]"; + if ($href != $output) + $this->getRoot()->addFootnote($output, $href); } else { if ($href != $output) { $output = "[$output]($href)"; @@ -687,7 +703,7 @@ class HtmlTableCell extends HtmlBlockElement { } function getMinWidth() { - return parent::getMinWidth() / $this->cols; + return max(4, parent::getMinWidth() / $this->cols); } }