/**
  * Convert custom markup into HTML
  *
  * @param Note $note
  *
  * @return string
  */
 public static function formatCensusNote(Note $note)
 {
     global $WT_TREE;
     if (preg_match('/(.*)((?:\\n.*)*)\\n\\.start_formatted_area\\.\\n(.+)\\n(.+(?:\\n.+)*)\\n.end_formatted_area\\.((?:\\n.*)*)/', $note->getNote(), $match)) {
         // This looks like a census-assistant shared note
         $title = Filter::escapeHtml($match[1]);
         $preamble = Filter::escapeHtml($match[2]);
         $header = Filter::escapeHtml($match[3]);
         $data = Filter::escapeHtml($match[4]);
         $postamble = Filter::escapeHtml($match[5]);
         // Get the column headers for the census to which this note refers
         // requires the fact place & date to match the specific census
         // censusPlace() (Soundex match) and censusDate() functions
         $fmt_headers = array();
         $linkedRecords = array_merge($note->linkedIndividuals('NOTE'), $note->linkedFamilies('NOTE'));
         $firstRecord = array_shift($linkedRecords);
         if ($firstRecord) {
             $countryCode = '';
             $date = '';
             foreach ($firstRecord->getFacts('CENS') as $fact) {
                 if (trim($fact->getAttribute('NOTE'), '@') === $note->getXref()) {
                     $date = $fact->getAttribute('DATE');
                     $place = explode(',', strip_tags($fact->getPlace()->getFullName()));
                     $countryCode = Soundex::daitchMokotoff(array_pop($place));
                     break;
                 }
             }
             foreach (Census::allCensusPlaces() as $censusPlace) {
                 if (Soundex::compare($countryCode, Soundex::daitchMokotoff($censusPlace->censusPlace()))) {
                     foreach ($censusPlace->allCensusDates() as $census) {
                         if ($census->censusDate() == $date) {
                             foreach ($census->columns() as $column) {
                                 $abbrev = $column->abbreviation();
                                 if ($abbrev) {
                                     $description = $column->title() ? $column->title() : I18N::translate('Description unavailable');
                                     $fmt_headers[$abbrev] = '<span title="' . $description . '">' . $abbrev . '</span>';
                                 }
                             }
                             break 2;
                         }
                     }
                 }
             }
         }
         // Substitute header labels and format as HTML
         $thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>';
         $thead = str_replace('.b.', '', $thead);
         // Format data as HTML
         $tbody = '';
         foreach (explode("\n", $data) as $row) {
             $tbody .= '<tr>';
             foreach (explode('|', $row) as $column) {
                 $tbody .= '<td>' . $column . '</td>';
             }
             $tbody .= '</tr>';
         }
         return $title . "\n" . '<div class="markdown">' . '<p>' . $preamble . '</p>' . '<table>' . '<thead>' . $thead . '</thead>' . '<tbody>' . $tbody . '</tbody>' . '</table>' . '<p>' . $postamble . '</p>' . '</div>';
     } else {
         // Not a census-assistant shared note - apply default formatting
         return Filter::formatText($note->getNote(), $WT_TREE);
     }
 }
 /**
  * Convert custom markup into HTML
  *
  * @param Note $note
  *
  * @return string
  */
 public static function formatCensusNote(Note $note)
 {
     global $WT_TREE;
     $headers = array('AgM' => 'Age at first marriage', 'Age' => 'Age at last birthday', 'Assets' => 'Assets = Owned,Rented - Value,Rent - Radio - Farm', 'BIC' => 'Born in County', 'BOE' => 'Born outside England', 'BP' => 'Birthplace - (Chapman format)', 'Birthplace' => 'Birthplace (Full format)', 'Bmth' => 'Month of birth - If born within Census year', 'ChB' => 'Children born alive', 'ChD' => 'Children who have died', 'ChL' => 'Children still living', 'DOB' => 'Date of birth', 'Edu' => 'Education - At School, Can Read, Can Write', 'EmD' => 'Employed?', 'EmN' => 'Unemployed?', 'EmR' => 'Employer?', 'Employ' => 'Employment', 'Eng?' => 'English spoken?', 'EngL' => 'English spoken?, if not, Native Language', 'FBP' => 'Father’s Birthplace - (Chapman format)', 'Health' => 'Health - 1.Blind, 2.Deaf & Dumb, 3.Idiotic, 4.Insane, 5.Disabled etc', 'Home' => 'Home Ownership - Owned/Rented-Free/Mortgaged-Farm/House-Farm Schedule number', 'Industry' => 'Industry', 'Infirm' => 'Infirmities - 1. Deaf & Dumb, 2. Blind, 3. Lunatic, 4. Imbecile/feeble-minded', 'Lang' => 'If Foreign Born - Native Language', 'MBP' => 'Mother’s Birthplace - (Chapman format)', 'MC' => 'Marital Condition - Married, Single, Unmarried, Widowed or Divorced', 'Mmth' => 'Month of marriage - If married during Census Year', 'MnsE' => 'Months employed during Census Year', 'MnsU' => 'Months unemployed during Census Year', 'N/A' => 'If Foreign Born - Naturalized, Alien', 'NL' => 'If Foreign Born - Native Language', 'Name' => 'Full Name or Married name if married', 'Occupation' => 'Occupation', 'Par' => 'Parentage - Father if foreign born, Mother if foreign born', 'Race' => 'Race or Color - Black, White, Mulatto, Asian, Indian, Chinese etc', 'Relation' => 'Relationship to Head of Household', 'Sex' => 'Male or Female', 'Situ' => 'Situation - Disease, Infirmity, Convict, Pauper etc', 'Ten' => 'Tenure - Owned/Rented, (if owned)Free/Morgaged', 'Vet' => 'War Veteran?', 'WH' => 'Working at Home?', 'War' => 'War or Expedition', 'WksU' => 'Weeks unemployed during Census Year', 'YOI' => 'If Foreign Born - Year of immigration', 'YON' => 'If Foreign Born - Year of naturalization', 'YUS' => 'If Foreign Born - Years in the USA', 'YrsM' => 'Years Married, or Y if married in Census Year');
     if (preg_match('/(.*)((?:\\n.*)*)\\n\\.start_formatted_area\\.\\n(.*)((?:\\n.*)*)\\n.end_formatted_area\\.((?:\\n.*)*)/', $note->getNote(), $match)) {
         // This looks like a census-assistant shared note
         $title = Filter::escapeHtml($match[1]);
         $preamble = Filter::escapeHtml($match[2]);
         $header = Filter::escapeHtml($match[3]);
         $data = Filter::escapeHtml($match[4]);
         $postamble = Filter::escapeHtml($match[5]);
         $fmt_headers = array();
         foreach ($headers as $key => $value) {
             $fmt_headers[$key] = '<span title="' . Filter::escapeHtml($value) . '">' . $key . '</span>';
         }
         // Substitue header labels and format as HTML
         $thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>';
         $thead = str_replace('.b.', '', $thead);
         // Format data as HTML
         $tbody = '';
         foreach (explode("\n", $data) as $row) {
             $tbody .= '<tr>';
             foreach (explode('|', $row) as $column) {
                 $tbody .= '<td>' . $column . '</td>';
             }
             $tbody .= '</tr>';
         }
         return $title . "\n" . '<p>' . $preamble . '</p>' . '<table class="table-census-assistant">' . '<thead>' . $thead . '</thead>' . '<tbody>' . $tbody . '</tbody>' . '</table>' . '<p>' . $postamble . '</p>';
     } else {
         // Not a census-assistant shared note - apply default formatting
         return Filter::formatText($note->getNote(), $WT_TREE);
     }
 }