public static JoinHtmlString ToHtmlString([CanBeNull] this MarkdownString markdownString, ILinkRenderer renderer = null) => PerformRender(markdownString, renderer, (text, writer, pipeline, context) => Markdig.Markdown.ToHtml(text, writer, pipeline, context), HtmlSanitizers.Simple);
public PlotElementViewModel([CanBeNull] Character?character, int?currentUserId, [NotNull] ILinkRenderer linkRendrer, [NotNull] PlotElementTexts plotElementVersion, IUriService uriService) { if (linkRendrer == null) { throw new ArgumentNullException(nameof(linkRendrer)); } if (plotElementVersion == null) { throw new ArgumentNullException(nameof(plotElementVersion)); } var p = plotElementVersion.PlotElement; Content = plotElementVersion.Content.ToHtmlString(linkRendrer); TodoField = plotElementVersion.TodoField; HasMasterAccess = p.HasMasterAccess(currentUserId); HasEditAccess = p.HasMasterAccess(currentUserId) && p.Project.Active; PlotFolderId = p.PlotFolderId; PlotElementId = p.PlotElementId; ProjectId = p.ProjectId; Status = p.GetStatus(); TargetsForDisplay = p.GetTargets().AsObjectLinks(uriService).ToList(); CharacterId = character?.CharacterId; PublishMode = !HasMasterAccess && !(character?.HasPlayerAccess(currentUserId) ?? false); }
public static IHtmlString ToHtmlString([CanBeNull] this MarkdownString markdownString, ILinkRenderer renderer = null) => PerformRender(markdownString, renderer, Markdig.Markdown.ToHtml, HtmlSanitizers.Simple);
private static JoinHtmlString PerformRender(MarkdownString markdownString, ILinkRenderer linkRenderer, Action <string, TextWriter, MarkdownPipeline, MarkdownParserContext> renderMethod, IHtmlSanitizer sanitizer) { linkRenderer ??= DoNothingLinkRenderer.Instance; if (markdownString?.Contents == null) { return("".MarkAsHtmlString()); } var context = new MarkdownParserContext(); var contents = sanitizer.Sanitize(markdownString.Contents); //TODO - do we need to save re-use pipeline? var pipeline = new MarkdownPipelineBuilder() .UseSoftlineBreakAsHardlineBreak() .UseMediaLinks() .UseAutoLinks() .UseEntityLinker(linkRenderer) .Build(); var writer = new StringWriter(); renderMethod(contents, writer, pipeline, context); var rendered = writer.ToString(); return(sanitizer.Sanitize(rendered).MarkAsHtmlString()); }
public LinkerParser([NotNull] ILinkRenderer linkRenderer) { if (linkRenderer == null) { throw new ArgumentNullException(nameof(linkRenderer)); } LinkRenderer = linkRenderer; }
public static IHtmlString ToPlainText([CanBeNull] this MarkdownString markdownString, ILinkRenderer renderer = null) => PerformRender(markdownString, renderer, Markdig.Markdown.ToPlainText, HtmlSanitizers.RemoveAll);
public EntityLinkerExtension([NotNull] ILinkRenderer linkRenderers) { if (linkRenderers == null) { throw new ArgumentNullException(nameof(linkRenderers)); } LinkRenderers = linkRenderers; }
public static IHtmlString ToHtmlString([CanBeNull] this MarkdownString markdownString, [NotNull] ILinkRenderer renderer) { if (renderer == null) { throw new ArgumentNullException(nameof(renderer)); } return(markdownString?.Contents == null ? new HtmlString("") : markdownString.RenderMarkDownToHtmlUnsafe(renderer).SanitizeHtml()); }
public static MarkdownPipelineBuilder UseEntityLinker(this MarkdownPipelineBuilder pipeline, [NotNull] ILinkRenderer renderer) { if (renderer == null) { throw new ArgumentNullException(nameof(renderer)); } pipeline.Extensions.AddIfNotAlready(new EntityLinkerExtension(renderer)); return(pipeline); }
/// <summary> /// Creates field value view object /// </summary> private FieldValueViewModel CreateFieldValueView(FieldWithValue fv, ILinkRenderer renderer) { FieldValueViewModel result = new FieldValueViewModel(this, fv, renderer); // Here is the point to calculate total fee if (result.HasPrice) { FieldsFee[result.FieldBound] += result.Fee; FieldWithFeeCount[result.FieldBound]++; HasFieldsWithFee = true; } return(result); }
private static UnSafeHtml RenderMarkDownToHtmlUnsafe(this MarkdownString markdownString, [NotNull] ILinkRenderer renderer) { if (renderer == null) { throw new ArgumentNullException(nameof(renderer)); } //TODO - do we need to save re-use pipeline? var pipeline = new MarkdownPipelineBuilder() .UseSoftlineBreakAsHardlineBreak() .UseAutoLinks() .UseEntityLinker(renderer) .Build(); return(Markdig.Markdown.ToHtml(markdownString.Contents, pipeline)); }
public FieldValueViewModel( CustomFieldsViewModel model, [NotNull] FieldWithValue ch, ILinkRenderer renderer) { if (ch == null) { throw new ArgumentNullException(nameof(ch)); } Value = ch.Value; DisplayString = ch.Field.SupportsMarkdown() ? new MarkdownString(ch.DisplayString).ToHtmlString(renderer) : ch.DisplayString.SanitizeHtml(); FieldViewType = (ProjectFieldViewType)ch.Field.FieldType; FieldName = ch.Field.FieldName; Description = ch.Field.Description.ToHtmlString(); IsPlayerVisible = ch.Field.CanPlayerView; IsDeleted = !ch.Field.IsActive; HasValue = ch.HasViewableValue; var hasViewAccess = ch.HasViewableValue && ch.HasViewAccess(model.AccessArguments); CanView = hasViewAccess && (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target)); CanEdit = model.EditAllowed && ch.HasEditAccess(model.AccessArguments, model.Target) && (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target)); //if not "HasValues" types, will be empty ValueList = ch.GetDropdownValues().Select(v => new FieldPossibleValueViewModel(v)).ToArray(); PossibleValueList = ch.GetPossibleValues().Select(v => new FieldPossibleValueViewModel(v)).ToList(); ProjectFieldId = ch.Field.ProjectFieldId; FieldBound = (FieldBoundToViewModel)ch.Field.FieldBoundTo; MandatoryStatus = IsDeleted ? MandatoryStatusViewType.Optional : (MandatoryStatusViewType)ch.Field.MandatoryStatus; ProjectId = ch.Field.ProjectId; }
private static IHtmlString PerformRender(MarkdownString markdownString, ILinkRenderer linkRenderer, Func <string, MarkdownPipeline, string> renderMethod, IHtmlSanitizer sanitizer) { linkRenderer = linkRenderer ?? DoNothingLinkRenderer.Instance; if (markdownString?.Contents == null) { return(new HtmlString("")); } var contents = sanitizer.Sanitize(markdownString.Contents); //TODO - do we need to save re-use pipeline? var pipeline = new MarkdownPipelineBuilder() .UseSoftlineBreakAsHardlineBreak() .UseAutoLinks() .UseEntityLinker(linkRenderer) .Build(); return(new HtmlString(sanitizer.Sanitize(renderMethod(contents, pipeline)))); }
public LinkerParser([NotNull] ILinkRenderer linkRenderer) => LinkRenderer = linkRenderer ?? throw new ArgumentNullException(nameof(linkRenderer));
public PlotElementViewModel([NotNull] PlotElement p, [CanBeNull] Character character, int?currentUserId, ILinkRenderer linkRendrer) { if (p == null) { throw new ArgumentNullException(nameof(p)); } Content = p.Texts.Content.ToHtmlString(linkRendrer); TodoField = p.Texts.TodoField; HasMasterAccess = p.HasMasterAccess(currentUserId); HasEditAccess = p.HasMasterAccess(currentUserId) && p.Project.Active; HasPlayerAccess = character?.HasPlayerAccess(currentUserId) ?? false; PlotFolderId = p.PlotFolderId; PlotElementId = p.PlotElementId; ProjectId = p.ProjectId; Status = p.GetStatus(); TargetsForDisplay = p.GetTargets().AsObjectLinks().ToList(); CharacterId = character?.CharacterId; PublishMode = !HasMasterAccess && !HasPlayerAccess; }
public static string ToPlainText([CanBeNull] this MarkdownString markdownString, [NotNull] ILinkRenderer renderer) { if (renderer == null) { throw new ArgumentNullException(nameof(renderer)); } if (markdownString?.Contents == null) { return(""); } return(markdownString.RenderMarkDownToHtmlUnsafe(renderer).RemoveHtml().Trim()); }
public LinkerRenderAdapter(ILinkRenderer linkRenderer) => LinkRenderer = linkRenderer;
public EntityLinkerExtension([NotNull] ILinkRenderer linkRenderers) => LinkRenderers = linkRenderers ?? throw new ArgumentNullException(nameof(linkRenderers));
/// <summary> /// Ensures that some markdown string will be converted to some HTML /// </summary> public static void ShouldBeHtml(this MarkdownString markdownString, string expectedHtml, ILinkRenderer linkRenderer = null) => markdownString.ToHtmlString(linkRenderer).ToHtmlString().ShouldBe(expectedHtml);
public FieldValueViewModel( CustomFieldsViewModel model, [NotNull] FieldWithValue ch, ILinkRenderer renderer) { if (ch == null) { throw new ArgumentNullException(nameof(ch)); } Value = ch.Value; DisplayString = ch.Field.SupportsMarkdown() ? new MarkdownString(ch.DisplayString).ToHtmlString(renderer) : ch.DisplayString.SanitizeHtml(); FieldViewType = (ProjectFieldViewType)ch.Field.FieldType; FieldName = ch.Field.FieldName; HasMasterAccess = model.AccessArguments.MasterAccess; Description = ch.Field.Description.ToHtmlString(); MasterDescription = HasMasterAccess ? ch.Field.MasterDescription.ToHtmlString() : "".MarkAsHtmlString(); IsPlayerVisible = ch.Field.CanPlayerView; IsDeleted = !ch.Field.IsActive; HasValue = ch.HasViewableValue; CanView = ch.HasViewableValue && ch.HasViewAccess(model.AccessArguments) && (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target)); CanEdit = model.EditAllowed && ch.HasEditAccess(model.AccessArguments) && (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target)); // Detecting if field (or its values) has a price or not HasPrice = ch.SupportsPricing(); //if not "HasValues" types, will be empty ValueList = ch.GetDropdownValues() .Select(v => new FieldPossibleValueViewModel(v, HasPrice, true)).ToList(); PossibleValueList = ch.GetPossibleValues(model.AccessArguments).Select(v => new FieldPossibleValueViewModel(v, HasPrice, ValueList.Any(sv => sv.ProjectFieldDropdownValueId == v.ProjectFieldDropdownValueId))) .ToArray(); if (HasPrice) { if (FieldViewType.SupportsPricingOnField()) { Price = ch.Field.Price; } Fee = ch.GetCurrentFee(); } ShowPrice = HasPrice && model.AccessArguments.AnyAccessToClaim; ProjectFieldId = ch.Field.ProjectFieldId; FieldBound = (FieldBoundToViewModel)ch.Field.FieldBoundTo; MandatoryStatus = IsDeleted ? MandatoryStatusViewType.Optional : (MandatoryStatusViewType)ch.Field.MandatoryStatus; ProjectId = ch.Field.ProjectId; SetFieldLabels(ch); }
void InitRenderer() { linkRenderer = part.FindModulesImplementing <ILinkRenderer>() .FirstOrDefault(r => r.cfgRendererName == rendererName); }
public FieldValueViewModel(CustomFieldsViewModel model, [NotNull] FieldWithValue ch, ILinkRenderer renderer) { if (ch == null) { throw new ArgumentNullException(nameof(ch)); } Value = ch.Value; if (ch.Field.SupportsMarkdown()) { DisplayString = new MarkdownString(ch.DisplayString).ToHtmlString(renderer); } else { DisplayString = ch.DisplayString.SanitizeHtml(); } FieldViewType = (ProjectFieldViewType)ch.Field.FieldType; FieldName = ch.Field.FieldName; Description = ch.Field.Description.ToHtmlString(); IsPlayerVisible = ch.Field.CanPlayerView; IsDeleted = !ch.Field.IsActive; HasValue = ch.HasValue || !ch.Field.CanHaveValue(); var hasViewAccess = ch.Field.IsPublic || model.HasMasterAccess || (model.HasPlayerAccessToCharacter && ch.Field.CanPlayerView && ch.Field.FieldBoundTo == FieldBoundTo.Character) || (model.HasPlayerClaimAccess && ch.Field.CanPlayerView && ch.Field.FieldBoundTo == FieldBoundTo.Claim); CanView = hasViewAccess && (ch.HasValue || (!ch.Field.CanHaveValue() && ch.Field.IsAvailableForTarget(model.Target))); CanEdit = model.EditAllowed && ch.HasEditAccess( model.HasMasterAccess, model.HasPlayerAccessToCharacter, model.HasPlayerClaimAccess, model.Target); if (ch.Field.HasValueList()) { ValueList = ch.GetDropdownValues().ToArray(); PossibleValueList = ch.GetPossibleValues(); } ProjectFieldId = ch.Field.ProjectFieldId; FieldBound = (FieldBoundToViewModel)ch.Field.FieldBoundTo; MandatoryStatus = IsDeleted ? MandatoryStatusViewType.Optional : (MandatoryStatusViewType)ch.Field.MandatoryStatus; }