예제 #1
0
        /// <summary>
        /// Converts a tags array to a valid tags field text output for embedding.
        /// Used by <see cref="MetaCommand"/> and <see cref="MetaMechanism"/>.
        /// </summary>
        /// <param name="tags">The tags array.</param>
        /// <returns>The tags field text.</returns>
        public string GetTagsField(string[] tags)
        {
            int           limitLengthRemaining = 1000;
            StringBuilder tagsFieldBuilder     = new StringBuilder(tags.Length * 30);

            foreach (string tag in tags)
            {
                string tagOut = $"`{tag}`";
                if (tag.EndsWith(">"))
                {
                    MetaTag realTag = Program.CurrentMeta.FindTag(tag);
                    if (realTag == null)
                    {
                        tagOut += " (Invalid tag)";
                    }
                    else
                    {
                        tagOut += " " + realTag.Description.Replace("\n", " ");
                    }
                }
                if (tagOut.Length > 128)
                {
                    tagOut = tagOut.Substring(0, 100) + "...";
                }
                limitLengthRemaining -= tagOut.Length;
                tagsFieldBuilder.Append(tagOut).Append("\n");
                if (limitLengthRemaining <= 0)
                {
                    break;
                }
            }
            return(tagsFieldBuilder.ToString());
        }
예제 #2
0
 /// <summary>
 /// Post-check handler for tags, used in <see cref="MetaCommand"/> and <see cref="MetaMechanism"/>.
 /// </summary>
 /// <param name="docs">The relevant docs object.</param>
 /// <param name="tags">The relevant tags list.</param>
 public void PostCheckTags(MetaDocs docs, string[] tags)
 {
     foreach (string tag in tags)
     {
         if (tag.EndsWith(">"))
         {
             MetaTag realTag = docs.FindTag(tag);
             if (realTag == null)
             {
                 docs.LoadErrors.Add($"{Type.Name} '{Name}' references tag '{tag}', which doesn't exist.");
             }
         }
         PostCheckLinkableText(docs, tag);
     }
 }