Ejemplo n.º 1
0
        public string BeforeParse(string text, PageHtml pageHtml)
        {
            bool isCacheable = true;

            foreach (TextPlugin plugin in _plugins)
            {
                try
                {
                    string previousText = text;
                    text = plugin.BeforeParse(text);

                    if (previousText != text)
                    {
                        // Determine if the plugin thinks the page is still cacheable (provided the plugin has changed the HTML).
                        // Cacheable is true by default, so make sure if one plugin marks it as false the false value is kept.
                        // TODO: if there are performance issues here, the plugin should report if it ran a transformation or not.
                        if (isCacheable == true)
                        {
                            isCacheable = plugin.IsCacheable;
                        }
                    }

                    pageHtml.HeadHtml += plugin.GetHeadContent();
                    pageHtml.FooterHtml += plugin.GetFooterContent();
                }
                catch (Exception e)
                {
                    Log.Error(e, "An exception occurred with the plugin {0} when calling BeforeParse()", plugin.Id);
                }
            }

            IsCacheable = isCacheable;
            return text;
        }
        public string BeforeParse(string text, PageHtml pageHtml)
        {
            bool isCacheable = true;

            foreach (TextPlugin plugin in _plugins)
            {
                try
                {
                    string previousText = text;
                    text = plugin.BeforeParse(text);

                    if (previousText != text)
                    {
                        // Determine if the plugin thinks the page is still cacheable (provided the plugin has changed the HTML).
                        // Cacheable is true by default, so make sure if one plugin marks it as false the false value is kept.
                        // TODO: if there are performance issues here, the plugin should report if it ran a transformation or not.
                        if (isCacheable == true)
                        {
                            isCacheable = plugin.IsCacheable;
                        }
                    }

                    pageHtml.HeadHtml   += plugin.GetHeadContent();
                    pageHtml.FooterHtml += plugin.GetFooterContent();
                }
                catch (Exception e)
                {
                    Log.Error(e, "An exception occurred with the plugin {0} when calling BeforeParse()", plugin.Id);
                }
            }

            IsCacheable = isCacheable;
            return(text);
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Turns the wiki markup provided into HTML.
		/// </summary>
		/// <param name="text">A wiki markup string, e.g. creole markup.</param>
		/// <returns>The wiki markup converted to HTML.</returns>
		public PageHtml ToHtml(string text)
		{
			CustomTokenParser tokenParser = new CustomTokenParser(_applicationSettings);
			PageHtml pageHtml = new PageHtml();
			TextPluginRunner runner = new TextPluginRunner(_pluginFactory);

			// Text plugins before parse
			text = runner.BeforeParse(text, pageHtml);			

			// Parse the markup into HTML
			string html = _parser.Transform(text);
			
			// Remove bad HTML tags
			html = RemoveHarmfulTags(html);

			// Customvariables.xml file
			html = tokenParser.ReplaceTokensAfterParse(html);

			// Text plugins after parse
			html = runner.AfterParse(html);

			// Text plugins pre and post #container HTML
			pageHtml.PreContainerHtml = runner.PreContainerHtml();
			pageHtml.PostContainerHtml = runner.PostContainerHtml();
			
			pageHtml.IsCacheable = runner.IsCacheable;
			pageHtml.Html = html;

			return pageHtml;
		}