コード例 #1
0
        /// <summary>
        /// Exports the specified <paramref name="changes">changeset</paramref> to a Html <paramref name="file" />.
        /// </summary>
        /// <param name="changes">The changes to export.</param>
        /// <param name="file">The file to create or overwrite. <see cref="ExportOptions.Append" /> is ignored.</param>
        /// <param name="options">The options for exporting.</param>
        /// <exception cref="NotImplementedException"></exception>
        public void Export(ChangeSet changes, FileInfo file, ExportOptions options = null)
        {
            var markdown = MarkDownChangelogExporter.WriteChanges(changes, options);

            var changesAsHtml = Markdig.Markdown.ToHtml(markdown.ToString());

            var html = $@"<!DOCTYPE html>
<html>
    <head>
        <title>Changelog for {changes.Name}</title>

		<!-- Custom CSS -->
		<style>
			/* Enable line-breaks withing change log messages */
			li {{
				white-space:pre-line;
			}}
		</style>

		<!-- CSS from markdownpad-github -->
        <style>
{Css}
        </style>
    </head>
    <body>
    {changesAsHtml}
    </body>
</html>";

            using (var w = file.CreateText())
                w.Write(html);
        }
コード例 #2
0
        /// <summary>Exports the specified format.</summary>
        /// <param name="changes">The changes to exort.</param>
        /// <param name="format">The format to export to.</param>
        /// <param name="targetFile">The target file (when applicable).</param>
        /// <param name="exportOptions">The export options.</param>
        /// <exception cref="NotImplementedException">When an export format (<paramref name="format"/>) is not supported yet</exception>
        /// <returns>A <see cref="FileInfo"/> referring to the exported file (when applicable).</returns>
        public static FileInfo Export(
            this ChangeSet changes,
            OutputFormat format,
            string targetFile,
            ExportOptions exportOptions)
        {
            IChangelogExporter exporter = null;

            var file = new FileInfo(targetFile);

            if (string.IsNullOrWhiteSpace(file.Extension))
            {
                file = new FileInfo($"{targetFile}.{format.FileExtension()}");
            }

            switch (format)
            {
            case OutputFormat.MarkDown:

                exporter = new MarkDownChangelogExporter();
                break;

            case OutputFormat.Console:

                exporter = new ConsoleChangelogExporter();
                break;

            case OutputFormat.JSON:

                exporter = new JsonChangelogExporter();
                break;

            case OutputFormat.XML:

                exporter = new XmlChangelogExporter();
                break;

            case OutputFormat.Html:

                exporter = new HtmlChangelogExporter();
                break;

            default:
                throw new NotImplementedException($"Export to {format} is not yet implemented");
            }

            file.Directory.AssertExistence();

            exporter.Export(changes, file, exportOptions);

            file.Refresh();

            return(file);
        }