Example #1
0
        /// <summary>
        /// Creates a partial start tag of a form "&lt;<paramref name="tag"/> id="<see cref="InlineElementAttributes.ID"/>"
        /// class="<see cref="InlineElementAttributes.CssClass"/>" lang="<see cref="InlineElementAttributes.Language"/>"".
        /// <para />
        /// Note that <c>style</c> attribute is missing.
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="attributes"></param>
        /// <returns></returns>
        protected static String GetPartialPhraseStartTagWithoutStyle(String tag, InlineElementAttributes attributes)
        {
            StringBuilder tagBuilder = new StringBuilder();

            tagBuilder.AppendFormat("<{0}", tag);

            if (attributes != null)
            {
                if (!IsNullOrEmpty(attributes.CssClass))
                {
                    tagBuilder.AppendFormat(" class=\"{0}\"", attributes.CssClass);
                }

                if (!IsNullOrEmpty(attributes.ID))
                {
                    tagBuilder.AppendFormat(" id=\"{0}\"", attributes.ID);
                }

                if (!IsNullOrEmpty(attributes.Language))
                {
                    tagBuilder.AppendFormat(" lang=\"{0}\"", attributes.Language);
                }
            } // if

            return(tagBuilder.ToString());
        }
Example #2
0
        /// <summary>
        /// Creates a partial start tag of a form "&lt;<paramref name="tag"/> id="<see cref="InlineElementAttributes.ID"/>"
        /// class="<see cref="InlineElementAttributes.CssClass"/>" lang="<see cref="InlineElementAttributes.Language"/>"
        /// style="<see cref="InlineElementAttributes.Style"/>"".
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="attributes"></param>
        /// <returns></returns>
        protected static String GetPartialPhraseStartTag(String tag, InlineElementAttributes attributes)
        {
            StringBuilder tagBuilder = new StringBuilder(GetPartialPhraseStartTagWithoutStyle(tag, attributes));

            if (attributes != null)
            {
                if (!IsNullOrEmpty(attributes.Style))
                {
                    tagBuilder.AppendFormat(" style=\"{0}", attributes.Style);

                    if (!attributes.Style.EndsWith(";"))
                    {
                        tagBuilder.Append(";\"");
                    }
                    else
                    {
                        tagBuilder.Append("\"");
                    }
                } // if
            }     // if

            return(tagBuilder.ToString());
        }
        /// <summary>
        /// Creates an instance of <see cref="BlockElementAttributes"/> class from the
        /// given <paramref name="match"/>, provided that <paramref name="match"/>
        /// has required groups (<c>CssClass</c>, <c>ID</c>, <c>Style</c>, <c>Language</c>,
        /// <c>Alignment</c>, <c>LeftIndent</c> and <c>RightIndent</c>).
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        protected static BlockElementAttributes CreateBlockElementAttributes(Match match)
        {
            InlineElementAttributes inlineElementAttributes =
                CreateInlineElementAttributes(match);

            //
            // Fetching values
            String alignment  = match.Groups["Alignment"].Value;
            String leftIndent = match.Groups["LeftIndent"].Captures.Count > 0 ?
                                match.Groups["LeftIndent"].Captures[0].Value :
                                match.Groups["LeftIndent"].Value;
            String rightIndent = match.Groups["RightIndent"].Captures.Count > 0 ?
                                 match.Groups["RightIndent"].Captures[0].Value :
                                 match.Groups["RightIndent"].Value;

            //
            // Determining block element alignment
            BlockElementAlignment elementAlignment = BlockElementAlignment.Unknown;

            if (!IsNullOrEmpty(alignment))
            {
                switch (alignment.ToUpper())
                {
                case "<":
                    elementAlignment = BlockElementAlignment.Left;
                    break;

                case ">":
                    elementAlignment = BlockElementAlignment.Right;
                    break;

                case "=":
                    elementAlignment = BlockElementAlignment.Center;
                    break;

                case "<>":
                    elementAlignment = BlockElementAlignment.Justify;
                    break;
                } // switch
            }     // if

            //
            // Determining indentation values
            Int32 leftIndentValue  = 0;
            Int32 rightIndentValue = 0;

            //
            // Left indent.
            if (!IsNullOrEmpty(leftIndent))
            {
                leftIndentValue = leftIndent.Length;
            }

            //
            // Right indent.
            if (!IsNullOrEmpty(rightIndent))
            {
                rightIndentValue = rightIndent.Length;
            }

            return(new BlockElementAttributes(inlineElementAttributes.CssClass,
                                              inlineElementAttributes.ID, inlineElementAttributes.Style, inlineElementAttributes.Language,
                                              elementAlignment, leftIndentValue, rightIndentValue));
        }