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. 28
      ThirdParty/PJonDevelopment.BBCode/Classes/BBCodeHtmlFormatter.vb
  33. 2
      ThirdParty/PJonDevelopment.BBCode/Classes/BBCodeNode.vb
  34. 4
      ThirdParty/PJonDevelopment.BBCode/Classes/BBCodeText.vb
  35. 14
      ThirdParty/PJonDevelopment.BBCode/Interfaces/ITextFormatter.vb

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

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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/>";
}

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

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

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -10,7 +10,7 @@ namespace FLocal.Common.BBCodes {
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);
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>";

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("math") {
}
public override string Format(IPostParsingContext context, ITextFormatter formatter) {
public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string tex = "$$" + this.InnerBBCode + "$$";
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>";

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: 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();
if(inner == "") return "";
string marker = this.Default;

@ -10,7 +10,7 @@ namespace FLocal.Common.BBCodes {
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") {
return "";
} else if(this.Name.ToLower() == "code") {

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("spoiler") {
}
public override string Format(IPostParsingContext context, ITextFormatter formatter) {
public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string marker = this.Default;
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/>";

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: base("tex") {
}
public override string Format(IPostParsingContext context, ITextFormatter formatter) {
public override string Format(IPostParsingContext context, ITextFormatter<IPostParsingContext> formatter) {
string tex = this.InnerBBCode;
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>";

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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 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>";

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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 name = this.Safe(upload.filename);
if(this.Default != null) {

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

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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);
}

@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes {
: 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>";
}

@ -11,7 +11,7 @@ namespace FLocal.Common.BBCodes {
: 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();
foreach (var node in this.Nodes) {
builder.Append(node.Format(context, formatter));

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

@ -71,7 +71,7 @@ Public NotInheritable Class BBCodeDocument(Of TContext As Class)
''' </summary>
''' <returns>The formatted text.</returns>
Public Function Format(ByVal context As TContext) As String
Return Format(context, New BBCodeHtmlFormatter())
Return Format(context, New BBCodeHtmlFormatter(Of TContext)())
End Function
''' <summary>
@ -79,7 +79,7 @@ Public NotInheritable Class BBCodeDocument(Of TContext As Class)
''' </summary>
''' <param name="formatter">An object that implements the <see cref="ITextFormatter"/> interface.</param>
''' <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()
For Each n In Nodes
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>
''' <param name="formatter">An object that implements the <see cref="ITextFormatter" /> interface.</param>
''' <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
Dim sb As New Text.StringBuilder(Me.ReplacementFormat)
Dim attribs = __RxAttribute.Matches(Me.ReplacementFormat)
@ -241,7 +241,7 @@ Public Class BBCodeElement(Of TContext As Class)
End Set
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)
For Each attrib In attribs
If (String.CompareOrdinal(attrib, "VALUE") = 0) Then

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

@ -57,7 +57,7 @@ Public MustInherit Class BBCodeNode(Of TContext As Class)
''' </summary>
''' <param name="formatter">An object that implements the <see cref="ITextFormatter"/> interface.</param>
''' <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>
''' 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>
''' <param name="formatter">An object that implements the <see cref="ITextFormatter" /> interface.</param>
''' <returns>The text formatted by the <see cref="ITextFormatter" />.</returns>
Public Overrides Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter) As String
Return formatter.Format(__InnerText)
Public Overrides Function Format(ByVal context As TContext, ByVal formatter As ITextFormatter(Of TContext)) As String
Return formatter.Format(context, __InnerText)
End Function
''' <summary>Gets or sets the inner BBCode.</summary>

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

Loading…
Cancel
Save