Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented interface for text-links #16

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions MwParserFromScratch/Nodes/Inline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public abstract class InlineNode : Node

}

public interface ITextLink
{
Run Target { get; set; }
Run Text { get; set; }

string ToPlainText();
}

public class PlainText : InlineNode
{
public PlainText() : this(null)
Expand Down Expand Up @@ -59,7 +67,7 @@ internal override void ToPlainTextCore(StringBuilder builder, NodePlainTextForma
/// <summary>
/// <c>[[Target|text]]</c>
/// </summary>
public class WikiLink : InlineNode
public class WikiLink : InlineNode, ITextLink
{
private Run _Target;
private Run _Text;
Expand Down Expand Up @@ -96,7 +104,7 @@ protected override Node CloneCore()

/// <inheritdoc />
public override string ToString() => Text == null ? $"[[{Target}]]" : $"[[{Target}|{Text}]]";

/// <param name="builder"></param>
/// <param name="formatter"></param>
/// <inheritdoc />
Expand Down Expand Up @@ -153,7 +161,7 @@ public WikiImageLink(Run target)
Target = target;
Arguments = new WikiImageLinkArgumentCollection(this);
}

/// <summary>
/// Title of the image.
/// </summary>
Expand Down Expand Up @@ -207,7 +215,7 @@ internal override void ToPlainTextCore(StringBuilder builder, NodePlainTextForma
if (alt != null) formatter(alt, builder);
var caption = Arguments.Caption;
// delimit alt text and caption with a space.
if (alt != null && caption != null)
if (alt != null && caption != null)
builder.Append(' ');
if (caption != null) formatter(caption, builder);
}
Expand Down Expand Up @@ -284,7 +292,7 @@ internal override void ToPlainTextCore(StringBuilder builder, NodePlainTextForma
}
}

public class ExternalLink : InlineNode
public class ExternalLink : InlineNode, ITextLink
{
private Run _Target;
private Run _Text;
Expand Down Expand Up @@ -342,7 +350,7 @@ internal override void ToPlainTextCore(StringBuilder builder, NodePlainTextForma
{
if (!Brackets)
{
formatter( Target, builder);
formatter(Target, builder);
}
else
{
Expand Down Expand Up @@ -714,7 +722,7 @@ public string ClosingTagTrailingWhitespace
public TagAttributeCollection Attributes { get; }

protected abstract void BuildContentString(StringBuilder builder);

/// <summary>
/// Enumerates the children of this node.
/// </summary>
Expand Down