Skip to content

Commit fb3fe8b

Browse files
authored
Merge pull request #838 from Melodi17/master
Implemented better indent control in TextRendererBase
2 parents abb19ec + 1482784 commit fb3fe8b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Markdig/Renderers/TextRendererBase.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) Alexandre Mutel. All rights reserved.
2-
// This file is licensed under the BSD-Clause 2 license.
2+
// This file is licensed under the BSD-Clause 2 license.
33
// See the license.txt file in the project root for more information.
44

55
using System.Diagnostics.CodeAnalysis;
@@ -174,10 +174,14 @@ public void PushIndent(string[] lineSpecific)
174174

175175
public void PopIndent()
176176
{
177-
// TODO: Check
178-
indents.RemoveAt(indents.Count - 1);
177+
if (this.indents.Count > 0)
178+
indents.RemoveAt(indents.Count - 1);
179+
else
180+
throw new InvalidOperationException("No indent to pop");
179181
}
180182

183+
public void ClearIndent() => indents.Clear();
184+
181185
[MethodImpl(MethodImplOptions.AggressiveInlining)]
182186
private protected void WriteIndent()
183187
{
@@ -220,12 +224,12 @@ public T Write(string? content)
220224
[MethodImpl(MethodImplOptions.AggressiveInlining)]
221225
internal T Write(char c, int count)
222226
{
223-
WriteIndent();
224-
227+
WriteIndent();
228+
225229
for (int i = 0; i < count; i++)
226230
{
227231
Writer.Write(c);
228-
}
232+
}
229233

230234
return (T)this;
231235
}

0 commit comments

Comments
 (0)