public ErrorViewModel(ErrorContext errorContext, IDictionary<string, object> routeValues, WikiDownConfig config) { if (config == null) { throw new ArgumentNullException("config"); } this.ClientMessage = (errorContext != null) ? errorContext.ClientData : null; var exception = (errorContext != null) ? errorContext.Exception : null; if (exception != null) { this.ExceptionContent = exception.ToString(); this.ExceptionMessage = exception.Message; this.ExceptionTypeName = exception.GetType().Name; } if (routeValues != null) { this.ActionName = routeValues.TryGet("action") as string; this.ControllerName = routeValues.TryGet("controller") as string; } this.config = config; }
public static IDocumentStore FromInferred(WikiDownConfig config) { if (config == null) { throw new ArgumentNullException("config"); } string connectionString = config.RavenDbConnectionString; if (!string.IsNullOrWhiteSpace(connectionString)) { return FromConnectionString(connectionString); } string connectionStringName = config.RavenDbConnectionStringName; if (!string.IsNullOrWhiteSpace(connectionStringName)) { return FromConnectionStringName(connectionStringName); } string appSettingName = config.RavenDbAppSettingName; if (!string.IsNullOrWhiteSpace(appSettingName)) { return FromAppSettingName(appSettingName); } throw new RavenDbException("Could not infer RavenDB-connection."); }
public DevelopmentController(WikiDownConfig config) { if (config == null) { throw new ArgumentNullException("config"); } this.config = config; }
public static ArticleAccess Default(WikiDownConfig config) { var configArticleAccess = GetConfigArticleAccess(config); return new ArticleAccess { CanAdmin = configArticleAccess.CanAdmin, CanEdit = configArticleAccess.CanEdit, CanRead = configArticleAccess.CanRead }; }
public WikiArticleViewModel( ControllerContext controllerContext, ArticleSlug articleSlug, ArticleRevisionDate articleRevisionDate, bool shouldRedirect, bool handleIndexSlug, WikiDownConfig config) : base(controllerContext, articleSlug, RouteNames.WikiArticle, articleRevisionDate, HeaderTab.Article, shouldRedirect) { if (config == null) { throw new ArgumentNullException("config"); } this.handleIndexSlug = handleIndexSlug; if (this.ArticlePage.HasRedirect && !this.ShouldRedirect) { return; } this.articleTags = (this.ArticlePage.HasArticle && this.ArticlePage.ArticleTags != null) ? this.ArticlePage.ArticleTags.ToList() : this.ArticleTags; if (!this.HasArticle) { return; } if (string.IsNullOrWhiteSpace(this.ArticlePage.ArticleRevisionMarkdownContent)) { return; } string articleHtml = GetCachedArticleHtml( this.ArticlePage.ArticleRevisionId, this.ArticlePage.ArticleRevisionMarkdownContent, config); this.htmlContent = !string.IsNullOrWhiteSpace(articleHtml) ? new WikiDownArticleHtmlString(articleHtml, this.CurrentRepository) : null; }
public AssetsWikiDownJsViewModel(ConverterHooksConfig converterHooksConfig, WikiDownConfig config) { if (converterHooksConfig == null) { throw new ArgumentNullException("converterHooksConfig"); } if (config == null) { throw new ArgumentNullException("config"); } this.config = config; PreConversionHookRules = GetConversionHookRules(converterHooksConfig.PreConversionHooks); PostConversionHookRules = GetConversionHookRules(converterHooksConfig.PostConversionHooks); }
private static string GetHookRegexReplace(WikiDownConfig config) { if (config == null) { throw new ArgumentNullException("config"); } string regexReplaceWikiPrefix = (!string.IsNullOrWhiteSpace(config.WikiPrefix) ? (config.WikiPrefix + "/") : null); return string.Format( "<div class=\"{0}\"><strong>{1}</strong>: <a href=\"/{2}$2/$3\">$1</a></div>", CssClass, ContentText, regexReplaceWikiPrefix); }
public WikiDownArticleHtmlString(string html, Repository repository, WikiDownConfig config) { if (repository == null) { throw new ArgumentNullException("repository"); } this.html = html; this.articleExistsHelper = new ArticleExistsHelper(repository); this.config = config; this.wikiLinkPrefixRemoveRegex = new Regex( string.Format(@"^[\/]?{0}\/", this.config.WikiPrefix), RegexOptions.Multiline); this.wikiSlashUrlPrefix = string.Format("/{0}/", this.config.WikiPrefix); this.wikiUrlPrefix = string.Format("{0}/", this.config.WikiPrefix); }
public static IEnumerable<IConverterHook> GetDefaultConverterHooks(WikiDownConfig config) { if (config == null) { throw new ArgumentNullException("config"); } var preConverterHookPlaceholders = GetPreConverterHookPlaceholders(); foreach (var preConverterHookPlaceholder in preConverterHookPlaceholders) { yield return preConverterHookPlaceholder; } var preConverterHooks = GetPreConverterHooks(config); foreach (var preConverterHook in preConverterHooks) { yield return preConverterHook; } //var fencedCodeBlocks = new RegexReplaceConverterHook( // ConverterHookType.PostConversion, // @"(^|\n)<[^>]+>```(?:<\/[^>]+>)?\n*([\w\W]*?)\n*(?:<[^>]+>)?```<\/[^>]+>(\n|$)", // "$1<pre><code>$2</code></pre>$3"); //yield return fencedCodeBlocks; var postConverterHookPlaceholders = GetPostConverterHookPlaceholders(); foreach (var postConverterHookPlaceholder in postConverterHookPlaceholders) { yield return postConverterHookPlaceholder; } var postConverterHooks = GetPostConverterHooks(); foreach (var postConverterHook in postConverterHooks) { yield return postConverterHook; } }
private static ArticleAccess GetConfigArticleAccess(WikiDownConfig config) { if (config == null) { throw new ArgumentNullException("config"); } var defaultCanAdminAccessLevel = config.DefaultCanAdminAccessLevel; var defaultCanEditAccessLevel = config.DefaultCanEditAccessLevel; var defaultCanReadAccessLevel = config.DefaultCanReadAccessLevel; return new ArticleAccess { CanAdmin = defaultCanAdminAccessLevel, CanEdit = defaultCanEditAccessLevel, CanRead = defaultCanReadAccessLevel }; }
private void UpdateLinks(WikiDownConfig config) { var html = !string.IsNullOrWhiteSpace(this.MarkdownContent) ? MarkdownService.MakeHtml(this.MarkdownContent) : null; var links = HtmlAgilityPackHelper.GetDocumentLinks(html).ToList(); string wikiPrefix = config.WikiPrefix; string prefixedWikiPrefix = "/" + wikiPrefix; var wikiLinks = links.Where(x => x.StartsWith(wikiPrefix, StringComparison.InvariantCultureIgnoreCase)) .Select(x => x.Substring(wikiPrefix.Length)); var prefixedWikiLinks = links.Where(x => x.StartsWith(prefixedWikiPrefix, StringComparison.InvariantCultureIgnoreCase)) .Select(x => x.Substring(prefixedWikiPrefix.Length)); var wikiArticleSlugs = wikiLinks.Concat(prefixedWikiLinks) .Select(x => x.Trim('/')) .Select(x => !string.IsNullOrWhiteSpace(x) ? x : WikiDownConfig.WikiIndexArticleSlug) .Select(x => new ArticleSlug(x)) .Where(x => x.HasValue) .OrderBy(x => x.Slug) .ThenBy(x => x.Hash) .Select(x => x.SlugAndHash) .Distinct() .ToList(); //var externalLinks = links.Except(wikiLinks).Where(x => ExternalLinkRegex.IsMatch(x)).ToList(); this.OutboundArticleSlugs = wikiArticleSlugs; }
internal void UpdateInternal(WikiDownConfig config) { UpdateTextContentInternal(); UpdateLinks(config); }
private static string GetCachedArticleHtml( string articleRevisionId, string markdownContent, WikiDownConfig config) { if (config.IsDebugMode) { return GetArticleHtml(markdownContent); } string cacheKey = string.Format( "WikiDown.Website.ViewModels.WikiArticleViewModel_ArticleHtml_{0}", articleRevisionId); string articleHtml = MemoryCache.Default.Get(cacheKey) as string; if (articleHtml == null && !MemoryCache.Default.Contains(cacheKey)) { articleHtml = GetArticleHtml(markdownContent); MemoryCache.Default.Set(cacheKey, articleHtml, DateTimeOffset.Now.AddMinutes(15)); } return articleHtml; }
private static IEnumerable<IConverterHook> GetPreConverterHooks(WikiDownConfig config) { var wikiLinksImplicit = new RegexReplaceConverterHook( ConverterHookType.PreConversion, @"\[\[[ ]*([^\n\]\|\#]+?)[ ]*\]\]", string.Format("[[$1|{0}]]", ArticleSlugPlaceholderConverterHook.EncodeArticleSlug("$1")), multiline: false); yield return wikiLinksImplicit; var wikiLinks = new RegexReplaceConverterHook( ConverterHookType.PreConversion, @"\[\[[ ]*([^\n\]\|]+?)[ ]*\|[ ]*([^\n\]\#]+?)[ ]*(#[^\n\]]+?)?[ ]*\]\]", string.Format("<a href=\"/{0}/$2/$3\">$1</a>", config.WikiPrefix), multiline: false); yield return wikiLinks; var wikiHashLinks = new RegexReplaceConverterHook( ConverterHookType.PreConversion, @"\[\[[ ]*([^\n\]\|]+?)[ ]*\|[ ]*#([^\n\]]+?)[ ]*\]\]", "<a href=\"#$2\">$1</a>", multiline: false); yield return wikiHashLinks; string mainArticleImplicitTagContent = string.Format( "{0}|$1|{1}$2", WikiDownTags.MainArticle, ArticleSlugPlaceholderConverterHook.EncodeArticleSlug("$1")); var mainArticleImplicit = new RegexReplaceConverterHook( ConverterHookType.PreConversion, WikiDownMarkdownHelper.FormatTagRegex( @"[ ]*" + WikiDownTags.MainArticle + @"[ ]*\|[ ]*([^#\|\n]+?)(#[^\]\n\}]+?)?[ ]*"), WikiDownMarkdownHelper.FormatTag(mainArticleImplicitTagContent), multiline: false); yield return mainArticleImplicit; yield return new MainArticleConverterHook(config); var noRefTitle = new RegexReplaceConverterHook( ConverterHookType.PreConversion, WikiDownMarkdownHelper.FormatTagRegex( @"[ ]*" + WikiDownTags.ReferenceNeeded + @"[ ]*\|[ ]*([^\]]+?)[ ]*"), string.Format("<sup title=\"$1\">{0}</sup>", ReferenceNeededContent), multiline: false); yield return noRefTitle; var noRef = new RegexReplaceConverterHook( ConverterHookType.PreConversion, WikiDownMarkdownHelper.FormatTagRegex(WikiDownTags.ReferenceNeeded), string.Format("<sup>{0}</sup>", ReferenceNeededContent), multiline: false); yield return noRef; yield return new ArticleSlugPlaceholderConverterHook(); //var underscoredWords = new RegexReplaceConverterHook( // ConverterHookType.PreConversion, // @"(([A-Za-z0-9_!]+_)+([A-Za-z0-9_!]*))(?![^<]*>|[^<>]*</)", // regexPatternReplaces: new Dictionary<string, string> { { "_", @"\_" } }); //yield return underscoredWords; }
public MainArticleConverterHook(WikiDownConfig config) : base(ConverterHookType.PreConversion, HookRegexPattern, GetHookRegexReplace(config), multiline: false) { }