Example #1
0
		public static void Write(Heading heading, TextWriter w)
		{
			for (int i = 0; i < heading.Depth; i++)
				w.Write("#");
			w.Write(" ");
			w.WriteLine(heading.Title);
			w.WriteLine();
		}
Example #2
0
		public static List<Element> Assemble(List<Block> blocks)
		{
			Block previous		= null;
			Verse previousVerse = null;
			Quote previousQuote = null;

			List<Element> elements = new List<Element>();

			foreach (Block block in blocks) {
				Element element = null;

				if (block.Verse) {
					if (previous != null && previous.Tied && previous.Verse) {
						Debug.Assert(previousVerse != null);
						previousVerse.blocks.Add(block);
					} else {
						previousVerse = new Verse();
						previousVerse.blocks.Add(block);
						element = previousVerse;
					}
				}
				else if (block.Heading.HasValue) {
					Heading head = new Heading();
					Debug.Assert(block.Lines.Count == 1);
					head.Title = block.Lines[0];
					head.Depth = block.Heading.Value;
					element = head;
				}
				else if (block.Footnote.HasValue) {
					Footnote fn = new Footnote();
					fn.Text	 = block;
					fn.Index = block.Footnote.Value;
					element = fn;
				}
				else {
					Paragraph para = new Paragraph();
					para.block = block;
					element = para;
				}

				bool added = false;

				if (block.Quoted && element != null) {
					if (previous != null && previous.Tied && previous.Quoted) {
						Debug.Assert(previousQuote != null);
						previousQuote.elements.Add(element);
						added = true;
					} else {
						previousQuote = new Quote();
						previousQuote.elements.Add(element);
						element = previousQuote;
					}
				}

				if (! added && element != null)
					elements.Add(element);

				previous = block;
			}

			return elements;
		}