Exemplo n.º 1
0
		public static EmphasisInline TryParse(CreoleReader reader)
		{
			if (reader.Peek(2) != "//" || HasLinkPrefix(reader))
				return null;

			int index = 0;
			while (true)
			{
				index = reader.IndexOf("//", index + 2);
				if (index == -1)
					break;

				if (!HasLinkPrefix(reader, index))
					break;
			}
			
			reader.Skip(2);
			string content;
			if (index != -1)
			{
				content = reader.Read(index - 2);
				reader.Skip(2);
			}
			else
			{
				content = reader.ReadToEnd();
			}

			return new EmphasisInline(content);
		}
Exemplo n.º 2
0
		public static LinkInline TryParse(CreoleReader reader)
		{
			if (reader.Peek(2) == "[[")
			{
				var index = reader.IndexOf("]]", 2);
				if (index == -1)
					return null;

				reader.Skip(2);
				var data = reader.Read(index - 2);
				reader.Skip(2);

				index = data.IndexOf("|");
				if (index == -1)
					return new LinkInline(data, data, parseContent: false);

				var url = data.Substring(0, index);
				var content = data.Substring(index + 1, data.Length - index - 1);

				return new LinkInline(url, content);
			}
			else if (reader.IsNewWord && UrlRegex.IsMatch(reader.NextWord))
			{
				var url = reader.ReadWord();

				return new LinkInline(url, url, parseContent: false);
			}

			return null;
		}
Exemplo n.º 3
0
		public static NoWikiInline TryParse(CreoleReader reader)
		{
			if (reader.Peek(3) != "{{{")
				return null;

			var index = reader.IndexOf("}}}", 2);
			if (index == -1)
				return null;

			reader.Skip(3);
			var content = reader.Read(index - 3);
			reader.Skip(3);

			return new NoWikiInline(content);
		}
Exemplo n.º 4
0
		public static LineBreakInline TryParse(CreoleReader reader)
		{
			if (reader.Peek(2) != "\\\\")
				return null;

			reader.Skip(2);
			return new LineBreakInline();
		}
Exemplo n.º 5
0
		public static StrongInline TryParse(CreoleReader reader)
		{
			if (reader.Peek(2) != "**")
				return null;

			var index = reader.IndexOf("**", 2);

			reader.Skip(2);
			string content;
			if (index != -1)
			{
				content = reader.Read(index - 2);
				reader.Skip(2);
			}
			else
			{
				content = reader.ReadToEnd();
			}		

			return new StrongInline(content);
		}
Exemplo n.º 6
0
		public static ImageInline TryParse(CreoleReader reader)
		{
			if (reader.Peek(2) != "{{")
				return null;

			var index = reader.IndexOf("}}", 2);
			if (index == -1)
				return null;

			reader.Skip(2);
			var content = reader.Read(index - 2);
			reader.Skip(2);

			index = content.IndexOf("|");
			if (index == -1)
				return new ImageInline(content, null);

			var url = content.Substring(0, index);
			var alt = content.Substring(index + 1, content.Length - index - 1);

			return new ImageInline(url, alt);
		}
Exemplo n.º 7
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");
			}
		}