@@ -132,28 +132,45 @@ TREMLWriter = class(TNoPublicConstructObject)
132
132
@param Text [in] Plain text to be converted.
133
133
@return Converted text.
134
134
}
135
- function RenderTag (const TagElem: IActiveTextActionElem): string;
136
- { Renders an active text action element as a REML tag.
137
- @param TagElem [in] Active text action element to be rendered.
138
- @return Required REML tag.
139
- }
140
- function RenderText (const TextElem: IActiveTextTextElem): string;
141
- { Renders an active text text element. Illegal characters are converted to
142
- REML character entities.
143
- @param TextElem [in] Active text text element.
144
- @return REML-safe text containing necessary character entities.
145
- }
135
+ // / <summary>Renders an active text action element as a REML tag.</summary>
136
+ // / <param name="TagElem"><c>IActiveTextActionElem</c> [in] Active text
137
+ // / action element to be rendered.</param>
138
+ // / <param name="Formatted"><c>Boolean</c> [in] Optional flag that
139
+ // / determines if tag is to be rendered formatted as multiple, indented
140
+ // / lines of REML code (True) or with no formatting (False).</param>
141
+ // / <returns><c>string</c>. Required REML tag.</returns>
142
+ function RenderTag (const TagElem: IActiveTextActionElem;
143
+ const Formatted: Boolean): string;
144
+
145
+ // / <summary>Renders an active text text element. Illegal characters are
146
+ // / converted to REML character entities.</summary>
147
+ // / <param name="TextElem"><c>IActiveTextTextElem</c> [in] Active text text
148
+ // / element to be rendered.</param>
149
+ // / <param name="Indented"><c>Boolean</c> [in] Optional flag that
150
+ // / determines if text is to be rendered indented (True) or not (False).
151
+ // / </param>
152
+ // / <returns><c>string</c>. REML-safe text containing necessary character
153
+ // / entities.</returns>
154
+ function RenderText (const TextElem: IActiveTextTextElem;
155
+ const Indented: Boolean): string;
156
+
146
157
strict protected
147
158
constructor InternalCreate;
148
- { Internal class constructor. Sets up object to render active text document
159
+ { Internal constructor. Sets up object to render active text document
149
160
as REML.
150
161
}
151
162
public
152
- class function Render (const ActiveText: IActiveText): string;
153
- { Renders REML representation of an active text object.
154
- @param ActiveText [in] Active text to be rendered.
155
- @return String containing REML markup.
156
- }
163
+ // / <summary>Renders REML representation of an active text object.
164
+ // / </summary>
165
+ // / <param name="ActiveText"><c>IActiveText</c> [in] Active text to be
166
+ // / rendered.</param>
167
+ // / <param name="Formatted"><c>Boolean</c> [in] Optional flag that
168
+ // / determines if REML is to be rendered formatted as multiple lines of
169
+ // / indented text (True: the default) or as a single line of text with no
170
+ // / formatting (False).</param>
171
+ // / <returns><c>string</c> containing REML markup.</returns>
172
+ class function Render (const ActiveText: IActiveText;
173
+ const Formatted: Boolean = True): string;
157
174
end ;
158
175
159
176
@@ -719,11 +736,8 @@ constructor TREMLWriter.InternalCreate;
719
736
inherited InternalCreate;
720
737
end ;
721
738
722
- class function TREMLWriter.Render (const ActiveText: IActiveText): string;
723
- { Renders REML representation of an active text object.
724
- @param ActiveText [in] Active text to be rendered.
725
- @return String containing REML markup.
726
- }
739
+ class function TREMLWriter.Render (const ActiveText: IActiveText;
740
+ const Formatted: Boolean): string;
727
741
var
728
742
Elem: IActiveTextElem; // each element in active text object
729
743
TextElem: IActiveTextTextElem; // an active text text element
@@ -744,30 +758,31 @@ class function TREMLWriter.Render(const ActiveText: IActiveText): string;
744
758
for Elem in ActiveText do
745
759
begin
746
760
if Supports(Elem, IActiveTextTextElem, TextElem) then
747
- Text := Text + RW.RenderText(TextElem)
761
+ Text := Text + RW.RenderText(TextElem, Formatted )
748
762
else if Supports(Elem, IActiveTextActionElem, TagElem) then
749
- Text := Text + RW.RenderTag(TagElem);
763
+ Text := Text + RW.RenderTag(TagElem, Formatted );
750
764
end ;
751
- SrcLines := TIStringList.Create(Text, EOL, False);
752
- DestLines := TIStringList.Create;
753
- for SrcLine in SrcLines do
765
+ if Formatted then
754
766
begin
755
- DestLine := StrTrimRight(SrcLine);
756
- if not StrIsEmpty(DestLine) then
757
- DestLines.Add(DestLine);
758
- end ;
759
- Result := DestLines.GetText(EOL, False);
767
+ SrcLines := TIStringList.Create(Text, EOL, False);
768
+ DestLines := TIStringList.Create;
769
+ for SrcLine in SrcLines do
770
+ begin
771
+ DestLine := StrTrimRight(SrcLine);
772
+ if not StrIsEmpty(DestLine) then
773
+ DestLines.Add(DestLine);
774
+ end ;
775
+ Result := DestLines.GetText(EOL, False);
776
+ end
777
+ else
778
+ Result := StrTrim(Text);
760
779
finally
761
780
RW.Free;
762
781
end ;
763
782
end ;
764
783
765
- function TREMLWriter.RenderTag (
766
- const TagElem: IActiveTextActionElem): string;
767
- { Renders an active text action element as a REML tag.
768
- @param TagElem [in] Active text action element to be rendered.
769
- @return Required REML tag.
770
- }
784
+ function TREMLWriter.RenderTag (const TagElem: IActiveTextActionElem;
785
+ const Formatted: Boolean): string;
771
786
var
772
787
TagName: string; // name of tag
773
788
ParamName: string; // name of any parameter
@@ -785,7 +800,8 @@ function TREMLWriter.RenderTag(
785
800
if TActiveTextElemCaps.DisplayStyleOf(TagElem.Kind) = dsBlock then
786
801
begin
787
802
Dec(fLevel);
788
- Result := EOL + StrOfSpaces(IndentMult * fLevel) + Result + EOL;
803
+ if Formatted then
804
+ Result := EOL + StrOfSpaces(IndentMult * fLevel) + Result + EOL;
789
805
fIsStartOfTextLine := True;
790
806
end ;
791
807
end
@@ -815,15 +831,17 @@ function TREMLWriter.RenderTag(
815
831
);
816
832
if TActiveTextElemCaps.DisplayStyleOf(TagElem.Kind) = dsBlock then
817
833
begin
818
- Result := EOL + StrOfSpaces(IndentMult * fLevel) + Result + EOL;
834
+ if Formatted then
835
+ Result := EOL + StrOfSpaces(IndentMult * fLevel) + Result + EOL;
819
836
Inc(fLevel);
820
837
fIsStartOfTextLine := True;
821
838
end
822
839
else if TActiveTextElemCaps.DisplayStyleOf(TagElem.Kind) = dsInline then
823
840
begin
824
841
if fIsStartOfTextLine then
825
842
begin
826
- Result := StrOfSpaces(IndentMult * fLevel) + Result;
843
+ if Formatted then
844
+ Result := StrOfSpaces(IndentMult * fLevel) + Result;
827
845
fIsStartOfTextLine := False;
828
846
end ;
829
847
end ;
@@ -839,15 +857,10 @@ function TREMLWriter.RenderTag(
839
857
end ;
840
858
end ;
841
859
842
- function TREMLWriter.RenderText (
843
- const TextElem: IActiveTextTextElem): string;
844
- { Renders an active text text element. Illegal characters are converted to
845
- REML character entities.
846
- @param TextElem [in] Active text text element.
847
- @return REML-safe text containing necessary character entities.
848
- }
860
+ function TREMLWriter.RenderText (const TextElem: IActiveTextTextElem;
861
+ const Indented: Boolean): string;
849
862
begin
850
- if fIsStartOfTextLine then
863
+ if fIsStartOfTextLine and Indented then
851
864
begin
852
865
Result := StrOfSpaces(IndentMult * fLevel);
853
866
fIsStartOfTextLine := False;
0 commit comments