<?
#
#These functions handle everything except footnotes
#

function passage_xml_to_html($xml) { #for use on passage pages
    
$regex = array(
        
"!</?verse-unit[^>]*?>!" => ""#we don't need to show this in html
        
"!<heading([^>]*?)>(.*?)</heading>!" => "<h3$1>$2</h3>\n"#also used for psalm-book headings
        
"!<subheading([^>]*?)>(.*?)</subheading>!" => "<h4$1>$2</h4>\n",
        
"! virtual=\"virtual\"!" => ""#if begin- or end- tags were added programmatically to match, remove the attribute
        
"!<begin-paragraph([^>]*?)/>!" => "<p$1>",
        
"!<end-line class=\"br\"/>!" => "<br />\n",
        
"!<end-paragraph[^>]*?>!" => "</p>\n",
        
"!<br />\s*?</p>!" => "</p>"#eliminate trailing brs, which can happen with virtual paragraph endings
        
"!<span[^>]*?>(.*?)</span>!" => "<span class=\"small-caps\">$1</span>",
        
"!<verse-num>!" => "<span class=\"verse-num\">",
        
"!<verse-num class=\"woc\">!" => "<span class=\"verse-num-woc\">",
        
"!<verse-num begin-chapter=\"(\d+?)\"(?: class=\"woc\")?>1</verse-num>!" => "<span class=\"chapter-num\">$1:1</span>",
        
"!</verse-num>!" => "&nbsp;</span>"#the nbsp is to prevent a verse number from appearing at the end of a line
        
"!<begin-block-indent[^>]*?>!" => "<div class=\"block-indent\">\n",
        
"!<end-block-indent[^>]*?>!" => "</div>\n",
        
"!<begin-line class=\"indent\"/>!" => "<span class=\"indent\"></span>",
        
"!<begin-line class=\"indent-(\d+?)\"/>!" => "<span class=\"indent-$1\"></span>",
        
"!<crossref[^>]*?>!" => "",
        
"!<woc>(.*?)</woc>!s" => "<span class=\"woc\">$1</span>",
        
"!<begin-line class=\"([^\"]*?)\"/>!" => "<span class=\"$1-line\"></span>\n",
        
"!<selah>(.*?)</selah>!" => "<span class=\"selah\">$1</span>",
        
"!<(/?)i>!" => "<$1"."em>",
        
"!<(?:begin|end)-[^>]+?/>!" => ""#everything we need to convert has already been done; -chapter, some -line
        
);
    
$html preg_replace(array_keys($regex), array_values($regex), $xml);
    
$html translate_entities($html);
    return 
$html;
    }

function 
translate_entities($text) { #convert named entities to their html equivalents
    
$regex = array(
        
"/&ldblquot;/" => "&#8220;",
        
"/&rdblquot;/" => "&#8221;",
        
"/&lquot;/" => "&#8216;",
        
"/&rquot;/" => "&#8217;",
        
"/&apos;/" => "'"#so people using browser's find feature can enter a regular '
        
"/&emdash;/" => "&#8212;",
        
"/&endash;/" => "&#8211;",
        
"/&ellipsis;/" => "&nbsp;.&nbsp;.&nbsp;.",
        
"/&ellipsis4;/" => ".&nbsp;.&nbsp;.&nbsp;.",
        );
    return 
preg_replace(array_keys($regex), array_values($regex), $text);
    }

function 
translate_entities_to_simple_xml($text) {
    
$regex = array(
        
"/&ldblquot;/" => "&quot;",
        
"/&rdblquot;/" => "&quot;",
        
"/&lquot;/" => "'",
        
"/&rquot;/" => "'",
    
#    "/&apos;/" => "'", #&apos; always indicates a possessive quote
        
"/&emdash;/" => "--",
        
"/&endash;/" => "-",
        
"/&ellipsis;/" => "...",
        
"/&ellipsis4;/" => "....",
        );
    return 
preg_replace(array_keys($regex), array_values($regex), $text);
    }

?>