Skip to content

Commit fe32aba

Browse files
committed
Add InlineContainer.Prepend method.
1 parent 0afc2ec commit fe32aba

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

MwParserFromScratch/MwParserFromScratch.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
99
<PackageProjectUrl>https://github.com/CXuesong/MwParserFromScratch</PackageProjectUrl>
1010
<Authors>CXuesong</Authors>
11-
<Version>0.1-int3a</Version>
11+
<Version>0.1-int4</Version>
1212
<PackageTags>MediaWiki Wikitext Parser</PackageTags>
1313
<RepositoryUrl>https://github.com/CXuesong/MwParserFromScratch</RepositoryUrl>
1414
<RepositoryType>Git</RepositoryType>
1515
<PackageReleaseNotes>See https://github.com/CXuesong/MwParserFromScratch/releases .</PackageReleaseNotes>
1616
<Description>A .NET Library for parsing wikitext into AST.</Description>
1717
<Copyright>Copyright (C) CXuesong, 2017</Copyright>
18-
<AssemblyVersion>0.1.1.3</AssemblyVersion>
18+
<AssemblyVersion>0.1.1.4</AssemblyVersion>
1919
<NeutralLanguage>en-us</NeutralLanguage>
20-
<FileVersion>0.1.1.3</FileVersion>
20+
<FileVersion>0.1.1.4</FileVersion>
2121
</PropertyGroup>
2222

2323
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

MwParserFromScratch/Nodes/Wikitext.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,26 @@ public InlineContainer(IEnumerable<InlineNode> nodes)
7373
if (nodes != null) Inlines.Add(nodes);
7474
}
7575

76+
/// <summary>
77+
/// Append a <see cref="PlainText"/> node to the beginning of the paragraph.
78+
/// </summary>
79+
/// <param name="text">The text to be inserted.</param>
80+
/// <returns>Either the new <see cref="PlainText"/> node inserted, or the existing <see cref="PlainText"/> at the beginning of the paragraph.</returns>
81+
/// <exception cref="ArgumentNullException"><paramref name="text"/> is <c>null</c>.</exception>
82+
public PlainText Prepend(string text)
83+
{
84+
if (text == null) throw new ArgumentNullException(nameof(text));
85+
var pt = Inlines.FirstNode as PlainText;
86+
if (pt == null) Inlines.AddFirst(pt = new PlainText());
87+
pt.Content = text + pt.Content;
88+
return pt;
89+
}
90+
7691
/// <summary>
7792
/// Append a <see cref="PlainText"/> node to the end of the paragraph.
7893
/// </summary>
7994
/// <param name="text">The text to be inserted.</param>
80-
/// <returns>Either the new <see cref="PlainText"/> node inserted, or the existing <see cref="PlainText"/> in the end of the paragraph.</returns>
95+
/// <returns>Either the new <see cref="PlainText"/> node inserted, or the existing <see cref="PlainText"/> at the end of the paragraph.</returns>
8196
/// <exception cref="ArgumentNullException"><paramref name="text"/> is <c>null</c>.</exception>
8297
public PlainText Append(string text)
8398
{

0 commit comments

Comments
 (0)