public function paragraph($text = "") { if ($this->line != "") { // The filter that converts from USFM to clear texts inserts some stuff // that's being removed here again, as not desirable in clear text. $this->line = str_replace(Filter_Character::enSpace(), " ", $this->line); $this->line = str_replace(" ", " ", $this->line); $this->output[] = $this->line; $this->line = ""; } $this->text($text); }
/** * This function does the processing of the USFM code for one note, * formatting the document and extracting information. */ private function processNote() { for (; $this->chapterUsfmMarkersAndTextPointer < count($this->chapterUsfmMarkersAndText); $this->chapterUsfmMarkersAndTextPointer++) { $currentItem = $this->chapterUsfmMarkersAndText[$this->chapterUsfmMarkersAndTextPointer]; if (Filter_Usfm::isUsfmMarker($currentItem)) { // Flags about the nature of the marker. $isOpeningMarker = Filter_Usfm::isOpeningMarker($currentItem); $isEmbeddedMarker = Filter_Usfm::isEmbeddedMarker($currentItem); // Clean up the marker, so we remain with the basic version, e.g. 'f'. $marker = Filter_Usfm::getMarker($currentItem); if (array_key_exists($marker, $this->styles)) { $style = $this->styles[$marker]; switch ($style['type']) { case StyleTypeVerseNumber: // Verse found. The note should have stopped here. Incorrect note markup. $this->addToFallout("The note did not close at the end of the verse. The text is not correct.", false); break 2; case StyleTypeFootEndNote: switch ($style['subtype']) { case FootEndNoteSubtypeFootnote: if ($isOpeningMarker) { $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerFootEndNote]); $citation = $this->getNoteCitation($style); if ($this->odf_text_standard) { $this->odf_text_standard->addNote($citation, $marker); } // Note citation in superscript in the document with text and note citations. if ($this->odf_text_text_and_note_citations) { $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle; $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript"); $this->odf_text_text_and_note_citations->addText($citation); $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle; } // Add space if the paragraph has text already. if ($this->odf_text_notes) { if ($this->odf_text_notes->currentParagraphContent != "") { $this->odf_text_notes->addText(" "); } } // Add the note citation. And a no-break space after it. if ($this->odf_text_notes) { $this->odf_text_notes->addText($citation . Filter_Character::noBreakSpace()); } // Open note in the web pages. if ($this->html_text_standard) { $this->html_text_standard->addNote($citation, $this->standardContentMarkerFootEndNote); } if ($this->html_text_linked) { $this->html_text_linked->addNote($citation, $this->standardContentMarkerFootEndNote); } // Online Bible. Footnotes do not seem to behave as they ought in the Online Bible compiler. // Just take them out, then. //if ($this->onlinebible_text) $this->onlinebible_text->addNote (); } else { break 3; } break; case FootEndNoteSubtypeEndnote: if ($isOpeningMarker) { $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerFootEndNote]); $citation = $this->getNoteCitation($style); if ($this->odf_text_standard) { $this->odf_text_standard->addNote($citation, $marker, true); } // Note citation in superscript in the document with text and note citations. if ($this->odf_text_text_and_note_citations) { $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle; $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript"); $this->odf_text_text_and_note_citations->addText($citation); $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle; } // Open note in the web page. if ($this->html_text_standard) { $this->html_text_standard->addNote($citation, $this->standardContentMarkerFootEndNote, true); } if ($this->html_text_linked) { $this->html_text_linked->addNote($citation, $this->standardContentMarkerFootEndNote, true); } // Online Bible. //if ($this->onlinebible_text) $this->onlinebible_text->addNote (); } else { break 3; } break; case FootEndNoteSubtypeStandardContent: // The style of the standard content is already used in the note's body. // If means that the text style should be cleared // in order to return to the correct style for the paragraph. if ($this->odf_text_standard) { $this->odf_text_standard->closeTextStyle(true, false); } if ($this->odf_text_notes) { $this->odf_text_notes->closeTextStyle(false, false); } if ($this->html_text_standard) { $this->html_text_standard->closeTextStyle(true, false); } if ($this->html_text_linked) { $this->html_text_linked->closeTextStyle(true, false); } break; case FootEndNoteSubtypeContent: case FootEndNoteSubtypeContentWithEndmarker: if ($isOpeningMarker) { if ($this->odf_text_standard) { $this->odf_text_standard->openTextStyle($style, true, $isEmbeddedMarker); } if ($this->odf_text_notes) { $this->odf_text_notes->openTextStyle($style, false, $isEmbeddedMarker); } if ($this->html_text_standard) { $this->html_text_standard->openTextStyle($style, true, $isEmbeddedMarker); } if ($this->html_text_linked) { $this->html_text_linked->openTextStyle($style, true, $isEmbeddedMarker); } } else { if ($this->odf_text_standard) { $this->odf_text_standard->closeTextStyle(true, $isEmbeddedMarker); } if ($this->odf_text_notes) { $this->odf_text_notes->closeTextStyle(false, $isEmbeddedMarker); } if ($this->html_text_standard) { $this->html_text_standard->closeTextStyle(true, $isEmbeddedMarker); } if ($this->html_text_linked) { $this->html_text_linked->closeTextStyle(true, $isEmbeddedMarker); } } break; case FootEndNoteSubtypeParagraph: // The style of this is not yet implemented. if ($this->odf_text_standard) { $this->odf_text_standard->closeTextStyle(true, false); } if ($this->odf_text_notes) { $this->odf_text_notes->closeTextStyle(false, false); } if ($this->html_text_standard) { $this->html_text_standard->closeTextStyle(true, false); } if ($this->html_text_linked) { $this->html_text_linked->closeTextStyle(true, false); } break; default: break; } // UserBool1NoteAppliesToApocrypha: For xref too? break; case StyleTypeCrossreference: switch ($style['subtype']) { case CrossreferenceSubtypeCrossreference: if ($isOpeningMarker) { $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerCrossReference]); $citation = $this->getNoteCitation($style); if ($this->odf_text_standard) { $this->odf_text_standard->addNote($citation, $marker); } // Note citation in superscript in the document with text and note citations. if ($this->odf_text_text_and_note_citations) { $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle; $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript"); $this->odf_text_text_and_note_citations->addText($citation); $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle; } // Add a space if the paragraph has text already. if ($this->odf_text_notes) { if ($this->odf_text_notes->currentParagraphContent != "") { $this->odf_text_notes->addText(" "); } } // Add the note citation. And a no-break space (NBSP) after it. if ($this->odf_text_notes) { $this->odf_text_notes->addText($citation . Filter_Character::noBreakSpace()); } // Open note in the web page. $this->ensureNoteParagraphStyle($this->standardContentMarkerCrossReference, $this->styles[$this->standardContentMarkerCrossReference]); if ($this->html_text_standard) { $this->html_text_standard->addNote($citation, $this->standardContentMarkerCrossReference); } if ($this->html_text_linked) { $this->html_text_linked->addNote($citation, $this->standardContentMarkerCrossReference); } // Online Bible. //if ($this->onlinebible_text) $this->onlinebible_text->addNote (); } else { break 3; } break; case CrossreferenceSubtypeStandardContent: // The style of the standard content is already used in the note's body. // If means that the text style should be cleared // in order to return to the correct style for the paragraph. if ($this->odf_text_standard) { $this->odf_text_standard->closeTextStyle(true, false); } if ($this->odf_text_notes) { $this->odf_text_notes->closeTextStyle(false, false); } if ($this->html_text_standard) { $this->html_text_standard->closeTextStyle(true, false); } if ($this->html_text_linked) { $this->html_text_linked->closeTextStyle(true, false); } break; case CrossreferenceSubtypeContent: case CrossreferenceSubtypeContentWithEndmarker: if ($isOpeningMarker) { if ($this->odf_text_standard) { $this->odf_text_standard->openTextStyle($style, true, $isEmbeddedMarker); } if ($this->odf_text_notes) { $this->odf_text_notes->openTextStyle($style, false, $isEmbeddedMarker); } if ($this->html_text_standard) { $this->html_text_standard->openTextStyle($style, true, $isEmbeddedMarker); } if ($this->html_text_linked) { $this->html_text_linked->openTextStyle($style, true, $isEmbeddedMarker); } } else { if ($this->odf_text_standard) { $this->odf_text_standard->closeTextStyle(true, $isEmbeddedMarker); } if ($this->odf_text_notes) { $this->odf_text_notes->closeTextStyle(false, $isEmbeddedMarker); } if ($this->html_text_standard) { $this->html_text_standard->closeTextStyle(true, $isEmbeddedMarker); } if ($this->html_text_linked) { $this->html_text_linked->closeTextStyle(true, $isEmbeddedMarker); } } break; default: break; } break; default: $this->addToFallout("Marker not suitable in note context \\{$marker}", false); break; } } else { // Here is an unknown marker. Add the marker to fallout, plus any text that follows. $this->addToFallout("Unknown marker \\{$marker}", true); } } else { // Here is no marker. Treat it as text. if ($this->odf_text_standard) { $this->odf_text_standard->addNoteText($currentItem); } if ($this->odf_text_notes) { $this->odf_text_notes->addText($currentItem); } if ($this->html_text_standard) { $this->html_text_standard->addNoteText($currentItem); } if ($this->html_text_linked) { $this->html_text_linked->addNoteText($currentItem); } } } // "Close" the current note, so that any following note text, if malformed, // will be added to a new note, not to the last one created. if ($this->odf_text_standard) { $this->odf_text_standard->closeCurrentNote(); } if ($this->odf_text_notes) { $this->odf_text_notes->closeTextStyle(false, false); } if ($this->html_text_standard) { $this->html_text_standard->closeCurrentNote(); } if ($this->html_text_linked) { $this->html_text_linked->closeCurrentNote(); } //if ($this->onlinebible_text) $this->onlinebible_text->closeCurrentNote (); }
public function testNotesOpenDocumentOne() { $usfm = <<<'EOD' \id GEN \v 1 Text 1\x + \xt Isa. 1.1.\x*\x - \xt Isa. 2.2.\x*\x + \xt Isa. 3.3.\x*, text 2\f + \fk Word1: \fl Heb. \fq Explanation1.\f*\f + \fk Word2: \fl Heb. \fq Explanation2.\f*, text3.\f + \fk Test: \fl Heb. \fq Note at the very end.\f* EOD; $filter_text = new Filter_Text("phpunit"); $filter_text->odf_text_standard = new Odf_Text("phpunit"); $filter_text->addUsfmCode($usfm); $filter_text->run("Standard"); $filter_text->odf_text_standard->save("/tmp/TextTest.odt"); exec("odt2txt /tmp/TextTest.odt", $output, $return_var); $this->assertEquals(array("", "1" . Filter_Character::enSpace() . "Text 1a", "", "Isa. 1.1.", "", "Isa. 2.2.", "", "b", "", "Isa. 3.3.", "", ", text 21", "", "Word1: Heb. Explanation1.", "", "2", "", "Word2: Heb. Explanation2.", "", ", text3.3", "", "Test: Heb. Note at the very end.", ""), $output); }
/** * This filter inserts soft hyphens in $text. * It goes through $text character by character. * At the transition from any character in $firstset * to any character in $secondset, it inserts a soft hyphen. * $firstset: array of characters. * $secondset: array of characters. * $text: A string of text to operate on. * Returns: The hyphenated $text. */ public static function atTransition($firstset, $secondset, $text) { // Verify the input. if (!is_array($firstset)) { return $text; } if (count($firstset) == 0) { return $text; } if (!is_array($secondset)) { return $text; } if (count($secondset) == 0) { return $text; } if (!is_string($text)) { return ""; } // Split the text up into lines and go through each one. $lines = explode("\n", $text); foreach ($lines as &$line) { // Split the line up into an array of UTF8 Unicode characters. $characters = array(); if ($line != "") { preg_match_all('/./u', $line, $characters); $characters = $characters[0]; } // Processor flags. $previousCharacterWasRelevant = false; $thisCharacterIsRelevant = false; $isUsfm = false; // Process each character. foreach ($characters as $key => &$character) { // Skip USFM marker. if ($character == "\\") { $isUsfm = true; } if (!$isUsfm) { // Check whether to insert the soft hyphen here. $thisCharacterIsRelevant = in_array($character, $secondset); if ($thisCharacterIsRelevant && $previousCharacterWasRelevant) { if (!Filter_Hyphenate::nearWhiteSpace($characters, $key)) { $character = Filter_Character::softHyphen() . $character; } } // Flag for next iteration. $previousCharacterWasRelevant = in_array($character, $firstset); } if ($isUsfm) { // Look for the end of the USFM marker. if ($character == " ") { $isUsfm = false; } if ($character == "*") { $isUsfm = false; } } } // Re-assemble the line from the separate (updated) characters. $line = implode("", $characters); } // Assemble the hyphenated text from the separate lines. $text = implode("\n", $lines); return $text; }