Пример #1
0
        /// <summary>
        /// Creates a list.
        /// </summary>
        /// <param name="authoringEngine"></param>
        /// <param name="parentElement"></param>
        /// <param name="list"></param>
        /// <param name="attributes"></param>
        /// <returns></returns>
        private static DomElement CreateList(IAuthoringEngine authoringEngine, DomElement parentElement,
                                             Internal.List list, BlockElementAttributes attributes)
        {
            int index = 0;

            return(CreateListRecursive(authoringEngine, parentElement, list, ref index, list.Items[index].Qualifier, attributes));
        }
Пример #2
0
        /// <summary>
        /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when
        /// a match is encountered.
        /// </summary>
        /// <param name="authoringEngine"></param>
        /// <param name="parentElement"></param>
        /// <param name="match"></param>
        protected override void ProcessMatch(IAuthoringEngine authoringEngine,
                                             DomElement parentElement, Match match)
        {
            Internal.List          list       = new Internal.List(match);
            BlockElementAttributes attributes = CreateBlockElementAttributes(match);

            parentElement.AppendChild(CreateList(authoringEngine, parentElement, list, attributes));
        }
Пример #3
0
        /// <summary>
        /// Recursively creates a list.
        /// </summary>
        /// <param name="authoringEngine"></param>
        /// <param name="parentElement"></param>
        /// <param name="list"></param>
        /// <param name="index"></param>
        /// <param name="previousQualifier"></param>
        /// <param name="attributes"></param>
        /// <returns></returns>
        private static DomElement CreateListRecursive(IAuthoringEngine authoringEngine,
                                                      DomElement parentElement, Internal.List list, ref int index, string previousQualifier,
                                                      BlockElementAttributes attributes)
        {
            //
            // Creating DOM object
            List domList = previousQualifier[previousQualifier.Length - 1] == '#' ?
                           (List) new OrderedList(parentElement, attributes) :
                           new UnorderedList(parentElement, attributes);

            //
            // Iterating through items.
            for (; index < list.Items.GetLength(0); ++index)
            {
                //
                // Creating DOM list item and adding it to the
                // list created above.
                ListItem listItem = new ListItem(domList, BlockElementAttributes.Empty);
                authoringEngine.ParseInlineElements(listItem, list.Items[index].Title);

                /*listItem.AppendChild(new TextBlock(listItem, InlineElementAttributes.Empty,
                 *  list.Items[index].Title, TextBlockFormatting.Unknown));*/

                domList.AppendChild(listItem);

                if (index < list.Items.GetLength(0) - 1)
                {
                    string nextQualifier = list.Items[index + 1].Qualifier;

                    if (nextQualifier.Length != previousQualifier.Length)
                    {
                        if (nextQualifier.Length > previousQualifier.Length)
                        {
                            ++index;
                            listItem.AppendChild(CreateListRecursive(authoringEngine,
                                                                     listItem, list, ref index, nextQualifier, BlockElementAttributes.Empty));
                        } // if
                        else
                        {
                            break;
                        }
                    } // if
                }     // if
            }         // for

            return(domList);
        }
Пример #4
0
        /// <summary>
        /// Creates partial start tag of a form "&lt;<paramref name="tag"/> id="<see cref="InlineElementAttributes.ID"/>"
        /// class="<see cref="InlineElementAttributes.CssClass"/>" style="<see cref="InlineElementAttributes.Style"/>"
        /// lang="<see cref="InlineElementAttributes.Language"/>".
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="attributes"></param>
        /// <returns></returns>
        protected static String GetPartialBlockStartTag(String tag, BlockElementAttributes attributes)
        {
            StringBuilder tagBuilder = new StringBuilder(GetPartialPhraseStartTagWithoutStyle(tag, attributes));

            //
            // Now we need to construct a new "style" attribute since values
            // in Alignment, LeftIndent and RightIndent may add something new.
            // On the other hand, they may not be specified at all, so
            // this should be taken into consideration too.
            if (attributes.Alignment != BlockElementAlignment.Unknown ||
                attributes.LeftIndent != 0 || attributes.RightIndent != 0 ||
                !IsNullOrEmpty(attributes.Style))
            {
                String style = String.Empty;
                if (!IsNullOrEmpty(attributes.Style))
                {
                    style += attributes.Style;
                    if (!style.EndsWith(";"))
                    {
                        style += ";";
                    }
                } // if

                if (attributes.Alignment != BlockElementAlignment.Unknown)
                {
                    style += String.Format("text-align: {0};",
                                           attributes.Alignment.ToString().ToLower());
                } // if

                if (attributes.LeftIndent != 0)
                {
                    style += String.Format("padding-left: {0}em;",
                                           attributes.LeftIndent);
                } // if

                if (attributes.RightIndent != 0)
                {
                    style += String.Format("padding-right: {0}em;",
                                           attributes.RightIndent);
                } // if

                tagBuilder.AppendFormat(" style=\"{0}\"", style);
            } // if

            return(tagBuilder.ToString());
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of <see cref="BlockElement"/> class with given properties.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="attributes"></param>
 protected BlockElement(DomElement parent, BlockElementAttributes attributes) :
     base(parent)
 {
     this.attributes = attributes;
 }
Пример #6
0
 /// <summary>
 /// Creates a full start tag of a form "&lt;<paramref name="tag"/> id="<see cref="InlineElementAttributes.ID"/>"
 /// class="<see cref="InlineElementAttributes.CssClass"/>" style="<see cref="InlineElementAttributes.Style"/>"
 /// lang="<see cref="InlineElementAttributes.Language"/>">".
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="attributes"></param>
 /// <returns></returns>
 protected static String GetFullBlockStartTag(String tag, BlockElementAttributes attributes)
 {
     return(GetPartialBlockStartTag(tag, attributes) + ">");
 }