@@ -58,6 +58,7 @@ public function line( $text, $nonNestables = array() ){
58
58
protected $ urlsLinked = true ; // Convert any URL into a link
59
59
protected $ safeMode = false ; // How strict are we about raw HTML code
60
60
protected $ strictMode ;
61
+ protected $ preserveIndentations = false ; // Do we add spacers to perserve indentations
61
62
protected $ liturgicalElements = false ; // Look for liturgical elements in the text
62
63
protected $ liturgicalHTML = true ; // Do we wrap liturgical elements in HTML tags
63
64
protected $ suppressAlleluia = false ; // Do we remove the word Alleluia from the text
@@ -173,6 +174,17 @@ function setUrlsLinked($urlsLinked){
173
174
return $ this ;
174
175
}
175
176
177
+ public function setPreserveIndentations (bool $ preserveIndentations ){
178
+ $ this ->preserveIndentations = $ preserveIndentations ;
179
+
180
+ if ( $ preserveIndentations )
181
+ $ this ->unmarkedBlockTypes = array ();
182
+ else
183
+ $ this ->unmarkedBlockTypes = array ('Code ' );
184
+
185
+ return $ this ;
186
+ }
187
+
176
188
public function setLiturgicalElements (bool $ liturgicalElements ){
177
189
$ this ->liturgicalElements = $ liturgicalElements ;
178
190
@@ -277,6 +289,25 @@ protected function linesElements(array $lines){
277
289
278
290
$ text = $ indent > 0 ? substr ($ line , $ indent ) : $ line ;
279
291
292
+ if ( $ this ->preserveIndentations && $ indent >= 4 ){
293
+ $ tabs = floor ( $ indent / 4 );
294
+
295
+ do {
296
+ if ( $ tabs >= 2 && $ this ->liturgicalHTML ){
297
+ $ text = '<span class="spacer-tab-x2"> </span> ' . $ text ;
298
+ $ tabs = $ tabs - 2 ;
299
+ }else {
300
+ if ( $ this ->liturgicalHTML )
301
+ $ text = '<span class="spacer-tab"> </span> ' . $ text ;
302
+ else
303
+ $ text = ' ' . $ text ;
304
+
305
+ --$ tabs ;
306
+ }
307
+ }
308
+ while ( $ tabs > 0 );
309
+ }
310
+
280
311
# ~
281
312
282
313
$ Line = array ('body ' => $ line , 'indent ' => $ indent , 'text ' => $ text );
@@ -1141,6 +1172,10 @@ protected function lineElements($text, $nonNestables = array()){
1141
1172
1142
1173
$ Excerpt = array ('text ' => $ excerpt , 'context ' => $ text );
1143
1174
1175
+ if ( !array_key_exists ( $ marker , $ ActiveInlineTypes ) || !is_array ( $ ActiveInlineTypes [$ marker ] ) ){
1176
+ $ ActiveInlineTypes [$ marker ] = array ();
1177
+ }
1178
+
1144
1179
foreach ($ ActiveInlineTypes [$ marker ] as $ inlineType ){
1145
1180
# check to see if the current inline type is nestable in the current context
1146
1181
@@ -1647,14 +1682,16 @@ protected function blockLiturgicalIntercession( $Line, array $CurrentBlock = nul
1647
1682
'marker ' => $ element ,
1648
1683
),
1649
1684
'element ' => array (
1650
- 'name ' => 'section ' ,
1651
- 'attributes ' => array (
1652
- 'class ' => 'intercession '
1653
- ),
1685
+ 'name ' => 'p ' ,
1654
1686
'elements ' => array (),
1655
1687
),
1656
1688
);
1657
1689
1690
+ if ( $ this ->liturgicalHTML ){
1691
+ $ Block ['element ' ]['name ' ] = 'section ' ;
1692
+ $ Block ['element ' ]['attributes ' ]['class ' ] = 'intercession ' ;
1693
+ }
1694
+
1658
1695
// $Block['element']['elements'][] =
1659
1696
$ this ->blockLiturgicalIntercessionFormat ( $ element , $ Text , $ Block );
1660
1697
@@ -1682,12 +1719,15 @@ protected function blockLiturgicalIntercessionFormat( $Element, $Text, &$BlockRe
1682
1719
}
1683
1720
1684
1721
1722
+ $ Text = trim ( $ Text );
1723
+
1724
+
1685
1725
if ( $ Type == 'introduction ' ){
1686
1726
$ Elements = array (
1687
1727
array (
1688
1728
'handler ' => array (
1689
1729
'function ' => 'lineElements ' ,
1690
- 'argument ' => ' ' . $ Text ,
1730
+ 'argument ' => $ Text ,
1691
1731
'destination ' => 'elements ' ,
1692
1732
),
1693
1733
)
@@ -1696,30 +1736,31 @@ protected function blockLiturgicalIntercessionFormat( $Element, $Text, &$BlockRe
1696
1736
}else if ( $ Type == 'response ' ){
1697
1737
$ Elements = array (
1698
1738
array (
1699
- 'name ' => 'span ' ,
1739
+ // 'name' => 'span',
1700
1740
'rawHtml ' => ' ' ,
1701
1741
'allowRawHtmlInSafeMode ' => true ,
1702
- 'attributes ' => array (
1703
- 'class ' => 'spacer ' ,
1704
- ),
1742
+ // 'attributes' => array(
1743
+ // 'class' => 'spacer',
1744
+ // ),
1705
1745
),
1706
1746
array (
1747
+ 'name ' => 'em ' ,
1707
1748
'handler ' => array (
1708
1749
'function ' => 'lineElements ' ,
1709
1750
'argument ' => $ Text ,
1710
1751
'destination ' => 'elements ' ,
1711
1752
),
1712
1753
)
1713
1754
);
1755
+
1756
+ if ( $ this ->liturgicalHTML ){
1757
+ $ Elements [0 ]['name ' ] = 'span ' ;
1758
+ $ Elements [0 ]['attributes ' ]['class ' ] = 'spacer ' ;
1759
+ unset( $ Elements [1 ]['name ' ] );
1760
+ }
1761
+
1714
1762
}else if ( $ Type == 'part1 ' ){
1715
1763
$ Elements = array (
1716
- // array(
1717
- // 'name' => 'span',
1718
- // 'text' => ' ',
1719
- // 'attributes' => array(
1720
- // 'class' => 'spacer',
1721
- // ),
1722
- // ),
1723
1764
array (
1724
1765
'handler ' => array (
1725
1766
'function ' => 'lineElements ' ,
@@ -1731,13 +1772,12 @@ protected function blockLiturgicalIntercessionFormat( $Element, $Text, &$BlockRe
1731
1772
}else if ( $ Type == 'part2 ' ){
1732
1773
$ Elements = array (
1733
1774
array (
1734
- 'name ' => 'span ' ,
1775
+ // 'name' => 'span',
1735
1776
'rawHtml ' => ' – ' ,
1736
1777
'allowRawHtmlInSafeMode ' => true ,
1737
- // 'text' =>
1738
- 'attributes ' => array (
1739
- 'class ' => 'spacer ' ,
1740
- ),
1778
+ // 'attributes' => array(
1779
+ // 'class' => 'spacer',
1780
+ // ),
1741
1781
),
1742
1782
array (
1743
1783
'handler ' => array (
@@ -1747,30 +1787,60 @@ protected function blockLiturgicalIntercessionFormat( $Element, $Text, &$BlockRe
1747
1787
),
1748
1788
)
1749
1789
);
1790
+
1791
+ if ( $ this ->liturgicalHTML ){
1792
+ $ Elements [0 ]['name ' ] = 'span ' ;
1793
+ $ Elements [0 ]['attributes ' ]['class ' ] = 'spacer ' ;
1794
+ unset( $ Elements [1 ]['name ' ] );
1795
+ }
1750
1796
}
1751
1797
1752
- $ ThisBlock = array (
1753
- 'name ' => 'div ' ,
1754
- 'attributes ' => array (
1755
- 'class ' => 'part- ' . $ Type ,
1756
- ),
1757
- 'elements ' => $ Elements
1758
- );
1798
+
1799
+
1800
+ if ( $ this ->liturgicalHTML ){
1801
+ $ ThisBlock = array (
1802
+ 'name ' => 'div ' ,
1803
+ 'attributes ' => array (
1804
+ 'class ' => 'part- ' . $ Type ,
1805
+ ),
1806
+ 'elements ' => $ Elements
1807
+ );
1808
+ }else {
1809
+ $ ThisBlock = $ Elements ;
1810
+ $ ThisBlock [] = array ('name ' => 'br ' );
1811
+ }
1759
1812
1760
1813
if ( $ Type == 'response ' ){
1761
1814
$ this ->intercessionResponse = $ ThisBlock ;
1762
1815
}
1763
1816
1764
- $ BlockReference ['element ' ]['elements ' ][] = $ ThisBlock ;
1817
+
1818
+
1819
+ if ( $ this ->liturgicalHTML ){
1820
+ $ BlockReference ['element ' ]['elements ' ][] = $ ThisBlock ;
1821
+ }else {
1822
+ foreach ( $ ThisBlock as $ a ){
1823
+ $ BlockReference ['element ' ]['elements ' ][] = $ a ;
1824
+ }
1825
+ }
1826
+
1827
+
1828
+ // var_dump( $BlockReference );
1765
1829
1766
1830
if ( $ Type == 'part2 ' ){
1767
1831
// Add the Response again
1768
- $ BlockReference ['element ' ]['elements ' ][] = $ this ->intercessionResponse ;
1832
+ // $BlockReference['element']['elements'][] = $this->intercessionResponse;
1833
+ if ( $ this ->liturgicalHTML ){
1834
+ $ BlockReference ['element ' ]['elements ' ][] = $ this ->intercessionResponse ;
1835
+ }else {
1836
+ foreach ( $ this ->intercessionResponse as $ a ){
1837
+ $ BlockReference ['element ' ]['elements ' ][] = $ a ;
1838
+ }
1839
+ }
1769
1840
}
1770
1841
1771
1842
1772
1843
return ;
1773
- // return $Elements;
1774
1844
}
1775
1845
1776
1846
protected function blockLiturgicalIntercessionContinue ($ Line , array $ CurrentBlock ){
@@ -1789,6 +1859,18 @@ protected function blockLiturgicalIntercessionContinue($Line, array $CurrentBloc
1789
1859
1790
1860
}
1791
1861
1862
+ protected function blockLiturgicalIntercessionComplete (array $ CurrentBlock ){
1863
+ // Remove the trailing <br> from the non-HTML version
1864
+ if ( $ this ->liturgicalHTML == false ){
1865
+ $ Elements = count ( $ CurrentBlock ['element ' ]['elements ' ] );
1866
+ if ( $ CurrentBlock ['element ' ]['elements ' ][ $ Elements - 1 ]['name ' ] == 'br ' ){
1867
+ unset( $ CurrentBlock ['element ' ]['elements ' ][$ Elements -1 ] );
1868
+ }
1869
+ }
1870
+
1871
+ return $ CurrentBlock ;
1872
+ }
1873
+
1792
1874
protected function inlineLiturgicalCross ($ Excerpt ){
1793
1875
$ Element = array (
1794
1876
'rawHtml ' => "✛ " ,
@@ -1805,7 +1887,7 @@ protected function inlineLiturgicalCross($Excerpt){
1805
1887
$ extent = 0 ;
1806
1888
$ remainder = $ Excerpt ['text ' ];
1807
1889
1808
- if ( preg_match ('/\[\+\]/ ' , $ remainder , $ matches ) ){
1890
+ if ( preg_match ('/^ \[\+\]/ ' , $ remainder , $ matches ) ){
1809
1891
$ extent += strlen ($ matches [0 ]);
1810
1892
$ remainder = substr ($ remainder , $ extent );
1811
1893
}else {
@@ -1821,7 +1903,7 @@ protected function inlineLiturgicalCross($Excerpt){
1821
1903
1822
1904
protected function inlineLiturgicalMidpoint ( $ Excerpt ){
1823
1905
$ Element = array (
1824
- 'rawHtml ' => "* " ,
1906
+ 'text ' => " * " , // Include the space to ensure it always has a space to the left (multiple spaces will collapse)
1825
1907
// 'allowRawHtmlInSafeMode' => true,
1826
1908
);
1827
1909
if ( $ this ->liturgicalHTML ){
@@ -1834,7 +1916,7 @@ protected function inlineLiturgicalMidpoint( $Excerpt ){
1834
1916
$ extent = 0 ;
1835
1917
$ remainder = $ Excerpt ['text ' ];
1836
1918
1837
- if ( preg_match ('/\[\*\]/ ' , $ remainder , $ matches ) ){
1919
+ if ( preg_match ('/^ \[\*\]/ ' , $ remainder , $ matches ) ){
1838
1920
$ extent += strlen ($ matches [0 ]);
1839
1921
$ remainder = substr ($ remainder , $ extent );
1840
1922
}else {
@@ -1850,7 +1932,7 @@ protected function inlineLiturgicalMidpoint( $Excerpt ){
1850
1932
1851
1933
protected function inlineLiturgicalDagger ( $ Excerpt ){
1852
1934
$ Element = array (
1853
- 'rawHtml ' => "† " ,
1935
+ 'rawHtml ' => " † " , // Include the space to ensure it always has a space to the left (multiple spaces will collapse)
1854
1936
'allowRawHtmlInSafeMode ' => true ,
1855
1937
);
1856
1938
if ( $ this ->liturgicalHTML ){
@@ -1863,7 +1945,7 @@ protected function inlineLiturgicalDagger( $Excerpt ){
1863
1945
$ extent = 0 ;
1864
1946
$ remainder = $ Excerpt ['text ' ];
1865
1947
1866
- if ( preg_match ('/\[t\]/ ' , $ remainder , $ matches ) ){
1948
+ if ( preg_match ('/^ \[t\]/ ' , $ remainder , $ matches ) ){
1867
1949
$ extent += strlen ($ matches [0 ]);
1868
1950
$ remainder = substr ($ remainder , $ extent );
1869
1951
}else {
@@ -1922,7 +2004,7 @@ protected function inlineOverUnderLine( $Excerpt ){
1922
2004
$ extent = 0 ;
1923
2005
$ remainder = $ Excerpt ['text ' ];
1924
2006
1925
- if ( preg_match ('/^_‾|‾_((.|\n)*?)_‾|‾_ /u ' , $ remainder , $ matches ) ){
2007
+ if ( preg_match ('/^(?: _‾|‾_) ((.|\n)*?)(?:‾_|_‾) /u ' , $ remainder , $ matches ) ){
1926
2008
$ extent += strlen ($ matches [0 ]);
1927
2009
$ remainder = substr ($ remainder , $ extent );
1928
2010
$ Element ['text ' ] = $ matches [1 ];
@@ -1932,8 +2014,6 @@ protected function inlineOverUnderLine( $Excerpt ){
1932
2014
$ remainder = substr ($ remainder , $ extent );
1933
2015
$ Element ['text ' ] = $ matches [1 ];
1934
2016
$ Element ['attributes ' ]['class ' ] = 'text-overline ' ;
1935
-
1936
- // }else if( preg_match('/^_((.|\n)*?)_/', $remainder, $matches) ){
1937
2017
}else if ( preg_match ('/^_((?: \\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us ' , $ remainder , $ matches ) ){
1938
2018
$ extent += strlen ($ matches [0 ]);
1939
2019
$ remainder = substr ($ remainder , $ extent );
0 commit comments