public static CharEntityFormat Modify(this CharEntityFormat format)
        {
            switch (format)
            {
            case CharEntityFormat.Hexadecimal:
                return(CharEntityFormat.Decimal);

            case CharEntityFormat.Decimal:
                return(CharEntityFormat.Hexadecimal);

            default:
                throw new ArgumentException(format.ToString(), nameof(format));
            }
        }
        internal string NumberAsString(CharEntityFormat format)
        {
            switch (format)
            {
            case CharEntityFormat.Hexadecimal:
                return(((int)Value).ToString("X", CultureInfo.InvariantCulture));

            case CharEntityFormat.Decimal:
                return(((int)Value).ToString(CultureInfo.InvariantCulture));

            default:
                throw new ArgumentException(ErrorMessages.UnknownEnumValue(format), nameof(format));
            }
        }
Exemple #3
0
        public MarkdownFormat(
            EmphasisStyle boldStyle           = EmphasisStyle.Asterisk,
            EmphasisStyle italicStyle         = EmphasisStyle.Asterisk,
            BulletListStyle bulletListStyle   = BulletListStyle.Asterisk,
            OrderedListStyle orderedListStyle = OrderedListStyle.Dot,
            HeadingStyle headingStyle         = HeadingStyle.NumberSign,
            HeadingOptions headingOptions     = HeadingOptions.EmptyLineBeforeAndAfter,
            TableOptions tableOptions         = TableOptions.FormatHeader
            | TableOptions.OuterDelimiter
            | TableOptions.Padding
            | TableOptions.EmptyLineBeforeAndAfter,
            CodeFenceStyle codeFenceStyle                   = CodeFenceStyle.Backtick,
            CodeBlockOptions codeBlockOptions               = CodeBlockOptions.EmptyLineBeforeAndAfter,
            CharEntityFormat charEntityFormat               = CharEntityFormat.Hexadecimal,
            HorizontalRuleFormat?horizontalRuleFormat       = null,
            AngleBracketEscapeStyle angleBracketEscapeStyle = AngleBracketEscapeStyle.Backslash)
        {
            BoldStyle        = boldStyle;
            ItalicStyle      = italicStyle;
            BulletListStyle  = bulletListStyle;
            OrderedListStyle = orderedListStyle;
            HeadingStyle     = headingStyle;
            HeadingOptions   = headingOptions;
            TableOptions     = tableOptions;
            CodeFenceStyle   = codeFenceStyle;
            CodeBlockOptions = codeBlockOptions;
            CharEntityFormat = charEntityFormat;

            if (BulletListStyle == BulletListStyle.Asterisk)
            {
                BulletItemStart = "* ";
            }
            else if (BulletListStyle == BulletListStyle.Plus)
            {
                BulletItemStart = "+ ";
            }
            else if (BulletListStyle == BulletListStyle.Minus)
            {
                BulletItemStart = "- ";
            }
            else
            {
                throw new InvalidOperationException(ErrorMessages.UnknownEnumValue(BulletListStyle));
            }

            if (BoldStyle == EmphasisStyle.Asterisk)
            {
                BoldDelimiter = "**";
            }
            else if (BoldStyle == EmphasisStyle.Underscore)
            {
                BoldDelimiter = "__";
            }
            else
            {
                throw new InvalidOperationException(ErrorMessages.UnknownEnumValue(BoldStyle));
            }

            if (ItalicStyle == EmphasisStyle.Asterisk)
            {
                ItalicDelimiter = "*";
            }
            else if (ItalicStyle == EmphasisStyle.Underscore)
            {
                ItalicDelimiter = "_";
            }
            else
            {
                throw new InvalidOperationException(ErrorMessages.UnknownEnumValue(ItalicStyle));
            }

            if (OrderedListStyle == OrderedListStyle.Dot)
            {
                OrderedItemStart = ". ";
            }
            else if (OrderedListStyle == OrderedListStyle.Parenthesis)
            {
                OrderedItemStart = ") ";
            }
            else
            {
                throw new InvalidOperationException(ErrorMessages.UnknownEnumValue(OrderedListStyle));
            }

            if (HeadingStyle == HeadingStyle.NumberSign)
            {
                HeadingStart = "#";
            }
            else
            {
                throw new InvalidOperationException(ErrorMessages.UnknownEnumValue(HeadingStyle));
            }

            if (CodeFenceStyle == CodeFenceStyle.Backtick)
            {
                CodeFence = "```";
            }
            else if (CodeFenceStyle == CodeFenceStyle.Tilde)
            {
                CodeFence = "~~~";
            }
            else
            {
                throw new InvalidOperationException(ErrorMessages.UnknownEnumValue(CodeFenceStyle));
            }

            if (horizontalRuleFormat != null)
            {
                Error.ThrowOnInvalidHorizontalRuleFormat(horizontalRuleFormat.Value);

                HorizontalRuleFormat = horizontalRuleFormat.Value;
            }
            else
            {
                HorizontalRuleFormat = HorizontalRuleFormat.Default;
            }

            if (HorizontalRuleStyle == HorizontalRuleStyle.Hyphen)
            {
                HorizontalRuleText = "-";
            }
            else if (HorizontalRuleStyle == HorizontalRuleStyle.Underscore)
            {
                HorizontalRuleText = "_";
            }
            else if (HorizontalRuleStyle == HorizontalRuleStyle.Asterisk)
            {
                HorizontalRuleText = "*";
            }
            else
            {
                throw new InvalidOperationException(ErrorMessages.UnknownEnumValue(HorizontalRuleStyle));
            }

            AngleBracketEscapeStyle = angleBracketEscapeStyle;
        }
Exemple #4
0
 public MarkdownFormat WithCharEntityFormat(CharEntityFormat charEntityFormat);
Exemple #5
0
 public MarkdownFormat(EmphasisStyle boldStyle = EmphasisStyle.Asterisk, EmphasisStyle italicStyle = EmphasisStyle.Asterisk, BulletListStyle bulletListStyle = BulletListStyle.Asterisk, OrderedListStyle orderedListStyle = OrderedListStyle.Dot, HeadingStyle headingStyle = HeadingStyle.NumberSign, HeadingOptions headingOptions = HeadingOptions.EmptyLineBeforeAndAfter, TableOptions tableOptions = TableOptions.FormatHeader | TableOptions.Padding | TableOptions.OuterDelimiter | TableOptions.EmptyLineBeforeAndAfter, CodeFenceStyle codeFenceStyle = CodeFenceStyle.Backtick, CodeBlockOptions codeBlockOptions = CodeBlockOptions.EmptyLineBeforeAndAfter, CharEntityFormat charEntityFormat = CharEntityFormat.Hexadecimal, HorizontalRuleFormat?horizontalRuleFormat = null);