@@ -197,6 +197,21 @@ public class OpenXmlRegexTests
197197 </w:body>
198198</w:document>" ;
199199
200+ private const string LastRenderedPageBreakXmlString =
201+ @"<w:document xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main"">
202+ <w:body>
203+ <w:p>
204+ <w:r>
205+ <w:t>ThisIsAParagraphContainingNoNaturalLi</w:t>
206+ </w:r>
207+ <w:r>
208+ <w:lastRenderedPageBreak/>
209+ <w:t>neBreaksSoTheLineBreakIsForced.</w:t>
210+ </w:r>
211+ </w:p>
212+ </w:body>
213+ </w:document>" ;
214+
200215 private static string InnerText ( XContainer e )
201216 {
202217 return e . Descendants ( W . r )
@@ -365,5 +380,30 @@ public void CanReplaceTextWithFields()
365380 Assert . Equal ( 1 , count ) ;
366381 Assert . Equal ( "As stated in Article {__1} and this Section {__1.1}, this is described in Exhibit 4." , innerText ) ;
367382 }
383+
384+ [ Fact ]
385+ public void CanMatchDespiteInvisibleLayoutMarkers ( )
386+ {
387+ XDocument partDocument = XDocument . Parse ( LastRenderedPageBreakXmlString ) ;
388+ XElement p = partDocument . Descendants ( W . p ) . Last ( ) ;
389+
390+ using ( var stream = new MemoryStream ( ) )
391+ using ( WordprocessingDocument wordDocument = WordprocessingDocument . Create ( stream , DocumentType ) )
392+ {
393+ MainDocumentPart part = wordDocument . AddMainDocumentPart ( ) ;
394+ part . PutXDocument ( partDocument ) ;
395+
396+ var content = partDocument . Descendants ( W . p ) ;
397+ var regex = new Regex ( @"LineBreak" ) ;
398+ int count = OpenXmlRegex . Replace ( content , regex , "LB" , null ) ;
399+
400+ p = partDocument . Descendants ( W . p ) . Last ( ) ;
401+ string innerText = InnerText ( p ) ;
402+
403+ Assert . Equal ( 2 , count ) ;
404+ Assert . Equal ( "ThisIsAParagraphContainingNoNaturalLBsSoTheLBIsForced." , innerText ) ;
405+ }
406+ }
407+
368408 }
369409}
0 commit comments