@@ -21,23 +21,21 @@ interface
2121
2222type
2323 TActiveTextTextRenderer = class (TObject)
24- public
24+ strict private
2525 const
2626 // / <summary>Special space character used to indicate the start of a list
2727 // / item.</summary>
2828 // / <remarks>This special character is a necessary kludge because some
29- // / c odethat renders active text as formatted plain text strips away
29+ // / code that renders active text as formatted plain text strips away
3030 // / leading #32 characters as part of the formatting process. Therefore
3131 // / indentation in list items is lost if #32 characters are used for it.
32- // / NBSP was chosen since it should render the same as a space if calling
33- // / code doesn't convert it .</remarks>
32+ // / NBSP was chosen since it should render the same as a space if not
33+ // / removed .</remarks>
3434 LISpacer = NBSP; // Do not localise. Must be <> #32
3535 // / <summary>Bullet character used when rendering unordered list items.
3636 // / </summary>
3737 Bullet = ' *' ; // Do not localise. Must be <> #32 and <> LISpacer
38- strict private
39- const
40- IndentDelta = 2 ;
38+ DefaultIndentDelta = 2 ;
4139 type
4240 TListKind = (lkNumber, lkBullet);
4341 TListState = record
@@ -60,6 +58,7 @@ TLIState = record
6058 fIndent: UInt16;
6159 fInPara: Boolean;
6260 fInListItem: Boolean;
61+ fIndentDelta: UInt8;
6362 function CanEmitInline : Boolean;
6463 procedure AppendToPara (const AText: string);
6564 procedure InitialiseRender ;
@@ -75,9 +74,10 @@ TLIState = record
7574 destructor Destroy; override;
7675 property DisplayURLs: Boolean read fDisplayURLs write fDisplayURLs
7776 default False;
78- function RenderWrapped (ActiveText: IActiveText; const PageWidth, LMargin,
79- ParaOffset: Cardinal; const Prefix: string = ' ' ;
80- const Suffix: string = ' ' ): string;
77+ property IndentDelta: UInt8 read fIndentDelta write fIndentDelta
78+ default DefaultIndentDelta;
79+ function RenderWrapped (ActiveText: IActiveText; const PageWidth,
80+ LMargin: Cardinal): string;
8181 end ;
8282
8383
@@ -122,6 +122,7 @@ constructor TActiveTextTextRenderer.Create;
122122 fIndent := 0 ;
123123 fInPara := False;
124124 fInListItem := False;
125+ fIndentDelta := DefaultIndentDelta;
125126end ;
126127
127128destructor TActiveTextTextRenderer.Destroy;
@@ -200,6 +201,21 @@ function TActiveTextTextRenderer.Render(ActiveText: IActiveText): string;
200201
201202procedure TActiveTextTextRenderer.RenderBlockActionElem (
202203 Elem: IActiveTextActionElem);
204+
205+ procedure OpenListContainer (const ListKind: TListKind);
206+ begin
207+ if (fListStack.Count > 0 ) and (fInPara) then
208+ OutputParagraph;
209+ fListStack.Push(TListState.Create(ListKind));
210+ Inc(fIndent, IndentDelta);
211+ end ;
212+
213+ procedure AddListMarker (const Marker: string);
214+ begin
215+ fParaBuilder.Append(Marker);
216+ fParaBuilder.Append(StringOfChar(NBSP, IndentDelta - Length(Marker)));
217+ end ;
218+
203219var
204220 ListState: TListState;
205221begin
@@ -208,22 +224,12 @@ procedure TActiveTextTextRenderer.RenderBlockActionElem(
208224 begin
209225 fBlocksStack.Push(Elem.Kind);
210226 case Elem.Kind of
211- ekPara: { Do nothing } ;
212- ekHeading: { Do nothing} ;
227+ ekPara, ekHeading, ekBlock:
228+ { Do nothing} ;
213229 ekUnorderedList:
214- begin
215- if (fListStack.Count > 0 ) and (fInPara) then
216- OutputParagraph;
217- fListStack.Push(TListState.Create(lkBullet));
218- Inc(fIndent, IndentDelta);
219- end ;
230+ OpenListContainer(lkBullet);
220231 ekOrderedList:
221- begin
222- if (fListStack.Count > 0 ) and (fInPara) then
223- OutputParagraph;
224- fListStack.Push(TListState.Create(lkNumber));
225- Inc(fIndent, IndentDelta);
226- end ;
232+ OpenListContainer(lkNumber);
227233 ekListItem:
228234 begin
229235 // Update list number of current list
@@ -235,34 +241,19 @@ procedure TActiveTextTextRenderer.RenderBlockActionElem(
235241 // Act depending on current list kind
236242 case fListStack.Peek.ListKind of
237243 lkNumber:
238- begin
239- // Number list: start a new numbered item, with current number
240- fParaBuilder.Append(IntToStr(fListStack.Peek.ListNumber));
241- fParaBuilder.Append(NBSP);
242- end ;
244+ AddListMarker(IntToStr(fListStack.Peek.ListNumber));
243245 lkBullet:
244- begin
245- // Bullet list: start a new bullet point
246- fParaBuilder.Append(Bullet + NBSP);
247- end ;
246+ AddListMarker(Bullet);
248247 end ;
249248 end ;
250249 end ;
251250 end ;
252251 fsClose:
253252 begin
254253 case Elem.Kind of
255- ekPara:
254+ ekPara, ekHeading, ekBlock :
256255 OutputParagraph;
257- ekHeading:
258- OutputParagraph;
259- ekUnorderedList:
260- begin
261- OutputParagraph;
262- fListStack.Pop;
263- Dec(fIndent, IndentDelta);
264- end ;
265- ekOrderedList:
256+ ekUnorderedList, ekOrderedList:
266257 begin
267258 OutputParagraph;
268259 fListStack.Pop;
@@ -315,7 +306,7 @@ procedure TActiveTextTextRenderer.RenderURL(Elem: IActiveTextActionElem);
315306end ;
316307
317308function TActiveTextTextRenderer.RenderWrapped (ActiveText: IActiveText;
318- const PageWidth, LMargin, ParaOffset : Cardinal; const Prefix, Suffix: string ):
309+ const PageWidth, LMargin: Cardinal):
319310 string;
320311var
321312 Paras: IStringList;
@@ -367,13 +358,13 @@ function TActiveTextTextRenderer.RenderWrapped(ActiveText: IActiveText;
367358
368359begin
369360 Result := ' ' ;
370- Paras := TIStringList.Create(Prefix + Render(ActiveText) + Suffix , EOL, True);
361+ Paras := TIStringList.Create(Render(ActiveText), EOL, True);
371362 for Para in Paras do
372363 begin
373364 if IsListItem then
374365 begin
375- Offset := -ParaOffset ;
376- ParaIndent := CalcParaIndent + LMargin + ParaOffset ;
366+ Offset := -IndentDelta ;
367+ ParaIndent := CalcParaIndent + LMargin + IndentDelta ;
377368 end
378369 else
379370 begin
0 commit comments