예제 #1
0
        /// <summary>
        /// Gets info about changed fields and other attributes for particular user (if available).
        /// </summary>
        private string GetChangedFieldsInfoForUser(
            [NotNull] EmailModelBase model,
            [NotNull] User user)
        {
            IEmailWithUpdatedFieldsInfo mailWithFields = model as IEmailWithUpdatedFieldsInfo;

            if (mailWithFields == null)
            {
                return("");
            }
            //Add project fields that user has right to view
            Predicate <FieldWithValue> accessRightsPredicate =
                CustomFieldsExtensions.GetShowForUserPredicate(mailWithFields.FieldsContainer, user.UserId);
            IEnumerable <MarkdownString> fieldString = mailWithFields
                                                       .UpdatedFields
                                                       .Where(f => accessRightsPredicate(f))
                                                       .Select(updatedField =>
                                                               new MarkdownString(
                                                                   $@"__**{updatedField.Field.FieldName}:**__
{MarkDownHelper.HighlightDiffPlaceholder(updatedField.DisplayString, updatedField.PreviousDisplayString).Contents}"));

            //Add info about other changed atttributes (no access rights validation)
            IEnumerable <MarkdownString> otherAttributesStrings = mailWithFields
                                                                  .OtherChangedAttributes
                                                                  .Select(changedAttribute => new MarkdownString(
                                                                              $@"__**{changedAttribute.Key}:**__
{MarkDownHelper.HighlightDiffPlaceholder(changedAttribute.Value.DisplayString, changedAttribute.Value.PreviousDisplayString).Contents}"));

            return(string.Join(
                       "\n\n",
                       otherAttributesStrings
                       .Union(fieldString)
                       .Select(x => x.ToHtmlString())));
        }
예제 #2
0
        public ActionResult ViewDoc(string path)
        {
            var mark = new Markdown();
            var file = System.IO.File.ReadAllText(path);
            //var html = CommonMark.CommonMarkConverter.Convert(file);
            var html = MarkDownHelper.Convert(file, "markdown", "html5");

            IHtmlString str = new HtmlString(html);

            return(Content(str.ToString()));
        }
예제 #3
0
        public ViewResult Details(int id, int bookId)
        {
            var book     = Repository.Get <Book>(bookId);
            var bookPost = book.Posts.First(post => post.Id == id);

            ViewBag.transformedContent = new Markdown().Transform(bookPost.Content);
            var bookPostInformation = new BookPostInformation(bookId, bookPost, book);

            ViewBag.MetaDescription = MarkDownHelper.SummaryForMetaDescription(bookPost.Content, 155);
            return(View(bookPostInformation));
        }
예제 #4
0
 public Message(string title, string content, Contact sender, Contact recipient)
 {
     if (string.IsNullOrEmpty(title))
     {
         throw new CustomMessageException("title can't be null");
     }
     if (title.Length > 50)
     {
         throw new CustomMessageException("主题长度不能超过50");
     }
     if (string.IsNullOrEmpty(content))
     {
         throw new CustomMessageException("content can't be null");
     }
     if (content.Length > 20000)
     {
         throw new CustomMessageException("内容过长");
     }
     if (sender == null)
     {
         throw new CustomMessageException("sender can't be null");
     }
     if (recipient == null)
     {
         throw new CustomMessageException("recipient can't be null");
     }
     if (sender.ID == recipient.ID)
     {
         throw new CustomMessageException("发件人和收件人不能为同一人");
     }
     this.Title           = title;
     this.Content         = MarkDownHelper.MarkDownTransform(content);
     this.OriginalContent = content.Replace("\n", "<br />");
     this.SendTime        = DateTime.Now;
     this.IP    = Util.GetUserIpAddress();
     this.State = MessageState.Unread;
     if (sender.ID == 0 || sender.ID == 35695)
     {
         this.Type = MessageType.Notice;
     }
     else
     {
         this.Type = MessageType.Personal;
     }
     this.DisplayType = MessageDisplayType.OutboxAndInbox;
     this.Sender      = sender;
     this.Recipient   = recipient;
 }
예제 #5
0
        public FileResult DownloadPdf(string path)
        {
            var mark = new Markdown();

            var file    = System.IO.File.ReadAllText(path);
            var content = MarkDownHelper.Convert(file, "markdown", "html5");

            byte[] res = null;
            using (var stream = new MemoryStream())
            {
                var writer   = new PdfWriter(stream);
                var pdf      = new PdfDocument(writer);
                var document = new iText.Layout.Document(pdf);

                document.Add(new Paragraph(content));

                HtmlConverter.ConvertToPdf(content, writer);

                res = stream.ToArray();
            }

            return(File(res, MediaTypeNames.Application.Pdf, Path.GetFileNameWithoutExtension(path) + ".pdf"));
        }
예제 #6
0
        public void ShouldRemoveEndingCharReturnValueInMetaDescriptionSummary()
        {
            const string content = "Michael Knight's\n> car is amazing.";

            Assert.AreEqual("Michael Knight's car is amazing.", MarkDownHelper.SummaryForMetaDescription(content, 32));
        }
예제 #7
0
        public void ShouldSummarizeDescription()
        {
            const string content = "__The quick brown fox__ jumps over the lazy dog.";

            Assert.AreEqual("<p><strong>The quick brown fox</strong> jumps</p>\n", MarkDownHelper.Summary(content, 24));
        }
예제 #8
0
        public void ShouldRemoveUnderscoresInMetaDescriptionSummary()
        {
            const string content = "__Michael Knight's__ car is amazing.";

            Assert.AreEqual("Michael Knight's car is amazing.", MarkDownHelper.SummaryForMetaDescription(content, 32));
        }
예제 #9
0
        public void ShouldRemoveAsterisksInMetaDescriptionSummary()
        {
            const string content = "*Michael Knight's car is amazing.*";

            Assert.AreEqual("Michael Knight's car is amazing.", MarkDownHelper.SummaryForMetaDescription(content, 32));
        }
예제 #10
0
        public void ShouldNotRemoveTheEndingHtmlTag()
        {
            const string content = "The quick brown fox jumps over<br/> the lazy dog.";

            Assert.AreEqual("<p>The quick brown fox jumps over<br/></p>\n", MarkDownHelper.Summary(content, 30));
        }
예제 #11
0
        public void ShouldRemoveTheEndingReturnCharAndBracket()
        {
            const string content = "The quick brown fox jumps over\n> the lazy dog.";

            Assert.AreEqual("<p>The quick brown fox jumps over</p>\n", MarkDownHelper.Summary(content, 30));
        }
예제 #12
0
        public void ShouldIgnoreImagesWithTitleInTheDescriptionWhileSummarize()
        {
            const string content = "__The ![image title][1]quick brown fox__ jumps over the lazy dog.";

            Assert.AreEqual("<p><strong>The quick brown fox</strong> jumps</p>\n", MarkDownHelper.Summary(content, 24));
        }
예제 #13
0
        public void ShouldReturnDescriptionIfItSmallerThanTheSummarySize()
        {
            const string content = "The quick brown fox jumps over the lazy dog.";

            Assert.AreEqual("<p>The quick brown fox jumps over the lazy dog.</p>\n", MarkDownHelper.Summary(content, 200));
        }
예제 #14
0
        public void ShouldTransformMarkdownString()
        {
            const string content = "__The quick brown fox__ jumps over the lazy dog.";

            Assert.AreEqual("<p><strong>The quick brown fox</strong> jumps over the lazy dog.</p>\n", MarkDownHelper.Transform(content));
        }
예제 #15
0
 public string Summary(int characters)
 {
     return(MarkDownHelper.Summary(Model.Content, characters));
 }
예제 #16
0
        public void ShouldTruncateTheExtraWordsInMetaDescriptionSummary()
        {
            const string content = "Michael Knight's\n> car is amazing.";

            Assert.AreEqual("Michael Knight's", MarkDownHelper.SummaryForMetaDescription(content, 10));
        }
예제 #17
0
        public void ShouldIgnoreImagesInMetaDescriptionSummary()
        {
            const string content = "![enter image description here][2]Michael Knight's\n> car is amazing.";

            Assert.AreEqual("Michael Knight's", MarkDownHelper.SummaryForMetaDescription(content, 10));
        }
예제 #18
0
        public void ShouldItalicIfTheClosingAsteriskIsTruncated()
        {
            const string content = "*The quick brown fox jumps over the lazy dog.*";

            Assert.AreEqual("<p><em>The quick brown fox</em></p>\n", MarkDownHelper.Summary(content, 20));
        }