Esempio n. 1
0
        /// <summary>
        /// Effectively validates <see cref="MarkdownEntry" />
        /// </summary>
        /// <param name="entry">the <see cref="MarkdownEntry" /> entry</param>
        public static MarkdownEntry DoNullCheck(this MarkdownEntry entry)
        {
            entry.DoNullCheckForFrontMatter();

            entry.DoNullCheckForContent();

            return(entry);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the <see cref="MarkdownEntry"/>
        /// based on <see cref="MarkdownEntry.FrontMatter"/>
        /// with a <c>title</c> property.
        /// </summary>
        /// <param name="entry">the <see cref="MarkdownEntry" /> entry</param>
        /// <param name="headerLevel"></param>
        /// <returns></returns>
        public static MarkdownEntry WithContentHeader(this MarkdownEntry entry, int headerLevel)
        {
            entry.DoNullCheckForFrontMatter();

            var propertyName = "title";

            if (!entry.FrontMatter.HasProperty(propertyName))
            {
                throw new FormatException($"The expected date property, `{propertyName ?? "[null]"}`, is not here.");
            }

            headerLevel = (headerLevel == 0) ? 1 : Math.Abs(headerLevel);
            var markdownHeader = new string(Enumerable.Repeat('#', (headerLevel > 6) ? 6 : headerLevel).ToArray());

            return(entry.WithEdit(i => i.Content = $"{markdownHeader} {i.FrontMatter[propertyName]}{MarkdownEntry.NewLine}{MarkdownEntry.NewLine}"));
        }