public static string wikiText_Transform(this string wikiText)
        {
            if (wikiText.notValid())
            {
                return("");
            }
            try
            {
                wikiText = wikiText.wikiCreole_Fix_WikiText_Bullets();
                var html            = "";
                var wikiParseThread = O2Thread.mtaThread(() =>
                {
                    html = new CreoleParser().Parse(wikiText)
                           .wikiCreole_Replaced_Html_Code_Tag_with_Pre();
                });
                if (wikiParseThread.Join(MAX_RENDER_WAIT))
                {
                    if (html.valid())
                    {
                        return(html);
                    }
                }

                "[CreoleWiki_ExtensionMethods][wikiText_Transform] failed for WikiText: \n\n{0}\n\n".error(wikiText);
                wikiParseThread.Abort();
            }
            catch (Exception ex)
            {
                ex.log("[wikiText_transform]");
            }
            return("<b>TEAM Mentor Error:</b><br/><br/> Sorry it was not possible to render this article. Please contact <a href=\"mailto:[email protected]\">Security Innovation Support</a>.");
        }
		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>");
		}
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			if (string.IsNullOrEmpty(content))
				return;

			writer.AppendRaw("<em>");
			writer.AppendRaw(parser.ParseInlines(content));
			writer.AppendRaw("</em>");
		}
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			if (string.IsNullOrWhiteSpace(content))
				return;

			writer.AppendRaw("<p>");
			writer.AppendRaw(parser.ParseInlines(content));
			writer.AppendRawLine("</p>");
		}
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			var resolvedUrl = parser.ResolveLink(url);

			var isExternal = resolvedUrl.StartsWith("http://") || resolvedUrl.StartsWith("https://") || resolvedUrl.StartsWith("ftp://");

			writer.AppendRaw("<a href=\"{0}\"{1}>", HttpUtility.UrlPathEncode(resolvedUrl), isExternal ? " target=\"_blank\"" : string.Empty);
			if (parseContent)
				writer.AppendRaw(parser.ParseInlines(content, TryParse));
			else
				writer.Append(content);
			writer.AppendRaw("</a>");
		}
		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");
			}
		}
        public void containspagelink_should_return_false_when_title_does_not_exist_in_creole()
        {
            // Arrange
            CreoleParser      parser  = new CreoleParser(_applicationSettings, _siteSettings);
            MarkupLinkUpdater updater = new MarkupLinkUpdater(parser);

            string text = "here is a nice [[the internal wiki page title|the link text]]";

            // Act
            bool hasLink = updater.ContainsPageLink(text, "page title");

            // Assert
            Assert.That(hasLink, Is.False);
        }
        public void ContainsPageLink_Should_Return_False_When_Title_Does_Not_Exist_In_Creole()
        {
            // Arrange
            CreoleParser      parser  = new CreoleParser(_applicationSettings, _siteSettings);
            MarkupLinkUpdater updater = new MarkupLinkUpdater(parser);

            string text = "here is a nice [[the internal wiki page title|the link text]]";

            // Act
            bool hasLink = updater.ContainsPageLink(text, "page title");

            // Assert
            Assert.That(hasLink, Is.False);
        }
        public void ReplacePageLinks_Should_Rename_Basic_Creole_Title()
        {
            // Arrange
            CreoleParser      parser  = new CreoleParser(_applicationSettings, _siteSettings);
            MarkupLinkUpdater updater = new MarkupLinkUpdater(parser);

            string text           = "here is a nice [[the internal wiki page title|the link text]]";
            string expectedMarkup = "here is a nice [[buy stuff online|the link text]]";

            // Act
            string actualMarkup = updater.ReplacePageLinks(text, "the internal wiki page title", "buy stuff online");

            // Assert
            Assert.That(actualMarkup, Is.EqualTo(expectedMarkup), actualMarkup);
        }
        public void ReplacePageLinks_Should_Not_Rename_Title_That_Is_Not_Found_In_Creole()
        {
            // Arrange
            CreoleParser      parser  = new CreoleParser(_applicationSettings, _siteSettings);
            MarkupLinkUpdater updater = new MarkupLinkUpdater(parser);

            string text = @"here is a nice [[the internal wiki page title|the link text]] and 
                            another one: here is a nice [[the internal wiki page title|the link text]] and 
							a different one: here is a nice [[different title|the link text]]"                            ;

            // Act
            string actualMarkup = updater.ReplacePageLinks(text, "page title", "buy stuff online");

            // Assert
            Assert.That(actualMarkup, Is.EqualTo(text), actualMarkup);
        }
        private void wikiHandleResponse(IAsyncResult result)
        {
            queryUpdateState qState   = (queryUpdateState)result.AsyncState;
            HttpWebRequest   qRequest = (HttpWebRequest)qState.AsyncRequest;

            qState.AsyncResponse = (HttpWebResponse)qRequest.EndGetResponse(result);

            Stream streamResult;

            try
            {
                streamResult = qState.AsyncResponse.GetResponseStream();

                // load the XML
                XDocument xmlquery = XDocument.Load(streamResult);

                //Wikipedia Data Need to be parsed
                string a = xmlquery.Descendants("query").Descendants("pages").Descendants("page").Descendants("revisions").Descendants("rev").First().Value;
                string h = new CreoleParser().ToHTML(a);

                //this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.UpdateLayout()));
                this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.NavigateToString(h)));
                this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.UpdateLayout()));

                //string x = xmlquery.ToString();

                /* if (x.IndexOf("<Description xml:space=\"preserve\">") != -1)
                 * {
                 *   x = x.Substring(x.IndexOf("<Description xml:space=\"preserve\">") + 34);
                 *   x = x.Substring(0, x.IndexOf("</Description>"));
                 *
                 *   this.Dispatcher.BeginInvoke(new Action(() => textBlock1.Text = x));
                 * }
                 * else
                 * {
                 *   this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("Oy")));
                 * }
                 * this.Dispatcher.BeginInvoke(new Action(() => this.ProgressBar.Visibility = Visibility.Collapsed));*/
            }
            catch (FormatException)
            {
                return;
            }
        }
Beispiel #12
0
        public ActionResult Add(string text)
        {
            // text
            if (text.Trim().Length == 0)
            {
                return(Redirect("/Comment/"));
            }
            Comment      comment = new Comment();
            CreoleParser parser  = new CreoleParser();

            comment.Text = parser.ToHTML(HttpUtility.HtmlEncode(text.Replace(Environment.NewLine, "\\\\")));
            comment.User = CurrentUser();

            // upload

            foreach (string inputTagName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[inputTagName];
                if (file.ContentLength == 0)
                {
                    continue;
                }
                Image image = new Image();
                image.PathRootBased = "Users";
                daoTemplate.Save(image);
                string filePath      = HttpContext.Server.MapPath(image.PathRootBasedBig);
                string thumbFilePath = HttpContext.Server.MapPath(image.PathRootBasedSmall);
                if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                }
                file.SaveAs(filePath);
                ImageUtils.SaveImageToFile(ImageUtils.ResizeImage(filePath, 640), filePath);
                ImageUtils.SaveImageToFile(ImageUtils.ResizeImageSquare(filePath, 100), thumbFilePath);


                comment.Image = image;
                daoTemplate.Save(image);
            }
            daoTemplate.Save(comment);
            return(Redirect("/Comment/"));
        }
        public void ReplacePageLinks_Should_Rename_Title_Inside_Creole_Markup_Block()
        {
            // Arrange
            CreoleParser      parser  = new CreoleParser(_applicationSettings, _siteSettings);
            MarkupLinkUpdater updater = new MarkupLinkUpdater(parser);

            string text = @"//here is a nice **[[the internal wiki page title|the link text]]** and// 
                            another one: *here is a nice [[the internal wiki page title|the link text]] and 
							*a different one: here is a nice [[different title|the link text]]"                            ;

            string expectedMarkup = @"//here is a nice **[[buy stuff online|the link text]]** and// 
                            another one: *here is a nice [[buy stuff online|the link text]] and 
							*a different one: here is a nice [[different title|the link text]]"                            ;

            // Act
            string actualMarkup = updater.ReplacePageLinks(text, "the internal wiki page title", "buy stuff online");

            // Assert
            Assert.That(actualMarkup, Is.EqualTo(expectedMarkup), actualMarkup);
        }
        public void replacepagelinks_should_rename_multiple_creole_titles()
        {
            // Arrange
            CreoleParser      parser  = new CreoleParser(_applicationSettings, _siteSettings);
            MarkupLinkUpdater updater = new MarkupLinkUpdater(parser);

            string text = @"here is a nice [[the internal wiki page title|the link text]] and 
                            another one: here is a nice [[the internal wiki page title|the link text]] and 
							a different one: here is a nice [[different title|the link text]]"                            ;

            string expectedMarkup = @"here is a nice [[buy stuff online|the link text]] and 
                            another one: here is a nice [[buy stuff online|the link text]] and 
							a different one: here is a nice [[different title|the link text]]"                            ;

            // Act
            string actualMarkup = updater.ReplacePageLinks(text, "the internal wiki page title", "buy stuff online");

            // Assert
            Assert.That(actualMarkup, Is.EqualTo(expectedMarkup), actualMarkup);
        }
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			writer.Append(content);
		}
		public abstract void Render(CreoleParser parser, CreoleWriter writer);
 public void Setup()
 {
     _applicationSettings = new ApplicationSettings();
     _siteSettings        = new SiteSettings();
     _parser = new CreoleParser(_applicationSettings, _siteSettings);
 }
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			writer.AppendRaw("<h{0}>", level);
			writer.Append(content);
			writer.AppendRaw("</h{0}>", level);
		}
Beispiel #19
0
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			RenderList(parser, writer, new CreoleReader(markup), 1);
		}
		public override void Render(CreoleParser parser, CreoleWriter writer)
		{
			var resolvedUrl = parser.ResolveImage(url);

			writer.AppendRaw(@"<img src=""{0}"" alt=""{1}"" />", HttpUtility.UrlPathEncode(resolvedUrl), HttpUtility.HtmlEncode(alt));
		}
		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 />");
		}