Exemple #1
0
		public void TestDefaults()
		{
			TableCellInfo info = new TableCellInfo();
			info.Parse("");
			Assert.IsTrue(info.HasBorder);
			Assert.IsTrue(!info.IsHighlighted);
		}
Exemple #2
0
		public void TestSpans()
		{
			TableCellInfo info = new TableCellInfo();
			info.Parse("C10!R5T-");
			Assert.IsTrue(info.IsHighlighted);
			Assert.AreEqual(info.ColSpan, 10);
			Assert.AreEqual(info.RowSpan, 5);
		}
 public void TestErrorOnMissingIntegers()
 {
     TableCellInfo info = new TableCellInfo();
     string missing = "Missing";
     Assert.IsTrue(info.Parse("TW").StartsWith(missing));
     Assert.IsTrue(info.Parse("R").StartsWith(missing));
     Assert.IsTrue(info.Parse("C").StartsWith(missing));
     Assert.IsTrue(info.Parse("W").StartsWith(missing));
 }
Exemple #4
0
		public void TestCellAlignment()
		{
			TableCellInfo info = new TableCellInfo();
			info.Parse("]");
			Assert.AreEqual(info.CellAlignment, TableCellInfo.AlignOption.Right);
			info.Parse("[");
			Assert.AreEqual(info.CellAlignment, TableCellInfo.AlignOption.Left);
			info.Parse("^");
			Assert.AreEqual(info.CellAlignment, TableCellInfo.AlignOption.Center);
		}
Exemple #5
0
		public void TestTable()
		{
			TableCellInfo info = new TableCellInfo();
			info.Parse("T-T]");
			Assert.IsTrue(!info.HasBorder);
			Assert.AreEqual(info.TableAlignment, TableCellInfo.AlignOption.Right);
			info.Parse("T[");
			Assert.AreEqual(info.TableAlignment, TableCellInfo.AlignOption.Left);
			info.Parse("T^");
			Assert.AreEqual(info.TableAlignment, TableCellInfo.AlignOption.Center);
		}
 public void TableFormattingRulesSpanTest()
 {
     TableCellInfo info = new TableCellInfo();
     info.Parse("C10R3");
     Assert.AreEqual(info.ColSpan, 10);
     Assert.AreEqual(info.RowSpan, 3);
 }
 public void TableFormattingRulesColor()
 {
     TableCellInfo info = new TableCellInfo();
     info.Parse("!*red*+");
     Assert.IsTrue(info.IsHighlighted);
     Assert.AreEqual(info.BackgroundColor, "red");
     Assert.IsFalse(info.AllowBreaks);
 }
 public void TableFormattingRulesCellWidthTest()
 {
     TableCellInfo info = new TableCellInfo();
     info.Parse("W10");
     Assert.AreEqual(info.CellWidth, 10);
 }
Exemple #9
0
		public void TestWidths()
		{
			TableCellInfo info = new TableCellInfo();
			info.Parse("");
			Assert.IsTrue(info.TableWidth == TableCellInfo.UnspecifiedWidth);
			Assert.IsTrue(info.CellWidth == TableCellInfo.UnspecifiedWidth);
			info.Parse("TW1");
			Assert.AreEqual(1, info.TableWidth);
			info.Parse("TW100");
			Assert.AreEqual(100, info.TableWidth);
			info.Parse("TW100C2");
			Assert.AreEqual(100, info.TableWidth);
			info.Parse("W1");
			Assert.AreEqual(1, info.CellWidth);
			info.Parse("W100");
			Assert.AreEqual(100, info.CellWidth);
			info.Parse("W100C2");
			Assert.AreEqual(100, info.CellWidth);
			info.Parse("W100TW200C2");
			Assert.AreEqual(100, info.CellWidth);
			Assert.AreEqual(200, info.TableWidth);


		}
Exemple #10
0
		abstract public void WriteTableCell(string s,  bool isHighlighted, TableCellInfo.AlignOption alignment, int colSpan, int RowSpan, bool hasBorder, bool allowBreaks, int Width);
 public void TableFormattingRulesTestRightCell()
 {
     TableCellInfo info = new TableCellInfo();
     info.Parse("]");
     Assert.AreEqual(info.CellAlignment, AlignOption.Right);
 }
Exemple #12
0
		public void TestError()
		{
			TableCellInfo info = new TableCellInfo();
			Assert.IsTrue(info.Parse("T%") != null);
		}
Exemple #13
0
		[Test] public void TableFormattingRulesTestLeftCell()
		{
			TableCellInfo info = new TableCellInfo();
			info.Parse("[");
			Assert.AreEqual(info.CellAlignment, TableCellInfo.AlignOption.Left);
		}
Exemple #14
0
		override public void WriteTableCell(string s,  bool isHighlighted, TableCellInfo.AlignOption alignment, int colSpan, int rowSpan, bool hasBorder, bool allowBreaks, int width)
		{
			Write("<td  ");
			if (isHighlighted)
			{
				if (hasBorder)
					Write("class=\"TableCellHighlighted\"");
				else
					Write("class=\"TableCellHighlightedNoBorder\"");
			}			
			else
			{
				if (hasBorder)
					Write("class=\"TableCell\"");
				else
					Write("class=\"TableCellNoBorder\"");
			}

			if (!allowBreaks)
				Write(" nowrap ");
			if (width > 0)
				Write(" width=\"" + width + "%\" ");

			switch (alignment)
			{
				case TableCellInfo.AlignOption.None:
					break;

				case TableCellInfo.AlignOption.Left:
					Write(" align=\"left\" ");
					break;

				case TableCellInfo.AlignOption.Right:
					Write(" align=\"right\" ");
					break;

				case TableCellInfo.AlignOption.Center:
					Write(" align=\"center\" ");
					break;
			}

			if (colSpan != 1)
				Write(" colspan=\"" + colSpan + "\" ");
			if (rowSpan != 1)
				Write(" rowspan=\"" + rowSpan + "\" ");
				
			WriteLine(css() + ">" + s + "</td>");
		}
Exemple #15
0
		override public void WriteOpenTable(TableCellInfo.AlignOption alignment, bool hasBorder, int width)
		{
			string styles = "";
			Write("<table ");
			switch (alignment)
			{
				case TableCellInfo.AlignOption.None:
					break;

				case TableCellInfo.AlignOption.Left:
					styles += ";margin-left: 0; float: left ";
					Write(" align=\"left\" ");
					break;

				case TableCellInfo.AlignOption.Right:
					styles += ";margin-left: 0; float: right";
					break;

				case TableCellInfo.AlignOption.Center:
					Write(" align=\"center\" ");
					break;
			}
			if (width > 0)
				Write(" width=\"" + width + "%\" ");
			string cls = "TableClass";
			if (!hasBorder)
				cls = "TableWithoutBorderClass";
			WriteLine("cellpadding=\"2\" cellspacing=\"1\" class=\"" + cls + "\"" + css(styles) + ">");
		}
 public void TableFormattingRulesTest1()
 {
     TableCellInfo info = new TableCellInfo();
     info.Parse("!+");
     Assert.IsTrue(info.IsHighlighted);
     Assert.IsFalse(info.AllowBreaks);
     Assert.AreEqual(info.CellAlignment, AlignOption.None);
     Assert.AreEqual(info.CellWidth, TableCellInfo.UnspecifiedWidth);
     Assert.AreEqual(info.ColSpan, 1);
     Assert.AreEqual(info.RowSpan, 1);
     Assert.AreEqual(info.BackgroundColor, null);
 }
 public void TableFormattingRulesTestLeftCenter()
 {
     TableCellInfo info = new TableCellInfo();
     info.Parse("^");
     Assert.AreEqual(info.CellAlignment, AlignOption.Center);
 }
Exemple #18
0
		public void TestHighlight()
		{
			TableCellInfo info = new TableCellInfo();
			info.Parse("!");
			Assert.IsTrue(info.IsHighlighted);
		}
Exemple #19
0
        /// <summary>
        /// Main formatting function.  The process of formatting the input to the output starts here.
        /// </summary>
        public void Format()
        {
            if (Federation.GetPerformanceCounter(PerformanceCounterNames.TopicFormat) != null)
            {
                Federation.GetPerformanceCounter(PerformanceCounterNames.TopicFormat).Increment();
            }

            for(int i=0;i<35;i++) indiceCount[i] = 1 ;
            CurrentState = new NeutralState(this);
            _currentLineIndex = 0;
            bool inMultilineProperty = false;
            bool currentMultilinePropertyIsHidden = false;
            string multiLinePropertyDelim = null;
            bool inPreBlock = false;
            bool inExtendedPreBlock = false;
            string preBlockKey = null;
            bool resetCount=false ;
            bool resetNextCount=false ;
            int thisNest = 0 ;

            _output.Begin();

            for (int lineNumber = 0; lineNumber < _source.Count; lineNumber++)
            {
                StyledLine eachLine = (StyledLine) (_source[lineNumber]);
                string each = eachLine.Text;
                _output.Style = eachLine.Style;

                each = StripHTMLSpecialCharacters(each);

                if (inPreBlock)
                {
                    if ((each.StartsWith("}+") || each.StartsWith("}@")) && each.Substring(2).Trim() == preBlockKey)
                    {
                        Ensure(typeof(NeutralState),0,false,false);
                        inPreBlock = false;
                        inExtendedPreBlock = false;
                        preBlockKey = null;
                    }
                    else
                    {
                        if (false == currentMultilinePropertyIsHidden)
                        {
                            // each = each.Replace("\t", " 	");
                            each = each.Replace("\t","        ");
                            if (inExtendedPreBlock)
                            {
                                // Ensure(CurrentState.GetType(),0,false);
                                each = ProcessLineElements(each);
                            }
                            _output.Write(each);
                            _output.WriteEndLine();
                        }
                        _currentLineIndex++;
                    }
                    continue;
                }
                else if (!inMultilineProperty && (each.StartsWith("{+") || each.StartsWith("{@")))
                {
                    Ensure(typeof(PreState),0,false,false);
                    inPreBlock = true;
                    inExtendedPreBlock = each.StartsWith("{+");
                    preBlockKey = each.Substring(2).Trim();
                    continue;
                }

                // Make all the 8-space sequences into tabs
                each = Regex.Replace(each, " {8}", "\t");

                // See if this is the first line of a multiline propertyName.
                if (!inMultilineProperty && TopicParser.MultilinePropertyRegex.IsMatch(each))
                {
                    // OK, here we go -- time to output the header
                    Match m = TopicParser.MultilinePropertyRegex.Match(each);
                    string name = m.Groups["name"].Value;
                    string val = m.Groups["val"].Value;
                    string leader = m.Groups["leader"].Value;
                    string delim = m.Groups["delim"].Value;
                    multiLinePropertyDelim = TopicParser.ClosingDelimiterForOpeningMultilinePropertyDelimiter(delim);
                    currentMultilinePropertyIsHidden = leader == ":";

                    if (currentMultilinePropertyIsHidden) // just write the anchor for hidden page properties
                    {
                        _output.WriteOpenAnchor(name);
                        _output.WriteCloseAnchor();
                        _output.WriteLine("");
                    }
                    else
                    {
                        // Ensure(CurrentState.GetType(),0,false);
                        // Don't bother showing out hidden page properties
                        val = val.Trim();

                        // Do the normal processing
                        name = StripHTMLSpecialCharacters(name);
                        string linkedName = LinkWikiNames(name);

                        val = StripHTMLSpecialCharacters(val);
                        val = ProcessLineElements(val);

                        _output.WriteOpenProperty(linkedName);
                        _output.WriteOpenAnchor(name);
                        if (TopicParser.IsBehaviorPropertyDelimiter(delim))
                        {
                            _output.Write(delim);
                        }
                        _output.Write(val);
                    }
                    inMultilineProperty = true;
                    continue;
                }

                if (inMultilineProperty)
                {
                    if (each.StartsWith(multiLinePropertyDelim))
                    {
                        // We're done!
                        if (!currentMultilinePropertyIsHidden)
                        {
                            if (TopicParser.IsBehaviorPropertyDelimiter(multiLinePropertyDelim))
                            {
                                _output.Write(multiLinePropertyDelim);
                            }
                            // Make sure we close off things like tables before we close the propertyName.
                            Ensure(typeof(NeutralState),0,false,false);
                            _output.WriteCloseAnchor();
                            _output.WriteCloseProperty();
                        }
                        inMultilineProperty = false;
                        currentMultilinePropertyIsHidden = false;
                        continue;
                    }

                    // If it's a line for a propertyName behavior, just show it -- don't perform any processing
                    if (TopicParser.IsBehaviorPropertyDelimiter(multiLinePropertyDelim))
                    {
                        if (!currentMultilinePropertyIsHidden)
                        {
                            _output.WriteSingleLine(each);
                        }
                        continue;
                    }
                }

                if (Formatter.StripExternalWikiDef(_externalWikiMap, each))
                    continue;

                // empty line resets everything (except pre and multiline imports )
                if (each.Trim().Length == 0)
                {
                    if (!(CurrentState is PreState) || (CurrentState is PreState && !IsNextLinePre()))
                        Ensure(typeof(NeutralState),0,false,false);
                    _output.WriteEndLine();
                }
                else if ((each.StartsWith("----")) && (false == currentMultilinePropertyIsHidden))
                {
                    Ensure(typeof(NeutralState),0,false,false);
                    _output.WriteRule();
                }
                // insert topic -- {{IncludeSomeTopic}} ?
                else if ((!each.StartsWith(" ") & Regex.IsMatch(each, @"^[\t]*\{\{" + s_wikiName + @"\}\}[\s]*$")) &&
                    (false == currentMultilinePropertyIsHidden))
                {
                    Regex nameGetter = new Regex("(?<topic>" + s_wikiName + ")");
                    string name = nameGetter.Matches(each)[0].Groups["topic"].Value;
                    TopicRevision topicRevision = new TopicRevision(name);

                    // Count the tabs
                    int tabs = 0;
                    string tabber = each;
                    while (tabber.Length > 0 && (tabber.StartsWith("\t")))
                    {
                        tabs++;
                        tabber = tabber.Substring(1);
                    }

                    Ensure(typeof(NeutralState),0,false,false);
                    if (NamespaceManager.TopicExists(topicRevision, ImportPolicy.IncludeImports))
                    {
                        if ((!IsBeyondSafeNestingDepth) && (false == currentMultilinePropertyIsHidden))
                        {
                            _output.Write(IncludedTopic(topicRevision, _headingLevelBase + tabs));
                        }
                    }
                    else
                    {
                        EnsureParaOpen();
                        _output.Write(LinkWikiNames(each));
                        EnsureParaClose();
                    }
                }
                // line begins with a space, it's PRE time!
                else if ((each.StartsWith(" ") || Regex.IsMatch(each, "^[ \t]+[^ \t*1#]")) &&
                    (false == currentMultilinePropertyIsHidden))
                {
                    Ensure(typeof(PreState),0,false,false);
                    _output.Write(Regex.Replace(each, "\t", "        "));
                }

                else
                {
                    // OK, it's likely more complicated

                    // Continue if we're inside a multiline hidden propertyName.
                    if (true == currentMultilinePropertyIsHidden)
                    {
                        continue;
                    }

                    // See if this is a bullet line
                    if (each.StartsWith("\t"))
                    {
                        each = ProcessLineElements(each);
                        // Save the last nesting level
                        // Starts with a tab - might be a list (we'll see)
                        // Count the tabs
                        thisNest = 0;
                        while (each.Length > 0 && (each.StartsWith("\t")))
                        {
                            thisNest++;
                            each = each.Substring(1);
                        }

                        if (each.StartsWith("*"))
                        {
                            each = each.Substring(1);
                            // We're in a list - make sure we've got the right <ul> nesting setup
                            // Could need more or fewer
                            if(CurrentState.GetType().ToString().Equals(typeof(UnorderedListState).ToString()) ||
                               CurrentState.GetType().ToString().Equals(typeof(OrderedListState).ToString()))
                                resetCount = false ;
                            else
                                resetCount = true ;
                            if(resetNextCount)
                            {
                               resetCount = true ;
                               resetNextCount = false ;
                            }
                            Ensure(typeof(UnorderedListState),thisNest,resetCount,false);
                            if ((bool)Federation.Application["RemoveListItemWhitespace"] == false)
                            {
                                _output.WriteListItem(each);
                            }
                            else
                            {
                                _output.WriteListItem(each.Trim());
                            }
                            indiceCount[stateStack.Count-1] = indiceCount[stateStack.Count-1] + 1 ;
                        }
                        else if (each.StartsWith("1."))
                        {
                         	each = each.Substring(2);
                            if(CurrentState.GetType().ToString().Equals(typeof(UnorderedListState).ToString()) ||
                               CurrentState.GetType().ToString().Equals(typeof(OrderedListState).ToString()))
                                resetCount = false ;
                            else
                                resetCount = true ;
                            if(resetNextCount)
                            {
                               resetCount = true ;
                               resetNextCount = false ;
                            }
                         	Ensure(typeof(OrderedListState),thisNest,resetCount,false);                            if ((bool)Federation.Application["RemoveListItemWhitespace"] == false)
                            if ((bool)Federation.Application["RemoveListItemWhitespace"] == false)
                            {
                                _output.WriteListItem(each);
                            }
                            else
                            {
                                _output.WriteListItem(each.Trim());
                            }
                            indiceCount[stateStack.Count-1] = indiceCount[stateStack.Count-1] + 1 ;
                        }
                        else if (each.StartsWith("#^"))
                        {
                            each = each.Substring(2);
                            Ensure(typeof(OrderedListState),thisNest,false,true);
                            if ((bool)Federation.Application["RemoveListItemWhitespace"] == false)
                            {
                                _output.WriteListItem(each);
                            }
                            else
                            {
                                _output.WriteListItem(each.Trim());
                            }
                            indiceCount[stateStack.Count-1] = indiceCount[stateStack.Count-1] + 1 ;
                        }
                        else if (each.StartsWith("#!"))
                        {
                            each = each.Substring(2);
                            if(CurrentState.GetType().ToString().Equals(typeof(UnorderedListState).ToString()) ||
                               CurrentState.GetType().ToString().Equals(typeof(OrderedListState).ToString()))
                                resetCount = false ;
                            else
                                resetCount = true ;
                            Ensure(typeof(OrderedListState),thisNest,resetCount,false);
                            if ((bool)Federation.Application["RemoveListItemWhitespace"] == false)
                            {
                                _output.WriteListItem(each);
                            }
                            else
                            {
                                _output.WriteListItem(each.Trim());
                            }
                            // Reset the list all levels
                            for(int i=0;i<35;i++)
                                indiceCount[i] = 1 ;
                            resetNextCount = true ;
                            Ensure(typeof(OrderedListState),0,false,false);
                        }
                        else if (each.StartsWith("#"))
                        {
                            each = each.Substring(1);
                            if(CurrentState.GetType().ToString().Equals(typeof(UnorderedListState).ToString()) ||
                               CurrentState.GetType().ToString().Equals(typeof(OrderedListState).ToString()))
                                resetCount = false ;
                            else
                                resetCount = true ;
                            if(resetNextCount)
                            {
                               resetCount = true ;
                               resetNextCount = false ;
                            }
                            Ensure(typeof(OrderedListState),thisNest,resetCount,false);
                            if ((bool)Federation.Application["RemoveListItemWhitespace"] == false)
                            {
                                _output.WriteListItem(each);
                            }
                            else
                            {
                                _output.WriteListItem(each.Trim());
                            }
                            indiceCount[stateStack.Count-1] = indiceCount[stateStack.Count-1] + 1 ;
                        }
                        else
                        {
                            // False alarm (just some tabs)
                            _output.Write(Regex.Replace(each, "\t", "        "));
                        }
                    }
                    else if (each.StartsWith("||") && each.EndsWith("||") && each.Length >= 4)
                    {
                        bool firstRow = !(CurrentState is TableState);
                        Ensure(typeof(TableState),0,false,false);
                        TableState ts = (TableState) CurrentState;

                        string endless = each.Substring(2, each.Length - 4);

                        // Write the row
                        bool firstCell = true;
                        foreach (string eachCell in Regex.Split(endless, @"\|\|"))
                        {
                            string cellContent = eachCell;
                            // Check the cell for formatting
                            TableCellInfo info = new TableCellInfo();
                            if (cellContent.StartsWith("{"))
                            {
                                int end = cellContent.IndexOf("}", 1);
                                if (end != -1)
                                {
                                    string fmt = cellContent.Substring(1, end - 1);
                                    cellContent = cellContent.Substring(end + 1);
                                    string result = info.Parse(fmt);
                                    if (result != null)
                                        cellContent = "(Error: " + result + ") " + cellContent;
                                }
                            }
                            if (firstCell)
                            {
                                if (firstRow)
                                {
                                    ts.HasBorder = info.HasBorder;
                                    Output.WriteOpenTable(info.TableAlignment, info.HasBorder, info.TableWidth);
                                }
                                _output.WriteOpenTableRow();
                            }
                            _output.WriteTableCell(ProcessLineElements(cellContent), info.IsHighlighted, info.CellAlignment, info.ColSpan, info.RowSpan, ts.HasBorder, info.AllowBreaks, info.CellWidth, info.BackgroundColor);
                            firstCell = false;
                        }
                        _output.WriteCloseTableRow();
                    }
                    else
                    {
                        Ensure(typeof(NeutralState),0,false,false);

                        // See if we've got a heading prefix
                        int heading = -1;
                        if (each.StartsWith("!!!!!!!"))
                            heading = 7;
                        else if (each.StartsWith("!!!!!!"))
                            heading = 6;
                        else if (each.StartsWith("!!!!!"))
                            heading = 5;
                        else if (each.StartsWith("!!!!"))
                            heading = 4;
                        else if (each.StartsWith("!!!"))
                            heading = 3;
                        else if (each.StartsWith("!!"))
                            heading = 2;
                        else if (each.StartsWith("!"))
                            heading = 1;

                        if (heading != -1)
                        {
                            _output.WriteHeading(each.Substring(heading), ProcessLineElements(each.Substring(heading)), _headingLevelBase + heading);
                        }
                        else
                        {
                            // If it's a single-line propertyName, wrap it visually
                            if (TopicParser.PropertyRegex.IsMatch(each))
                            {
                                Match m = TopicParser.PropertyRegex.Match(each);
                                string name = m.Groups["name"].Value;
                                string val = m.Groups["val"].Value;
                                string leader = m.Groups["leader"].Value;
                                bool isLeader = leader == ":";

                                // Write out an anchor tag.
                                if (isLeader)	// Only bother writing anchor and name for hidden page properties
                                {
                                    _output.WriteOpenAnchor(name);
                                    _output.WriteCloseAnchor();
                                }
                                else
                                {
                                    // Do the normal processing
                                    string linkedName = LinkWikiNames(name);

                                    val = val.Trim();
                                    val = ProcessLineElements(val);

                                    _output.WriteOpenProperty(linkedName);
                                    _output.WriteOpenAnchor(name);
                                    _output.Write(val);
                                    _output.WriteCloseAnchor();
                                    _output.WriteCloseProperty();
                                }
                            }
                            else if (true == each.StartsWith(BehaviorDelimiter))
                            {
                                // Don't wrap behaviors in <p> and </p>.
                                paraOpen = false;
                                each = ProcessLineElements(each);
                                _output.Write(each);
                            }
                            else
                            {
                                // As vanilla as can be -- just send it along
                                each = ProcessLineElements(each);
                                EnsureParaOpen();
                                _output.Write(each);
                            }
                        }
                    }
                }
                EnsureParaClose();
                if (false == currentMultilinePropertyIsHidden)
                {
                    _output.WriteEndLine();
                }
                _currentLineIndex++;
            }
            Ensure(typeof(NeutralState),0,false,false);            _output.End();

            CurrentState = null;	// Make sure to do this so the last state gets Exit()
        }
Exemple #20
0
		abstract public void WriteOpenTable(TableCellInfo.AlignOption alignment, bool hasBorder, int Width);