From 75ae0ee815eccdd234df1e3a8a763f5b0657c693 Mon Sep 17 00:00:00 2001
From: Terence Eden This is the first paragraph.1 This is the first paragraph.1 Some paragraph with a footnote5, and another6. Some paragraph with a footnote5, and another6. Another paragraph with a named footnote7. Another paragraph with a named footnote7. This paragraph should not have a footnote marker since
the footnote is undefined.[^3] This paragraph has a second footnote marker to footnote number one.5 This paragraph has a second footnote marker to footnote number one.5 This paragraph links to a footnote with plenty of
-block-level content.8
with a newline
+ foreach ( $xp->query('//br') as $node ) {
+ $br2nl = $doc->createTextNode( "\n" );
+ $node->parentNode->replaceChild( $br2nl, $node );
+ }
+
+ // Replace each with its alt text
+ foreach ( $xp->query('//img') as $node ) {
+ $alt_text = $doc->createTextNode( $node->getAttribute('alt') . " " );
+ $node->parentNode->replaceChild( $alt_text, $node );
+ }
+
+ // Replace each with its alt text
+ foreach ( $xp->query('//area') as $node ) {
+ $alt_text = $doc->createTextNode( $node->getAttribute('alt') . " " );
+ $node->parentNode->replaceChild( $alt_text, $node );
+ }
+
+ // Get a plaintext representation
+ $title_text = trim( html_entity_decode( strip_tags( $doc->saveHTML() ) ));
+
+ // Split by space
+ $parts = explode( " ", $title_text );
+
+ // Remove empty elements - strlen is needed to prevent text which evaluates to false from being removed
+ $parts = array_filter($parts, "strlen");
+
+ // Add each part to a new string until it is 200 characters long
+ $title_length = 200;
+ $title = "";
+
+ foreach ( $parts as $part) {
+ // Always add the first part
+ if ( mb_strlen( $title ) == 0 ) {
+ $title .= $part . " ";
+ // If the first part is a very long string, reduce it to the specified length
+ if ( mb_strlen( $title ) > $title_length ) {
+ $title = mb_substr( $title, 0, $title_length );
+ $title .= "…";
+ break;
+ }
+ } else if ( ( mb_strlen( $title ) + mb_strlen( $part ) ) < $title_length ) {
+ // Add the next whole word which doesn't take the total length over the specified length
+ $part = str_replace("\n ", "\n", $part);
+
+ if ( $part == "\n" ) {
+ // Don't add spaces if it ends with a newline to prevent indenting.
+ $title .= $part;
+ } else {
+ $title .= $part . " ";
+ }
+ } else {
+ // If it has been truncated, add an ellipsis
+ $title = trim( $title );
+ $title .= "…";
+ break;
+ }
+ }
+
+ return trim($title);
+ }
/**
* Generates the HTML for footnotes. Called by appendFootnotes, even if
@@ -1760,8 +1842,10 @@ protected function _appendFootnotes_callback($matches) {
$class = $this->encodeAttribute($class);
$attr .= " class=\"$class\"";
}
- if ($this->fn_link_title !== "") {
- $title = $this->fn_link_title;
+ if ($this->fn_link_title == "") {
+ // Decode any markdown in the footnote
+ $title = $this->get_footnote_title( $this->formParagraphs( $this->footnotes[$node_id] ) );
+ // Format it to be suitable for a title tool-tip
$title = $this->encodeAttribute($title);
$attr .= " title=\"$title\"";
}
From 567b0d114d0b2d9f1b5dc0241628c7b525610fd7 Mon Sep 17 00:00:00 2001
From: Terence Eden
Header4
+Header4
-
This paragraph host the footnote reference within a -footnote test9.
+footnote test9.Testing unusual footnote name10.
+Testing unusual footnote name10.
Footnotes mixed with images11
Footnotes mixed with images11
+
+
Content for sixth footnote spaning on +
Content for sixth footnote spanning on three lines, with some span-level markup like emphasis, a link. ↩︎
@@ -82,7 +84,7 @@ three lines, with some span-level markup likeFootnote Content ↩︎
+Footnote Content ↩︎
This footnote should appear even though it is referenced -from another footnote. But [^reference] should be litteral +from another footnote. But [^reference] should be literal since the footnote with that name has already been used. ↩︎