PJonDevelopment.BBCode.ITextFormatter refactored to use generic context

main
Inga 🏳‍🌈 13 years ago
parent 43a8cdee27
commit a1b2bf6d72
  1. 2
      FLocal.Common/BBCodes/AbstractLocalLink.cs
  2. 2
      FLocal.Common/BBCodes/B.cs
  3. 2
      FLocal.Common/BBCodes/Code.cs
  4. 4
      FLocal.Common/BBCodes/ECode.cs
  5. 2
      FLocal.Common/BBCodes/FUrl.cs
  6. 2
      FLocal.Common/BBCodes/Font.cs
  7. 2
      FLocal.Common/BBCodes/FontColor.cs
  8. 2
      FLocal.Common/BBCodes/FontSize.cs
  9. 2
      FLocal.Common/BBCodes/Google.cs
  10. 2
      FLocal.Common/BBCodes/I.cs
  11. 2
      FLocal.Common/BBCodes/Image.cs
  12. 2
      FLocal.Common/BBCodes/List.cs
  13. 2
      FLocal.Common/BBCodes/ListElem.cs
  14. 2
      FLocal.Common/BBCodes/Lurk.cs
  15. 2
      FLocal.Common/BBCodes/Math.cs
  16. 2
      FLocal.Common/BBCodes/Quote.cs
  17. 2
      FLocal.Common/BBCodes/QuoteSkipper.cs
  18. 2
      FLocal.Common/BBCodes/RuWiki.cs
  19. 2
      FLocal.Common/BBCodes/S.cs
  20. 2
      FLocal.Common/BBCodes/Spoiler.cs
  21. 2
      FLocal.Common/BBCodes/Tex.cs
  22. 2
      FLocal.Common/BBCodes/U.cs
  23. 2
      FLocal.Common/BBCodes/UploadImage.cs
  24. 2
      FLocal.Common/BBCodes/UploadLink.cs
  25. 2
      FLocal.Common/BBCodes/Url.cs
  26. 2
      FLocal.Common/BBCodes/User.cs
  27. 2
      FLocal.Common/BBCodes/Wiki.cs
  28. 2
      FLocal.Common/BBCodes/helpers/BBCode.cs
  29. 18
      FLocal.Common/UBBParser.cs
  30. 4
      ThirdParty/PJonDevelopment.BBCode/Classes/BBCodeDocument.vb
  31. 4
      ThirdParty/PJonDevelopment.BBCode/Classes/BBCodeElement.vb
  32. 6
      ThirdParty/PJonDevelopment.BBCode/Classes/BBCodeHtmlFormatter.vb
  33. 2
      ThirdParty/PJonDevelopment.BBCode/Classes/BBCodeNode.vb
  34. 4
      ThirdParty/PJonDevelopment.BBCode/Classes/BBCodeText.vb
  35. 4
      ThirdParty/PJonDevelopment.BBCode/Interfaces/ITextFormatter.vb

@ -16,7 +16,7 @@ namespace FLocal.Common.BBCodes {
get; get;
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
var url = this.url; var url = this.url;
var name = this.Safe(url.title); var name = this.Safe(url.title);
if(this.Default != null) { if(this.Default != null) {

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("b") { : base("b") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<b>" + this.GetInnerHTML(context, formatter) + "</b>"; return "<b>" + this.GetInnerHTML(context, formatter) + "</b>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("code") { : base("code") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<pre>" + System.Web.HttpUtility.HtmlEncode(this.InnerBBCode) + "</pre><br/>"; return "<pre>" + System.Web.HttpUtility.HtmlEncode(this.InnerBBCode) + "</pre><br/>";
} }

@ -11,8 +11,8 @@ namespace FLocal.Common.BBCodes {
: base("ecode") { : base("ecode") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return this.GetInnerHTML(context, new BBCodeHtmlFormatter()); return this.GetInnerHTML(context, new BBCodeHtmlFormatter<BBCodes.IPostParsingContext>());
} }
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("furl") { : base("furl") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string rawUrl = this.DefaultOrValue; string rawUrl = this.DefaultOrValue;
string title = null; string title = null;
if(rawUrl.ToLower() != this.InnerText.ToLower()) { if(rawUrl.ToLower() != this.InnerText.ToLower()) {

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("font") { : base("font") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<font face=\"" + this.Default + "\">" + this.GetInnerHTML(context, formatter) + "</font>"; return "<font face=\"" + this.Default + "\">" + this.GetInnerHTML(context, formatter) + "</font>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("color") { : base("color") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<font color=\"" + this.Default + "\">" + this.GetInnerHTML(context, formatter) + "</font>"; return "<font color=\"" + this.Default + "\">" + this.GetInnerHTML(context, formatter) + "</font>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("size") { : base("size") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<font size=\"" + this.Default + "\">" + this.GetInnerHTML(context, formatter) + "</font>"; return "<font size=\"" + this.Default + "\">" + this.GetInnerHTML(context, formatter) + "</font>";
} }

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: base("google") { : base("google") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<a href=\"http://lmgtfy.com/?q=" + HttpUtility.UrlPathEncode(this.DefaultOrValue) + "\">g:" + this.GetInnerHTML(context, formatter) + "</a>"; return "<a href=\"http://lmgtfy.com/?q=" + HttpUtility.UrlPathEncode(this.DefaultOrValue) + "\">g:" + this.GetInnerHTML(context, formatter) + "</a>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("i") { : base("i") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<i>" + this.GetInnerHTML(context, formatter) + "</i>"; return "<i>" + this.GetInnerHTML(context, formatter) + "</i>";
} }

@ -10,7 +10,7 @@ namespace FLocal.Common.BBCodes {
public Image() : base("image") { public Image() : base("image") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
var urlInfo = UrlProcessor.Process(this.InnerText); var urlInfo = UrlProcessor.Process(this.InnerText);
if (urlInfo.isLocal && urlInfo.relativeUrl.StartsWith("/user/upload/")) { if (urlInfo.isLocal && urlInfo.relativeUrl.StartsWith("/user/upload/")) {
return "<f:img><f:src>" + urlInfo.relativeUrl + "</f:src><f:alt>" + urlInfo.relativeUrl + "</f:alt></f:img>"; return "<f:img><f:src>" + urlInfo.relativeUrl + "</f:src><f:alt>" + urlInfo.relativeUrl + "</f:alt></f:img>";

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("list") { : base("list") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<ul>" + this.GetInnerHTML(context, formatter) + "</ul>"; return "<ul>" + this.GetInnerHTML(context, formatter) + "</ul>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("*") { : base("*") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
// return "<li>" + this.GetInnerHTML(formatter) + "</li>"; // return "<li>" + this.GetInnerHTML(formatter) + "</li>";
return "<li>"; return "<li>";
} }

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: base("lurk") { : base("lurk") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<a href=\"http://lurkmore.ru/" + HttpUtility.UrlPathEncode(this.DefaultOrValue) + "\">l:" + this.GetInnerHTML(context, formatter) + "</a>"; return "<a href=\"http://lurkmore.ru/" + HttpUtility.UrlPathEncode(this.DefaultOrValue) + "\">l:" + this.GetInnerHTML(context, formatter) + "</a>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("math") { : base("math") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string tex = "$$" + this.InnerBBCode + "$$"; string tex = "$$" + this.InnerBBCode + "$$";
var upload = helpers.TexProcessor.getCompiled(tex); var upload = helpers.TexProcessor.getCompiled(tex);
return "<f:img><f:src>/Upload/Item/" + upload.id.ToString() + "/</f:src><f:alt>" + this.Safe(tex) + "</f:alt></f:img>"; return "<f:img><f:src>/Upload/Item/" + upload.id.ToString() + "/</f:src><f:alt>" + this.Safe(tex) + "</f:alt></f:img>";

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: base("quote") { : base("quote") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string inner = this.GetInnerHTML(context, formatter).TrimHtml(); string inner = this.GetInnerHTML(context, formatter).TrimHtml();
if(inner == "") return ""; if(inner == "") return "";
string marker = this.Default; string marker = this.Default;

@ -10,7 +10,7 @@ namespace FLocal.Common.BBCodes {
public QuoteSkipper() : base("quoteskipper") { public QuoteSkipper() : base("quoteskipper") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
if(this.Name.ToLower() == "q" || this.Name.ToLower() == "quote") { if(this.Name.ToLower() == "q" || this.Name.ToLower() == "quote") {
return ""; return "";
} else if(this.Name.ToLower() == "code") { } else if(this.Name.ToLower() == "code") {

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: base("ruwiki") { : base("ruwiki") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<a href=\"http://ru.wikipedia.org/wiki/" + HttpUtility.UrlPathEncode(this.DefaultOrValue) + "\">в:" + this.GetInnerHTML(context, formatter) + "</a>"; return "<a href=\"http://ru.wikipedia.org/wiki/" + HttpUtility.UrlPathEncode(this.DefaultOrValue) + "\">в:" + this.GetInnerHTML(context, formatter) + "</a>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("s") { : base("s") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<s>" + this.GetInnerHTML(context, formatter) + "</s>"; return "<s>" + this.GetInnerHTML(context, formatter) + "</s>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("spoiler") { : base("spoiler") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string marker = this.Default; string marker = this.Default;
if(marker == null) marker = "Spoiler"; if(marker == null) marker = "Spoiler";
return "<blockquote spoiler><font opener class=\"small\" onClick=\"showSpoiler(this)\">" + marker + "</font><hr/><div inner name=\"inner\" style=\"display:none\">" + this.GetInnerHTML(context, formatter).Trim() + "</div><hr/></blockquote><br/>"; return "<blockquote spoiler><font opener class=\"small\" onClick=\"showSpoiler(this)\">" + marker + "</font><hr/><div inner name=\"inner\" style=\"display:none\">" + this.GetInnerHTML(context, formatter).Trim() + "</div><hr/></blockquote><br/>";

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("tex") { : base("tex") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string tex = this.InnerBBCode; string tex = this.InnerBBCode;
var upload = helpers.TexProcessor.getCompiled(tex); var upload = helpers.TexProcessor.getCompiled(tex);
return "<f:img><f:src>/Upload/Item/" + upload.id.ToString() + "/</f:src><f:alt>" + this.Safe(tex) + "</f:alt></f:img>"; return "<f:img><f:src>/Upload/Item/" + upload.id.ToString() + "/</f:src><f:alt>" + this.Safe(tex) + "</f:alt></f:img>";

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("u") { : base("u") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<u>" + this.GetInnerHTML(context, formatter) + "</u>"; return "<u>" + this.GetInnerHTML(context, formatter) + "</u>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("uploadimage") { : base("uploadimage") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
var upload = dataobjects.Upload.LoadById(int.Parse(this.InnerText)); var upload = dataobjects.Upload.LoadById(int.Parse(this.InnerText));
var name = upload.filename; var name = upload.filename;
return "<f:img><f:src>/Upload/Item/" + upload.id.ToString() + "/</f:src><f:alt>" + this.Safe(upload.filename) + "</f:alt></f:img>"; return "<f:img><f:src>/Upload/Item/" + upload.id.ToString() + "/</f:src><f:alt>" + this.Safe(upload.filename) + "</f:alt></f:img>";

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("uploadlink") { : base("uploadlink") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
var upload = dataobjects.Upload.LoadById(int.Parse(this.DefaultOrValue)); var upload = dataobjects.Upload.LoadById(int.Parse(this.DefaultOrValue));
var name = this.Safe(upload.filename); var name = this.Safe(upload.filename);
if(this.Default != null) { if(this.Default != null) {

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("url") { : base("url") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string rawUrl = this.DefaultOrValue; string rawUrl = this.DefaultOrValue;
string title = null; string title = null;
if(rawUrl.ToLower() != this.InnerText.ToLower()) { if(rawUrl.ToLower() != this.InnerText.ToLower()) {

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("user") { : base("user") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return UserMentionProcessor.ProcessUserMention(context, this.DefaultOrValue); return UserMentionProcessor.ProcessUserMention(context, this.DefaultOrValue);
} }

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: base("wiki") { : base("wiki") {
} }
public override string Format(IPostParsingContext context, ITextFormatter formatter) { public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
return "<a href=\"http://en.wikipedia.org/wiki/" + HttpUtility.UrlPathEncode(this.DefaultOrValue) + "\">w:" + this.GetInnerHTML(context, formatter) + "</a>"; return "<a href=\"http://en.wikipedia.org/wiki/" + HttpUtility.UrlPathEncode(this.DefaultOrValue) + "\">w:" + this.GetInnerHTML(context, formatter) + "</a>";
} }

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base(name) { : base(name) {
} }
protected string GetInnerHTML(IPostParsingContext context, PJonDevelopment.BBCode.ITextFormatter formatter) { protected string GetInnerHTML(IPostParsingContext context, PJonDevelopment.BBCode.ITextFormatter<IPostParsingContext> formatter) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
foreach (var node in this.Nodes) { foreach (var node in this.Nodes) {
builder.Append(node.Format(context, formatter)); builder.Append(node.Format(context, formatter));

@ -14,20 +14,20 @@ namespace FLocal.Common {
private class BBParserGateway { private class BBParserGateway {
private class SimpleFormatter : ITextFormatter { private class SimpleFormatter : ITextFormatter<BBCodes.IPostParsingContext> {
public static readonly SimpleFormatter instance = new SimpleFormatter(); public static readonly SimpleFormatter instance = new SimpleFormatter();
private SimpleFormatter() { private SimpleFormatter() {
} }
public string Format(string source) { public string Format(BBCodes.IPostParsingContext context, string source) {
return source; return source;
} }
} }
private class TextFormatter : ITextFormatter { private class TextFormatter : ITextFormatter<BBCodes.IPostParsingContext> {
public static readonly TextFormatter instance = new TextFormatter(); public static readonly TextFormatter instance = new TextFormatter();
@ -86,14 +86,14 @@ namespace FLocal.Common {
{ new Regex("&lt;-", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => "←" }, { new Regex("&lt;-", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => "←" },
}; };
private ITextFormatter inner; private ITextFormatter<BBCodes.IPostParsingContext> inner;
private TextFormatter() { private TextFormatter() {
this.inner = new BBCodeHtmlFormatter(); this.inner = new BBCodeHtmlFormatter<BBCodes.IPostParsingContext>();
} }
public string Format(string source) { public string Format(BBCodes.IPostParsingContext context, string source) {
string result = this.inner.Format(source).Replace("&nbsp;", " "); string result = this.inner.Format(context, source).Replace("&nbsp;", " ");
result = LINKS_MATCHER.Replace(result, LINKS_REPLACE); result = LINKS_MATCHER.Replace(result, LINKS_REPLACE);
foreach(var smile in SMILEYS_DATA) { foreach(var smile in SMILEYS_DATA) {
result = smile.Key.Replace(result, smile.Value); result = smile.Key.Replace(result, smile.Value);
@ -110,10 +110,10 @@ namespace FLocal.Common {
public static readonly BBParserGateway instance = new BBParserGateway(); public static readonly BBParserGateway instance = new BBParserGateway();
private BBCodeParser<BBCodes.IPostParsingContext> parser; private BBCodeParser<BBCodes.IPostParsingContext> parser;
private ITextFormatter formatter; private ITextFormatter<BBCodes.IPostParsingContext> formatter;
private BBCodeParser<BBCodes.IPostParsingContext> quotesParser; private BBCodeParser<BBCodes.IPostParsingContext> quotesParser;
private ITextFormatter simpleFormatter; private ITextFormatter<BBCodes.IPostParsingContext> simpleFormatter;
private BBParserGateway() { private BBParserGateway() {
this.parser = new BBCodeParser<BBCodes.IPostParsingContext>(); this.parser = new BBCodeParser<BBCodes.IPostParsingContext>();

@ -71,7 +71,7 @@ Public NotInheritable Class BBCodeDocument(Of TContext As Class)
''' </summary> ''' </summary>
''' <returns>The formatted text.</returns> ''' <returns>The formatted text.</returns>
Public Function Format(ByVal context As TContext) As String Public Function Format(ByVal context As TContext) As String
Return Format(context, New BBCodeHtmlFormatter()) Return Format(context, New BBCodeHtmlFormatter(Of TContext)())
End Function End Function
''' <summary> ''' <summary>
@ -79,7 +79,7 @@ Public NotInheritable Class BBCodeDocument(Of TContext As Class)
''' </summary> ''' </summary>
''' <param name="formatter">An object that implements the <see cref="ITextFormatter"/> interface.</param> ''' <param name="formatter">An object that implements the <see cref="ITextFormatter"/> interface.</param>
''' <returns>The formatted text.</returns> ''' <returns>The formatted text.</returns>
Public Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter) As String Public Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter(Of TContext)) As String
Dim sb As New Text.StringBuilder() Dim sb As New Text.StringBuilder()
For Each n In Nodes For Each n In Nodes
sb.Append(n.Format(context, formatter)) sb.Append(n.Format(context, formatter))

@ -135,7 +135,7 @@ Public Class BBCodeElement(Of TContext As Class)
''' <summary>Transforms this instance of <see cref="BBCodeElement" /> into its desired text representation.</summary> ''' <summary>Transforms this instance of <see cref="BBCodeElement" /> into its desired text representation.</summary>
''' <param name="formatter">An object that implements the <see cref="ITextFormatter" /> interface.</param> ''' <param name="formatter">An object that implements the <see cref="ITextFormatter" /> interface.</param>
''' <returns>The text formatted by the <see cref="ITextFormatter" />.</returns> ''' <returns>The text formatted by the <see cref="ITextFormatter" />.</returns>
Public Overrides Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter) As String Public Overrides Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter(Of TContext)) As String
IsValueFormatted = False IsValueFormatted = False
Dim sb As New Text.StringBuilder(Me.ReplacementFormat) Dim sb As New Text.StringBuilder(Me.ReplacementFormat)
Dim attribs = __RxAttribute.Matches(Me.ReplacementFormat) Dim attribs = __RxAttribute.Matches(Me.ReplacementFormat)
@ -241,7 +241,7 @@ Public Class BBCodeElement(Of TContext As Class)
End Set End Set
End Property End Property
Private Function GetAttribute(ByVal name As String, ByVal context As TContext, ByVal formatter As ITextFormatter) As String Private Function GetAttribute(ByVal name As String, ByVal context As TContext, ByVal formatter As ITextFormatter(Of TContext)) As String
Dim attribs = name.ToUpperInvariant().Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) Dim attribs = name.ToUpperInvariant().Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
For Each attrib In attribs For Each attrib In attribs
If (String.CompareOrdinal(attrib, "VALUE") = 0) Then If (String.CompareOrdinal(attrib, "VALUE") = 0) Then

@ -18,15 +18,15 @@
''' <summary> ''' <summary>
''' Represnts an HTML generator for the <see cref="BBCodeParser"/>. ''' Represnts an HTML generator for the <see cref="BBCodeParser"/>.
''' </summary> ''' </summary>
Public NotInheritable Class BBCodeHtmlFormatter Public NotInheritable Class BBCodeHtmlFormatter(Of TContext As Class)
Implements ITextFormatter Implements ITextFormatter(Of TContext)
''' <summary> ''' <summary>
''' Generates the desired text from the specified source. ''' Generates the desired text from the specified source.
''' </summary> ''' </summary>
''' <param name="source">The source to generate the text.</param> ''' <param name="source">The source to generate the text.</param>
''' <returns>The text generated by the source.</returns> ''' <returns>The text generated by the source.</returns>
Public Function GenerateText(ByVal source As String) As String Implements ITextFormatter.Format Public Function GenerateText(ByVal context As TContext, ByVal source As String) As String Implements ITextFormatter(Of TContext).Format
Dim sb As New Text.StringBuilder(HtmlEncode(source)) Dim sb As New Text.StringBuilder(HtmlEncode(source))
sb.Replace(vbCrLf, vbLf) sb.Replace(vbCrLf, vbLf)
sb.Replace(vbCr, String.Empty) sb.Replace(vbCr, String.Empty)

@ -57,7 +57,7 @@ Public MustInherit Class BBCodeNode(Of TContext As Class)
''' </summary> ''' </summary>
''' <param name="formatter">An object that implements the <see cref="ITextFormatter"/> interface.</param> ''' <param name="formatter">An object that implements the <see cref="ITextFormatter"/> interface.</param>
''' <returns>The text formatted by the <see cref="ITextFormatter"/>.</returns> ''' <returns>The text formatted by the <see cref="ITextFormatter"/>.</returns>
Public MustOverride Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter) As String Public MustOverride Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter(Of TContext)) As String
''' <summary> ''' <summary>
''' When implemented in a derived class, gets or sets the inner BBCode. ''' When implemented in a derived class, gets or sets the inner BBCode.

@ -37,8 +37,8 @@ Public NotInheritable Class BBCodeText(Of TContext As Class)
''' <summary>Transforms this instance of <see cref="BBCodeText" /> into its desired text representation.</summary> ''' <summary>Transforms this instance of <see cref="BBCodeText" /> into its desired text representation.</summary>
''' <param name="formatter">An object that implements the <see cref="ITextFormatter" /> interface.</param> ''' <param name="formatter">An object that implements the <see cref="ITextFormatter" /> interface.</param>
''' <returns>The text formatted by the <see cref="ITextFormatter" />.</returns> ''' <returns>The text formatted by the <see cref="ITextFormatter" />.</returns>
Public Overrides Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter) As String Public Overrides Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter(Of TContext)) As String
Return formatter.Format(__InnerText) Return formatter.Format(context, __InnerText)
End Function End Function
''' <summary>Gets or sets the inner BBCode.</summary> ''' <summary>Gets or sets the inner BBCode.</summary>

@ -18,13 +18,13 @@
''' <summary> ''' <summary>
''' Defines a generic text formatter. ''' Defines a generic text formatter.
''' </summary> ''' </summary>
Public Interface ITextFormatter Public Interface ITextFormatter(Of TContext As Class)
''' <summary> ''' <summary>
''' Formats the specified text. ''' Formats the specified text.
''' </summary> ''' </summary>
''' <param name="source">The text to be formatted.</param> ''' <param name="source">The text to be formatted.</param>
''' <returns>The formatted text.</returns> ''' <returns>The formatted text.</returns>
Function Format(ByVal source As String) As String Function Format(ByVal context As TContext, ByVal source As String) As String
End Interface End Interface

Loading…
Cancel
Save