Exemple #1
0
        private static bool MergeText(MarkdownToken current, string text, MarkdownTokens flag)
        {
            // Only allow merge if the previous token was text
            if (current == null || current.Type != MarkdownTokenType.Text)
            {
                return(false);
            }

            if (current.Flag.ShouldPreserve())
            {
                return(false);
            }

            // If the previous token was text, lessen the break but still don't allow merging
            if (current.Flag.HasFlag(MarkdownTokens.LineBreak) && !current.Flag.ShouldPreserve())
            {
                return(false);
            }

            // Text must have the same flags set
            if (current.Flag.HasFlag(MarkdownTokens.Italic) != flag.HasFlag(MarkdownTokens.Italic))
            {
                return(false);
            }

            if (current.Flag.HasFlag(MarkdownTokens.Bold) != flag.HasFlag(MarkdownTokens.Bold))
            {
                return(false);
            }

            if (current.Flag.HasFlag(MarkdownTokens.Code) != flag.HasFlag(MarkdownTokens.Code))
            {
                return(false);
            }

            if (!current.Flag.IsEnding())
            {
                current.Text = string.Concat(current.Text, text);
            }
            else if (current.Flag == MarkdownTokens.LineEnding)
            {
                return(false);
            }

            // Take on the ending of the merged token
            current.Flag = flag;

            return(true);
        }
Exemple #2
0
        private static void AppendEnding(StringBuilder stringBuilder, MarkdownToken token, bool preserveEnding = false)
        {
            if (token == null || stringBuilder.Length == 0 || !token.Flag.IsEnding())
            {
                return;
            }

            if (!preserveEnding && token.Flag.ShouldPreserve())
            {
                preserveEnding = true;
            }

            if (token.IsDoubleLineEnding())
            {
                stringBuilder.Append(preserveEnding ? string.Concat(Environment.NewLine, Environment.NewLine) : Environment.NewLine);
            }
            else if (token.IsSingleLineEnding())
            {
                stringBuilder.Append(preserveEnding ? Environment.NewLine : Space);
            }
        }
Exemple #3
0
 protected bool IsHeading(MarkdownToken token, int level, string text)
 {
     return(token.Type == MarkdownTokenType.Header &&
            token.Depth == level &&
            string.Equals(text, token.Text, StringComparison.OrdinalIgnoreCase));
 }
Exemple #4
0
 protected bool IsHeading(MarkdownToken token, int level)
 {
     return(token.Type == MarkdownTokenType.Header &&
            token.Depth == level);
 }