コード例 #1
0
ファイル: RichText.cs プロジェクト: kimduquan/DMIS
        private void RenderPortletPreview(HtmlTextWriter writer, Control container)
        {
            var controlCollection = container == null ? this.Controls : container.Controls;

            // custom view logic
            var text = _inputTextBox.Text;

            string currentText = text;
            var    markup      = PortletMarkup.GetFirstMarkup(currentText);

            while (markup != null)
            {
                var textBefore = currentText.Substring(0, markup.StartIndex);

                // render contents
                controlCollection.Add(new Literal {
                    Text = textBefore
                });
                markup.AddToControls(controlCollection);

                currentText = currentText.Substring(markup.EndIndex, currentText.Length - markup.EndIndex);

                markup = PortletMarkup.GetFirstMarkup(currentText);
            }
            controlCollection.Add(new Literal {
                Text = currentText
            });

            base.RenderContents(writer);
        }
コード例 #2
0
        public static PortletMarkup GetFirstMarkup(string text)
        {
            var snPortletMarkup = new PortletMarkup();

            try
            {
                var startIndex = text.IndexOf(MarkupStartFullTag);
                if (startIndex == -1)
                {
                    return(null);
                }

                // find closing 'table' tag, but the enclosed fraction should be well-formed with respect to the 'table' tags
                // (should contain equal number of opening and closing 'table' tags)
                snPortletMarkup.StartIndex = startIndex;
                var endIndex   = text.IndexOf(MarkupEndTag, startIndex);
                var innterText = text.Substring(startIndex, endIndex - startIndex + MarkupEndTag.Length);
                while (!IsValidMarkupSelection(innterText))
                {
                    endIndex   = text.IndexOf(MarkupEndTag, endIndex + 1);
                    innterText = text.Substring(startIndex, endIndex - startIndex + MarkupEndTag.Length);
                }

                // found valid innertext
                snPortletMarkup.EndIndex  = endIndex + MarkupEndTag.Length;
                snPortletMarkup.InnerText = innterText;

                // extract portlet information (resides in the section enclosed by the first 2 quatation marks)
                var sections    = innterText.Split(new char[] { '"' });
                var portletInfo = sections[1];

                var infos = portletInfo.Split(new char[] { ';' });
                snPortletMarkup.CustomRootPath = infos[0];
                snPortletMarkup.Renderer       = infos[1];
                return(snPortletMarkup);
            }
            catch
            {
                // could not extract portlet info from text fragment
                return(null);
            }
        }