/// <summary> /// Writes the provided output to the file. /// </summary> /// <param name="output">The output to write.</param> /// <param name="style">The optional Markdown style to apply.</param> /// <param name="format">The optional Markdown format to apply.</param> /// <param name="useMdLineBreaks"> /// If true, when the text is cleansed, all newlines will be replaced by Markdown line /// breaks to maintain the assumed intended line breaks in the text; otherwise, the text's /// newlines will not parsed as line breaks by Markdown parsers. /// </param> public void Write(object output, MdStyle style = MdStyle.None, MdFormat format = MdFormat.None, bool useMdLineBreaks = true) { string text = MdText.StyleAndFormat(output, style, format); _Stream.Write(MdText.Cleanse(text, useMdLineBreaks)); }
/// <summary> /// Writes the provided output to the file, followed by a Markdown paragraph break to /// terminate the line and start a new paragraph. /// </summary> /// <param name="output">The output to write.</param> /// <param name="style">The optional Markdown style to apply.</param> /// <param name="format">The optional Markdown format to apply.</param> /// <param name="useMdLineBreaks"> /// If true, when the text is cleansed, all newlines will be replaced by Markdown line /// breaks to maintain the assumed intended line breaks in the text; otherwise, the text's /// newlines will not parsed as line breaks by Markdown parsers. /// </param> public void WriteLine(object output, MdStyle style = MdStyle.None, MdFormat format = MdFormat.None, bool useMdLineBreaks = true, int numNewLines = 2) { string text = MdText.StyleAndFormat(output, style, format); _Stream.Write(MdText.Cleanse(text, useMdLineBreaks) + MakeParagraphLineBreak(numNewLines)); }
public static string StyleSubstring(this string str, string substring, MdStyle style, bool firstOnly = false) { if (string.IsNullOrEmpty(str)) { throw new System.ArgumentException("cannot stylize empty string", nameof(str)); } if (string.IsNullOrEmpty(substring)) { throw new System.ArgumentException("cannot stylize empty string", nameof(str)); } if (!firstOnly) { return(str?.Replace(substring, MdText.Style(substring, style), System.StringComparison.Ordinal)); } int pos = str.IndexOf(substring, System.StringComparison.Ordinal); if (pos < 0) { return(str); } return(str.Substring(0, pos) + MdText.Style(substring, style) + str.Substring(pos + substring.Length)); }
/// <summary> /// Writes the provided output to the file using the /// <see cref="MdFormat.UnorderedListItem"/> format, followed by a Markdown paragraph break /// to terminate the list item. /// </summary> /// <param name="output">The output to write.</param> /// <param name="listIndent"> /// The optional indent of the list item (0 adds no indent, 1 adds a single indentation to /// create a sublist, etc). Negative values are ignored. /// </param> /// <param name="style">The optional Markdown style to apply.</param> public void WriteUnorderedListItem(object output, int listIndent = 0, MdStyle style = MdStyle.None) { string text = MdText.StyleAndFormat(output, style, MdFormat.UnorderedListItem); text = MdText.Indent(text, listIndent); stream.Write(MdText.Cleanse(text, true) + MdText.ParagraphBreak); }
/// <summary> /// Writes the provided output to the file using the /// <see cref="MdFormat.UnorderedListItem"/> format, followed by a Markdown paragraph break /// to terminate the list item. /// </summary> /// <param name="output">The output to write.</param> /// <param name="listIndent"> /// The optional indent of the list item (0 adds no indent, 1 adds a single indentation to /// create a sublist, etc). Negative values are ignored. /// </param> /// <param name="style">The optional Markdown style to apply.</param> /// <param name="format">The optional Markdown format to apply.</param> /// </param> public void WriteUnorderedListItem(object output, int listIndent = 0, MdStyle style = MdStyle.None, MdFormat format = MdFormat.None, int numNewLines = 1) { string text = MdText.Format(output, format); text = MdText.StyleAndFormat(text, style, MdFormat.UnorderedListItem); text = MdText.Indent(text, listIndent); _Stream.Write(MdText.Cleanse(text, true) + MakeParagraphLineBreak(numNewLines)); }
/// <summary> /// Writes the provided output to the file using the <see cref="MdFormat.OrderedListItem"/> /// format, followed by a Markdown paragraph break to terminate the list item. /// </summary> /// <param name="output">The output to write.</param> /// <param name="itemNumber"> /// The optional item number of the list item. Does not affect parsed Markdown output or the /// list order, only the raw text. Negative values are ignored. /// </param> /// <param name="listIndent"> /// The optional indent of the list item (0 adds no indent, 1 adds a single indentation to /// create a sublist, etc). Negative values are ignored. /// </param> /// <param name="style">The optional Markdown style to apply.</param> public void WriteOrderedListItem(object output, int itemNumber = 1, int listIndent = 0, MdStyle style = MdStyle.None) { string text = MdText.StyleAndFormat(output, style, MdFormat.OrderedListItem); //replace the list item number supplied by MdText with the number provided if (itemNumber != MdText.DefaultListItemNumber && itemNumber >= 0) { text = itemNumber + text.Substring(1); } text = MdText.Indent(text, listIndent); _Stream.Write(MdText.Cleanse(text, true) + MdText.ParagraphBreak); }
/// <summary> /// Styles one or more substrings of the provided string using the specified /// <see cref="MdStyle"/>. /// </summary> /// <param name="str">The string containing the substring to style.</param> /// <param name="substring">The substring to style.</param> /// <param name="style">The Markdown style to apply.</param> /// <param name="firstOnly"> /// If true, only the first occurrence of the substring is styled; otherwise, all /// occurrences of the substring are styled. /// </param> /// <returns> /// The selectively styled string. If <paramref name="str"/> does not contain any /// occurrences of <paramref name="substring"/>, it is returned unchanged. /// </returns> public static string StyleSubstring(this string str, string substring, MdStyle style, bool firstOnly = false) { if (!firstOnly) { return str.Replace(substring, MdText.Style(substring, style)); } int pos = str.IndexOf(substring); if (pos < 0) { return str; } return str.Substring(0, pos) + MdText.Style(substring, style) + str.Substring(pos + substring.Length); }
/// <summary> /// Styles one or more substrings of the provided string using the specified /// <see cref="MdStyle"/>. /// </summary> /// <param name="str">The string containing the substring to style.</param> /// <param name="substring">The substring to style.</param> /// <param name="style">The Markdown style to apply.</param> /// <param name="firstOnly"> /// If true, only the first occurrence of the substring is styled; otherwise, all /// occurrences of the substring are styled. /// </param> /// <returns> /// The selectively styled string. If <paramref name="str"/> does not contain any /// occurrences of <paramref name="substring"/>, it is returned unchanged. /// </returns> public static string StyleSubstring(this string str, string substring, MdStyle style, bool firstOnly = false) { if (!firstOnly) { return(str.Replace(substring, MdText.Style(substring, style))); } int pos = str.IndexOf(substring); if (pos < 0) { return(str); } return(str.Substring(0, pos) + MdText.Style(substring, style) + str.Substring(pos + substring.Length)); }
/// <summary> /// Styles the provided text using the specified <see cref="MdStyle"/>. /// </summary> /// <param name="text">The text to style.</param> /// <param name="style">The Markdown style to apply.</param> /// <returns>The styled string.</returns> /// <exception cref="System.ArgumentException">The style is not recognized.</exception> public static string Style(object text, MdStyle style) { string wrap; switch (style) { case MdStyle.None: wrap = string.Empty; break; case MdStyle.Italic: wrap = ItalicWrap; break; case MdStyle.Bold: wrap = BoldWrap; break; case MdStyle.BoldItalic: wrap = ItalicWrap + BoldWrap; break; case MdStyle.Code: wrap = CodeWrap; break; case MdStyle.StrikeThrough: wrap = StrikeThroughWrap; break; default: throw new ArgumentException("The style is not recognized."); } return(wrap + text + wrap); }
/// <summary> /// Styles then formats the provided text using the specified <see cref="MdStyle"/> and /// <see cref="MdFormat"/>. /// </summary> /// <param name="text">The text to format and style.</param> /// <param name="style">The Markdown style to apply.</param> /// <param name="format">The Markdown format to apply.</param> /// <returns>The formatted and styled string.</returns> public static string StyleAndFormat(object text, MdStyle style, MdFormat format) { return Format(Style(text, style), format); }
/// <summary> /// Styles the provided text using the specified <see cref="MdStyle"/>. /// </summary> /// <param name="text">The text to style.</param> /// <param name="style">The Markdown style to apply.</param> /// <returns>The styled string.</returns> /// <exception cref="System.ArgumentException">The style is not recognized.</exception> public static string Style(object text, MdStyle style) { string wrap; switch (style) { case MdStyle.None: wrap = String.Empty; break; case MdStyle.Italic: wrap = ItalicWrap; break; case MdStyle.Bold: wrap = BoldWrap; break; case MdStyle.BoldItalic: wrap = ItalicWrap + BoldWrap; break; case MdStyle.Code: wrap = CodeWrap; break; case MdStyle.StrikeThrough: wrap = StrikeThroughWrap; break; default: throw new ArgumentException("The style is not recognized."); } return wrap + text + wrap; }
/// <summary> /// Writes the provided output to the file, followed by a Markdown paragraph break to /// terminate the line and start a new paragraph. /// </summary> /// <param name="output">The output to write.</param> /// <param name="style">The optional Markdown style to apply.</param> /// <param name="format">The optional Markdown format to apply.</param> /// <param name="useMdLineBreaks"> /// If true, when the text is cleansed, all newlines will be replaced by Markdown line /// breaks to maintain the assumed intended line breaks in the text; otherwise, the text's /// newlines will not parsed as line breaks by Markdown parsers. /// </param> public void WriteLine(object output, MdStyle style = MdStyle.None, MdFormat format = MdFormat.None, bool useMdLineBreaks = true) { string text = MdText.StyleAndFormat(output, style, format); stream.Write(MdText.Cleanse(text, useMdLineBreaks) + MdText.ParagraphBreak); }
/// <summary> /// Writes the provided output to the file using the <see cref="MdFormat.OrderedListItem"/> /// format, followed by a Markdown paragraph break to terminate the list item. /// </summary> /// <param name="output">The output to write.</param> /// <param name="itemNumber"> /// The optional item number of the list item. Does not affect parsed Markdown output or the /// list order, only the raw text. Negative values are ignored. /// </param> /// <param name="listIndent"> /// The optional indent of the list item (0 adds no indent, 1 adds a single indentation to /// create a sublist, etc). Negative values are ignored. /// </param> /// <param name="style">The optional Markdown style to apply.</param> public void WriteOrderedListItem(object output, int itemNumber = 1, int listIndent = 0, MdStyle style = MdStyle.None) { string text = MdText.StyleAndFormat(output, style, MdFormat.OrderedListItem); //replace the list item number supplied by MdText with the number provided if (itemNumber != MdText.DefaultListItemNumber && itemNumber >= 0) { text = itemNumber + text.Substring(1); } text = MdText.Indent(text, listIndent); stream.Write(MdText.Cleanse(text, true) + MdText.ParagraphBreak); }
/// <summary> /// Styles then formats the provided text using the specified <see cref="MdStyle"/> and /// <see cref="MdFormat"/>. /// </summary> /// <param name="text">The text to format and style.</param> /// <param name="style">The Markdown style to apply.</param> /// <param name="format">The Markdown format to apply.</param> /// <returns>The formatted and styled string.</returns> public static string StyleAndFormat(object text, MdStyle style, MdFormat format) { return(Format(Style(text, style), format)); }