예제 #1
0
        public void When_language_is_missing_brush_set_to_text()
        {
            var content = "[code gutter=false]var i = 1;[/code]";
            var result  = _svc.Parse(content);

            Assert.Equal("<pre class=\"brush: text; gutter: false\">var i = 1;</pre>", result);
        }
예제 #2
0
        public async Task Handle(ModelPreRender <BlogPostViewModel> notification, CancellationToken cancellationToken)
        {
            if (!await IsPluginActiveAsync() || !(notification.Model is BlogPostViewModel))
            {
                return;
            }

            var body = ((BlogPostViewModel)notification.Model).Body;

            ((BlogPostViewModel)notification.Model).Body = shortcodeService.Parse(body);
        }
예제 #3
0
        /// <summary>
        /// Handles <see cref="PageVM"/> by parsing shortcodes then nav links.
        /// </summary>
        /// <param name="notification"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task Handle(ModelPreRender <PageVM> notification, CancellationToken cancellationToken)
        {
            if (!(notification.Model is PageVM))
            {
                return(Task.CompletedTask);
            }

            var pageVM = (PageVM)notification.Model;

            ((PageVM)notification.Model).Body = shortcodeService.Parse(pageVM.Body);

            return(Task.CompletedTask);
        }
예제 #4
0
        /// <summary>
        /// Returns previewing of a single post.
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="day"></param>
        /// <param name="slug"></param>
        /// <returns></returns>
        public async Task <IActionResult> Preview(int year, int month, int day, string slug)
        {
            try
            {
                // Get back blog post from TempData
                DateTime dt       = new DateTime(year, month, day);
                var      link     = BlogRoutes.GetPostPreviewRelativeLink(dt, slug);
                var      blogPost = TempData.Get <BlogPost>(link);

                // Prep it
                blogPost.Body = _shortcodeSvc.Parse(blogPost.Body);
                blogPost.Body = OembedParser.Parse(blogPost.Body);
                var blogSettings = await _settingSvc.GetSettingsAsync <BlogSettings>();

                blogSettings.DisqusShortname = ""; // when preview turn off disqus
                var vm = new BlogPostViewModel(blogPost, blogSettings, Request);

                // Show it
                return(View("Post", vm));
            }
            catch (Exception)
            {
                // when user access the preview link directly or when user clicks on other links
                // and navigates away during the preview, hacky need to find a better way.
                return(RedirectToAction("ErrorCode", "Home", new { statusCode = 404 }));
            }
        }
예제 #5
0
        public void YouTubeShortcode_supports_two_kinds_of_youtube_url_formats(string url)
        {
            var result = _svc.Parse($"[youtube {url}]");

            Assert.Equal(
                "<iframe width=\"560\" height=\"315\" src =\"https://www.youtube.com/embed/MNor4dYXa6U\" frameborder =\"0\" allowfullscreen></iframe>",
                result);
        }
예제 #6
0
        /// <summary>
        /// Pre render processing of a blog post.
        /// </summary>
        /// <param name="blogPost"></param>
        /// <returns></returns>
        private async Task <BlogPost> PreRenderAsync(BlogPost blogPost)
        {
            if (blogPost == null)
            {
                return(blogPost);
            }

            blogPost.Body = _shortcodeSvc.Parse(blogPost.Body);
            blogPost.Body = OembedParser.Parse(blogPost.Body);
            blogPost.Body = await _imageService.ProcessResponsiveImageAsync(blogPost.Body);

            return(blogPost);
        }
예제 #7
0
        /// <summary>
        /// Gets a <see cref="BlogPost"/> for display to client from a <see cref="Post"/>.
        /// </summary>
        /// <param name="post"></param>
        /// <param name="parseShortcode">True will parse shortcode into html, false otherwise.</param>
        /// <returns></returns>
        /// <remarks>
        /// It readies <see cref="Post.CreatedOnDisplay"/>, Title, Excerpt, CategoryTitle, Tags and Body with shortcodes.
        /// </remarks>
        private async Task <BlogPost> GetBlogPostAsync(Post post, bool parseShortcode)
        {
            var blogPost     = _mapper.Map <Post, BlogPost>(post);
            var coreSettings = await _settingSvc.GetSettingsAsync <CoreSettings>();

            var blogSettings = await _settingSvc.GetSettingsAsync <BlogSettings>();

            // Friendly post time if the post was published within 2 days
            // else show the actual date time in setting's timezone
            blogPost.CreatedOnDisplay = (DateTimeOffset.UtcNow.Day - blogPost.CreatedOn.Day) > 2 ?
                                        Util.ConvertTime(blogPost.CreatedOn, coreSettings.TimeZoneId).ToString("dddd, MMMM dd, yyyy") :
                                        Util.ConvertTime(blogPost.CreatedOn, coreSettings.TimeZoneId).Humanize();

            if (blogPost.UpdatedOn.HasValue)
            {
                blogPost.UpdatedOnDisplay =
                    Util.ConvertTime(blogPost.UpdatedOn.Value, coreSettings.TimeZoneId).ToString("MM/dd/yyyy");
            }

            // Title
            blogPost.Title = WebUtility.HtmlDecode(blogPost.Title); // since OLW encodes it, we decode it here

            // Excerpt
            blogPost.Excerpt = post.Excerpt.IsNullOrEmpty() ? Util.GetExcerpt(post.Body, EXCERPT_WORD_LIMIT) : post.Excerpt;

            // CategoryTitle
            blogPost.CategoryTitle = post.Category.Title;

            // Tags and TagTitles
            foreach (var postTag in post.PostTags)
            {
                blogPost.Tags.Add(postTag.Tag);
                blogPost.TagTitles.Add(postTag.Tag.Title);
            }

            // Shortcodes
            blogPost.Body = parseShortcode ? _shortcodeSvc.Parse(post.Body) : post.Body;

            // Embeds
            blogPost.Body = parseShortcode ? OembedParser.Parse(blogPost.Body) : blogPost.Body;

            _logger.LogDebug("Show {@BlogPost}", blogPost);
            return(blogPost);
        }