예제 #1
0
 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);
예제 #2
0
        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);
        }
예제 #3
0
 public static IHtmlString ToHtmlString([CanBeNull]
                                        this MarkdownString markdownString,
                                        ILinkRenderer renderer = null)
 => PerformRender(markdownString,
                  renderer,
                  Markdig.Markdown.ToHtml,
                  HtmlSanitizers.Simple);
예제 #4
0
        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());
        }
예제 #5
0
 public LinkerParser([NotNull] ILinkRenderer linkRenderer)
 {
     if (linkRenderer == null)
     {
         throw new ArgumentNullException(nameof(linkRenderer));
     }
     LinkRenderer = linkRenderer;
 }
예제 #6
0
 public static IHtmlString ToPlainText([CanBeNull]
                                       this MarkdownString markdownString,
                                       ILinkRenderer renderer = null)
 =>
 PerformRender(markdownString,
               renderer,
               Markdig.Markdown.ToPlainText,
               HtmlSanitizers.RemoveAll);
예제 #7
0
 public EntityLinkerExtension([NotNull] ILinkRenderer linkRenderers)
 {
     if (linkRenderers == null)
     {
         throw new ArgumentNullException(nameof(linkRenderers));
     }
     LinkRenderers = linkRenderers;
 }
예제 #8
0
 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);
 }
예제 #10
0
        /// <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);
        }
예제 #11
0
        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));
        }
예제 #12
0
        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;
        }
예제 #13
0
        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))));
        }
예제 #14
0
 public LinkerParser([NotNull] ILinkRenderer linkRenderer) => LinkRenderer = linkRenderer ?? throw new ArgumentNullException(nameof(linkRenderer));
예제 #15
0
        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;
        }
예제 #16
0
 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());
 }
예제 #17
0
 public LinkerRenderAdapter(ILinkRenderer linkRenderer) => LinkRenderer = linkRenderer;
 public EntityLinkerExtension([NotNull] ILinkRenderer linkRenderers) => LinkRenderers = linkRenderers ?? throw new ArgumentNullException(nameof(linkRenderers));
예제 #19
0
 /// <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);
        }
예제 #21
0
 void InitRenderer()
 {
     linkRenderer = part.FindModulesImplementing <ILinkRenderer>()
                    .FirstOrDefault(r => r.cfgRendererName == rendererName);
 }
예제 #22
0
        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;
        }