<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace TestStack.BDDfy.Reporters.MarkDown
{
    public class MarkDownReportBuilder : IReportBuilder
    {
        private readonly List<Exception> _exceptions = new List<Exception>();

        public string CreateReport(FileReportModel model)
        {
            var report = new StringBuilder();

            foreach (var story in model.Stories)
            {
                _exceptions.Clear();
                if (story.Metadata != null)
                {
                    report.AppendLine(string.Format("## {0}{1}", story.Metadata.TitlePrefix, story.Metadata.Title));
                    if (!string.IsNullOrEmpty(story.Metadata.Narrative1))
                        report.AppendLine(string.Format(" **{0}**  ", story.Metadata.Narrative1));
                    if (!string.IsNullOrEmpty(story.Metadata.Narrative2))
                        report.AppendLine(string.Format(" **{0}**  ", story.Metadata.Narrative2));
                    if (!string.IsNullOrEmpty(story.Metadata.Narrative3))
                        report.AppendLine(string.Format(" **{0}**  ", story.Metadata.Narrative3));
                }

                report.AppendLine(); // separator

                foreach (var scenarioGroup in story.Scenarios.GroupBy(s => s.Id))
                {
                    if (scenarioGroup.Count() > 1)
                    {
                        // all scenarios in an example based scenario share the same header and narrative
                        var exampleScenario = story.Scenarios.First();
                        report.AppendLine(string.Format("### {0}", exampleScenario.Title));

                        if (exampleScenario.Steps.Any())
                        {
                            foreach (var step in exampleScenario.Steps.Where(s => s.ShouldReport))
                                report.AppendLine("  " + HttpUtility.HtmlEncode(step.Title) + "  ");
                        }

                        report.AppendLine(); // separator
                        WriteExamples(report, exampleScenario, scenarioGroup);
                        ReportTags(report, exampleScenario.Tags);
                    }
                    else
                    {
                        foreach (var scenario in scenarioGroup)
                        {
                            report.AppendLine(string.Format("### {0}", scenario.Title));

                            foreach (var step in scenario.Steps)
                                report.AppendLine("  " + HttpUtility.HtmlEncode(step.Title) + "  ");

                            report.AppendLine(); // separator
                        }
<commit_msg>Fixing #125 while I am at it<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace TestStack.BDDfy.Reporters.MarkDown
{
    public class MarkDownReportBuilder : IReportBuilder
    {
        private readonly List<Exception> _exceptions = new List<Exception>();

        public string CreateReport(FileReportModel model)
        {
            var report = new StringBuilder();

            foreach (var story in model.Stories)
            {
                _exceptions.Clear();
                if (story.Metadata != null)
                {
                    report.AppendLine(string.Format("## {0}{1}", story.Metadata.TitlePrefix, story.Metadata.Title));
                    if (!string.IsNullOrEmpty(story.Metadata.Narrative1))
                        report.AppendLine(string.Format(" **{0}**  ", story.Metadata.Narrative1));
                    if (!string.IsNullOrEmpty(story.Metadata.Narrative2))
                        report.AppendLine(string.Format(" **{0}**  ", story.Metadata.Narrative2));
                    if (!string.IsNullOrEmpty(story.Metadata.Narrative3))
                        report.AppendLine(string.Format(" **{0}**  ", story.Metadata.Narrative3));
                }

                report.AppendLine(); // separator

                foreach (var scenarioGroup in story.Scenarios.GroupBy(s => s.Id))
                {
                    if (scenarioGroup.Count() > 1)
                    {
                        // all scenarios in an example based scenario share the same header and narrative
                        var exampleScenario = story.Scenarios.First();
                        report.AppendLine(string.Format("### {0}", exampleScenario.Title));

                        if (exampleScenario.Steps.Any())
                        {
                            foreach (var step in exampleScenario.Steps.Where(s => s.ShouldReport))
                                report.AppendLine("  " + HttpUtility.HtmlEncode(step.Title) + "  ");
                        }

                        report.AppendLine(); // separator
                        WriteExamples(report, exampleScenario, scenarioGroup);
                        ReportTags(report, exampleScenario.Tags);
                    }
                    else
                    {
                        foreach (var scenario in scenarioGroup)
                        {
                            report.AppendLine(string.Format("### {0}", scenario.Title));

                            foreach (var step in scenario.Steps.Where(s => s.ShouldReport))
                                report.AppendLine("  " + HttpUtility.HtmlEncode(step.Title) + "  ");

                            report.AppendLine(); // separator
                        }

{'fraction_non_alphanumeric': 0.10466786355475763, 'fraction_numerical': 0.005565529622980251, 'mean_word_length': 1.4148244473342002, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5449193', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1265, 'n_words': 253}