protected function addFootnotes( \DOMDocument $chapter ) {
		$fn_candidates = $chapter->getelementsByTagName( 'a' );
		$fn_ids = [];
		foreach ( $fn_candidates as $fn_candidate ) {
			/** @var \DOMElement $fn_candidate */
			$href = $fn_candidate->getAttribute( 'href' );
			if ( ! empty( $href ) ) {
				$fn_matches = null;
				if ( preg_match( self::FOOTNOTE_HREF_PATTERN, $href, $fn_matches ) ) {
					$fn_ids[] = $fn_matches[1];
				}
			}
		}

		// TODO either/or is not sufficient, needs to be built to
		// cover a use case where both are present.
		$notes = [];
		if ( ! empty( $this->fn ) ) {
			$notes = $this->fn;
		}
		if ( ! empty( $this->en ) ) {
			$notes = $this->en;
		}

		foreach ( $fn_ids as $id ) {
			if ( array_key_exists( $id, $notes ) ) {
				$grandparent = $chapter->createElement( 'div' );
				$grandparent->setAttribute( 'id', "sdfootnote{$id}sym" );
				$parent = $chapter->createElement( 'span' );
				$child = $chapter->createElement( 'a', $id );
				$child->setAttribute( 'href', "#sdfootnote{$id}anc" );
				$child->setAttribute( 'name', "sdfootnote{$id}sym" );
				$text = $chapter->createTextNode( $notes[ $id ] );

				// attach
				$grandparent->appendChild( $parent );
				$parent->appendChild( $child );
				$parent->appendChild( $text );

				$chapter->documentElement->appendChild( $grandparent );
			}
		}

		return $chapter;
	}