예제 #1
0
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			if (string.IsNullOrWhiteSpace(content))
				return;

			writer.AppendRaw("<p>");
			writer.AppendRaw(parser.ParseInlines(content));
			writer.AppendRawLine("</p>");
		}
예제 #2
0
		private void RenderList(CreoleParser parser, CreoleWriter writer, CreoleReader reader, int level)
		{
			var indent = "";
			for (int i = 1; i < level * 2 - 1; i++)
				indent += "    ";

			while (!reader.EndOfMarkup)
			{
				var type = reader.Peek(level);
				if (type.Any(c => c != type[0]))
					break;
				type = type[0].ToString();

				if (type == "*") writer.AppendRawLine("{0}<ul>", indent);
				else if (type == "#") writer.AppendRawLine("{0}<ol>", indent);
				else throw new InvalidOperationException("Invalid list type");

				while (!reader.EndOfMarkup)
				{
					var nextType = reader.Peek(level);
					if (nextType.Any(c => c != type[0]))
						break;

					reader.Skip(level);
					var line = reader.ReadLine();
					var indentEndLi = false;

					writer.AppendRaw("{0}    <li>", indent);
					writer.AppendRaw(parser.ParseInlines(line).Trim());
					if (!reader.EndOfMarkup)
					{
						var next = reader.Peek(level + 1);
						if (next.Length == level + 1 && (!next.Any(c => c != '*') || !next.Any(c => c != '#')))
						{
							writer.AppendRawLine("");
							RenderList(parser, writer, reader, level + 1);
							indentEndLi = true;
						}
					}
					if (indentEndLi)
						writer.AppendRawLine("{0}    </li>", indent);
					else
						writer.AppendRawLine("</li>");
				}

				if (type == "*") writer.AppendRawLine("{0}</ul>", indent);
				else if (type == "#") writer.AppendRawLine("{0}</ol>", indent);
				else throw new InvalidOperationException("Invalid list type");
			}
		}
예제 #3
0
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			writer.AppendRaw("<pre>");
			writer.Append(content);
			writer.AppendRawLine("</pre>");
		}
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			writer.AppendRawLine("<hr />");
		}
예제 #5
0
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			writer.AppendRawLine("<table>");
			if (headers != null)
			{
				writer.AppendRawLine("    <thead>");
				writer.AppendRawLine("        <tr>");
				foreach (var header in headers)
					writer.AppendRawLine("            <th>{0}</th>", parser.ParseInlines(header.Trim()));
				writer.AppendRawLine("        </tr>");
				writer.AppendRawLine("    <thead>");
			}
			foreach (var row in rows)
			{
				writer.AppendRawLine("    <tr>");
				for (var i = 0; i < row.Length; i++)
				{
					var cell = row[i];

					if (i == 0 && cell.StartsWith("="))
						writer.AppendRawLine("        <td>{0}</td>", parser.ParseInlines(cell.Substring(1).Trim()));
					else
						writer.AppendRawLine("        <td>{0}</td>", parser.ParseInlines(cell.Trim()));
				}
				writer.AppendRawLine("    </tr>");
			}
			writer.AppendRawLine("</table>");
		}