@@ -187,12 +187,11 @@ private static void GenerateCoverImage(ImagePart imagePart1)
187187 /// </summary>
188188 /// <param name="rp">Current Run Properties, because special style may be nesting so we need keep it</param>
189189 /// <param name="inline">Current Inline element</param>
190- /// <param name="docPara ">In which we append out text</param>
191- private static void CovertMDInlines ( RunProperties rp , IList < MarkdownInline > inlines , ref Paragraph docPara )
190+ /// <param name="paragraph ">In which we append out text</param>
191+ private static void CovertMDInlines ( RunProperties rp , IList < MarkdownInline > inlines , ref Paragraph paragraph , ref List < Paragraph > paragraphs )
192192 {
193193 foreach ( MarkdownInline inline in inlines )
194194 {
195-
196195 switch ( inline )
197196 {
198197 case TextRunInline mtxt :
@@ -201,7 +200,7 @@ private static void CovertMDInlines(RunProperties rp, IList<MarkdownInline> inli
201200 Text dtext = new Text { Text = mtxt . Text , Space = SpaceProcessingModeValues . Preserve } ;
202201 trun . Append ( newtrp ) ;
203202 trun . Append ( dtext ) ;
204- docPara . Append ( trun ) ;
203+ paragraph . Append ( trun ) ;
205204 break ;
206205 case CodeInline mcode :
207206 RunProperties newcrp = ( RunProperties ) rp . Clone ( ) ;
@@ -210,34 +209,51 @@ private static void CovertMDInlines(RunProperties rp, IList<MarkdownInline> inli
210209 Text dcode = new Text { Text = mcode . Text } ;
211210 crun . Append ( newcrp ) ;
212211 crun . Append ( dcode ) ;
213- docPara . Append ( crun ) ;
212+ paragraph . Append ( crun ) ;
214213 break ;
215214 case BoldTextInline bd :
216215 RunProperties newbrp = ( RunProperties ) rp . Clone ( ) ;
217216 newbrp . Bold = new Bold ( ) ;
218217 newbrp . BoldComplexScript = new BoldComplexScript ( ) ;
219- CovertMDInlines ( newbrp , bd . Inlines , ref docPara ) ;
218+ CovertMDInlines ( newbrp , bd . Inlines , ref paragraph , ref paragraphs ) ;
220219 break ;
221220 case ItalicTextInline it :
222221 RunProperties newirp = ( RunProperties ) rp . Clone ( ) ;
223222 newirp . Italic = new Italic ( ) ;
224223 newirp . ItalicComplexScript = new ItalicComplexScript ( ) ;
225- CovertMDInlines ( newirp , it . Inlines , ref docPara ) ;
224+ CovertMDInlines ( newirp , it . Inlines , ref paragraph , ref paragraphs ) ;
226225 break ;
227226 case StrikethroughTextInline st :
228227 RunProperties newstrp = ( RunProperties ) rp . Clone ( ) ;
229228 newstrp . Strike = new Strike ( ) ;
230- CovertMDInlines ( newstrp , st . Inlines , ref docPara ) ;
229+ CovertMDInlines ( newstrp , st . Inlines , ref paragraph , ref paragraphs ) ;
231230 break ;
232231 case SubscriptTextInline sb :
233232 RunProperties newsbrp = ( RunProperties ) rp . Clone ( ) ;
234233 newsbrp . VerticalTextAlignment = new VerticalTextAlignment ( ) { Val = VerticalPositionValues . Subscript } ;
235- CovertMDInlines ( newsbrp , sb . Inlines , ref docPara ) ;
234+ CovertMDInlines ( newsbrp , sb . Inlines , ref paragraph , ref paragraphs ) ;
236235 break ;
237236 case SuperscriptTextInline sp :
238237 RunProperties newsprp = ( RunProperties ) rp . Clone ( ) ;
239238 newsprp . VerticalTextAlignment = new VerticalTextAlignment ( ) { Val = VerticalPositionValues . Superscript } ;
240- CovertMDInlines ( newsprp , sp . Inlines , ref docPara ) ;
239+ CovertMDInlines ( newsprp , sp . Inlines , ref paragraph , ref paragraphs ) ;
240+ break ;
241+ case ImageInline img :
242+ ParagraphProperties newpp = ( ParagraphProperties ) paragraph . ParagraphProperties . Clone ( ) ;
243+ paragraphs . Add ( paragraph ) ;
244+ paragraph = new Paragraph
245+ {
246+ ParagraphProperties = new ParagraphProperties
247+ {
248+ ParagraphStyleId = new ParagraphStyleId { Val = "Image Title" }
249+ }
250+ } ;
251+ Run run = new Run ( ) ;
252+ Text txt = new Text { Text = img . Tooltip , Space = SpaceProcessingModeValues . Preserve } ;
253+ run . Append ( txt ) ;
254+ paragraph . Append ( run ) ;
255+ paragraphs . Add ( paragraph ) ;
256+ paragraph = new Paragraph { ParagraphProperties = newpp } ;
241257 break ;
242258 default :
243259 Console . WriteLine ( inline . ToString ( ) ) ;
@@ -251,31 +267,32 @@ private static void CovertMDInlines(RunProperties rp, IList<MarkdownInline> inli
251267 /// </summary>
252268 /// <param name="block">Paragraph block, when block is not paragraph block, it throw a exception</param>
253269 /// <param name="docBody">In which we append our text</param>
254- private static void CovertQuoteRefer ( MarkdownBlock block , ref Body docBody )
270+ private static List < Paragraph > CovertQuoteRefer ( QuoteBlock refer )
255271 {
256- if ( ! ( block is ParagraphBlock ) )
257- {
258- throw new Exception ( $ "Rendering { block . GetType ( ) } in reference in quote not support") ;
259- }
260- Paragraph docPara = new Paragraph
272+ List < Paragraph > paragraphs = new List < Paragraph > ( ) ;
273+
274+ foreach ( MarkdownBlock block in refer . Blocks )
261275 {
262- ParagraphProperties = new ParagraphProperties
276+
277+ if ( ! ( block is ParagraphBlock ) )
263278 {
264- ParagraphStyleId = new ParagraphStyleId { Val = correspondecs [ "引用" ] }
279+ throw new Exception ( $ "Rendering { block . GetType ( ) } in reference in quote not support" ) ;
265280 }
266- } ;
267- Run run = new Run
268- {
269- RunProperties = new RunProperties ( )
270- } ;
271- Text txt = new Text
272- {
273- Text = block . ToString ( ) ,
274- Space = SpaceProcessingModeValues . Preserve
275- } ;
276- run . Append ( txt ) ;
277- docPara . Append ( run ) ;
278- docBody . Append ( docPara ) ;
281+ Paragraph paragraph = new Paragraph
282+ {
283+ ParagraphProperties = new ParagraphProperties
284+ {
285+ ParagraphStyleId = new ParagraphStyleId { Val = correspondecs [ "引用" ] }
286+ }
287+ } ;
288+ Run run = new Run { RunProperties = new RunProperties ( ) } ;
289+ Text txt = new Text { Text = block . ToString ( ) , Space = SpaceProcessingModeValues . Preserve } ;
290+ run . Append ( txt ) ;
291+ paragraph . Append ( run ) ;
292+ paragraphs . Add ( paragraph ) ;
293+ }
294+
295+ return paragraphs ;
279296 }
280297
281298 private static List < Paragraph > CovertCodeBlock ( CodeBlock code )
@@ -314,8 +331,12 @@ private static void CovertMarkdownBlock(MarkdownBlock block, ref Body docBody)
314331 ParagraphStyleId = new ParagraphStyleId { Val = correspondecs [ "正文" ] }
315332 }
316333 } ;
317- CovertMDInlines ( new RunProperties ( ) , mpara . Inlines , ref docPara ) ;
318- docBody . Append ( docPara ) ;
334+ List < Paragraph > paragraphs = new List < Paragraph > ( ) ;
335+ CovertMDInlines ( new RunProperties ( ) , mpara . Inlines , ref docPara , ref paragraphs ) ;
336+ foreach ( Paragraph paragraph in paragraphs )
337+ {
338+ docBody . Append ( paragraph ) ;
339+ }
319340 }
320341 else if ( block is CodeBlock mcode )
321342 {
@@ -328,6 +349,7 @@ private static void CovertMarkdownBlock(MarkdownBlock block, ref Body docBody)
328349 else if ( block is HeaderBlock mhead )
329350 {
330351 Paragraph docPara = new Paragraph { ParagraphProperties = new ParagraphProperties ( ) } ;
352+ List < Paragraph > paragraphs = new List < Paragraph > ( ) ;
331353 switch ( mhead . HeaderLevel )
332354 {
333355 case int i when i < 10 :
@@ -336,14 +358,19 @@ private static void CovertMarkdownBlock(MarkdownBlock block, ref Body docBody)
336358 default :
337359 throw new Exception ( $ "Rendering { block . GetType ( ) } not implement yet") ;
338360 }
339- CovertMDInlines ( new RunProperties ( ) , mhead . Inlines , ref docPara ) ;
340- docBody . Append ( docPara ) ;
361+ CovertMDInlines ( new RunProperties ( ) , mhead . Inlines , ref docPara , ref paragraphs ) ;
362+ paragraphs . Add ( docPara ) ;
363+ foreach ( Paragraph paragraph in paragraphs )
364+ {
365+ docBody . Append ( paragraph ) ;
366+ }
341367 }
342368 else if ( block is QuoteBlock refer )
343369 {
344- foreach ( var e in refer . Blocks )
370+ List < Paragraph > paragraphs = CovertQuoteRefer ( refer ) ;
371+ foreach ( Paragraph paragraph in paragraphs )
345372 {
346- CovertQuoteRefer ( e , ref docBody ) ;
373+ docBody . Append ( paragraph ) ;
347374 }
348375 }
349376 else if ( ! ( block is YamlHeaderBlock ) )
0 commit comments