상속: IMarkdownToken
예제 #1
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownTagInlineToken token, MarkdownInlineContext context)
 {
     if (engine.Options.Sanitize)
     {
         if (engine.Options.Sanitizer != null)
         {
             return(engine.Options.Sanitizer(token.RawMarkdown));
         }
         return(StringHelper.Escape(token.RawMarkdown));
     }
     return(token.RawMarkdown);
 }
예제 #2
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownTagInlineToken token, MarkdownInlineContext context)
 {
     if (renderer.Options.Sanitize)
     {
         if (renderer.Options.Sanitizer != null)
         {
             return(renderer.Options.Sanitizer(token.SourceInfo.Markdown));
         }
         return(StringHelper.Escape(token.SourceInfo.Markdown));
     }
     return(token.SourceInfo.Markdown);
 }
예제 #3
0
            public IMarkdownToken Validate(MarkdownEngine engine, MarkdownTagInlineToken token)
            {
                var m = OpeningTag.Match(token.Content);
                bool isOpeningTag = true;
                if (m.Length == 0)
                {
                    m = ClosingTag.Match(token.Content);
                    if (m.Length == 0)
                    {
                        return null;
                    }
                    isOpeningTag = false;
                }

                return ValidateCore(token, m, isOpeningTag);
            }
예제 #4
0
 private IMarkdownToken ValidateCore(MarkdownTagInlineToken token, Match m, bool isOpeningTag)
 {
     foreach (var validator in Validators)
     {
         if (isOpeningTag || !validator.OpeningTagOnly)
         {
             foreach (var tagName in validator.TagNames)
             {
                 if (string.Equals(tagName, m.Groups[1].Value, System.StringComparison.OrdinalIgnoreCase))
                 {
                     return ValidateOne(token, m, validator);
                 }
             }
         }
     }
     return null;
 }
예제 #5
0
 private IMarkdownToken ValidateOne(MarkdownTagInlineToken token, Match m, MarkdownTagValidationRule validator)
 {
     if (!string.IsNullOrEmpty(validator.CustomValidatorContractName))
     {
         if (CompositionHost == null)
         {
             Logger.LogWarning($"Unable to validate tag by contract({validator.CustomValidatorContractName}): CompositionHost is null.");
             return null;
         }
         var customValidators = GetCustomMarkdownTagValidators(validator);
         if (customValidators.Count == 0)
         {
             Logger.LogWarning($"Cannot find custom markdown tag validator by contract name: {validator.CustomValidatorContractName}.");
             return null;
         }
         if (customValidators.TrueForAll(av => av.Validate(token.Content)))
         {
             return null;
         }
     }
     return ValidateOneCore(token, m, validator);
 }
예제 #6
0
 private IMarkdownToken ValidateOneCore(MarkdownTagInlineToken token, Match m, MarkdownTagValidationRule validator)
 {
     switch (validator.Behavior)
     {
         case TagRewriteBehavior.Warning:
             Logger.LogWarning(string.Format(validator.MessageFormatter, m.Groups[1].Value, token.Content));
             return null;
         case TagRewriteBehavior.Error:
             Logger.LogError(string.Format(validator.MessageFormatter, m.Groups[1].Value, token.Content));
             return null;
         case TagRewriteBehavior.ErrorAndRemove:
             Logger.LogError(string.Format(validator.MessageFormatter, m.Groups[1].Value, token.Content));
             return new MarkdownIgnoreToken(token.Rule);
         case TagRewriteBehavior.None:
         default:
             return null;
     }
 }
예제 #7
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownTagInlineToken token, MarkdownInlineContext context)
 {
     if (engine.Options.Sanitize)
     {
         if (engine.Options.Sanitizer != null)
         {
             return engine.Options.Sanitizer(token.RawMarkdown);
         }
         return StringHelper.Escape(token.RawMarkdown);
     }
     return token.RawMarkdown;
 }
예제 #8
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownTagInlineToken token, MarkdownInlineContext context)
 {
     return(Insert(token, ExposeTokenName(token)));
 }
예제 #9
0
            public void Validate(MarkdownTagInlineToken token)
            {
                var m = OpeningTag.Match(token.RawMarkdown);
                bool isOpeningTag = true;
                if (m.Length == 0)
                {
                    m = ClosingTag.Match(token.RawMarkdown);
                    if (m.Length == 0)
                    {
                        return;
                    }
                    isOpeningTag = false;
                }

                ValidateCore(token, m, isOpeningTag);
            }
예제 #10
0
 private void ValidateOneCore(MarkdownTagInlineToken token, Match m, MarkdownTagValidationRule validator)
 {
     switch (validator.Behavior)
     {
         case TagValidationBehavior.Warning:
             Logger.LogWarning(string.Format(validator.MessageFormatter, m.Groups[1].Value, token.RawMarkdown));
             return;
         case TagValidationBehavior.Error:
             Logger.LogError(string.Format(validator.MessageFormatter, m.Groups[1].Value, token.RawMarkdown));
             return;
         case TagValidationBehavior.None:
         default:
             return;
     }
 }
예제 #11
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownTagInlineToken token, MarkdownInlineContext context)
 {
     return(this.Insert("Tag", this.GetSize(), Type.Leaf));
 }