Skip to content

Commit

Permalink
Add capability to add custom replacer to scheme
Browse files Browse the repository at this point in the history
Closes #463
  • Loading branch information
baynezy committed Aug 23, 2024
1 parent c6f831b commit 7c2f893
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added support extending existing Schemes for customisation

## [7.0.0.8] - 2024-08-15

### Added
Expand Down
5 changes: 5 additions & 0 deletions src/Html2Markdown/Scheme/AbstractScheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public IList<IReplacer> Replacers()
{
return ReplacerCollection;
}

public void AddReplacer(IReplacer replacer)

Check warning on line 34 in src/Html2Markdown/Scheme/AbstractScheme.cs

View workflow job for this annotation

GitHub Actions / build / build-libraries

Missing XML comment for publicly visible type or member 'AbstractScheme.AddReplacer(IReplacer)'

Check warning on line 34 in src/Html2Markdown/Scheme/AbstractScheme.cs

View workflow job for this annotation

GitHub Actions / build / build-libraries

Missing XML comment for publicly visible type or member 'AbstractScheme.AddReplacer(IReplacer)'
{
ReplacerCollection.Add(replacer);
}
}
106 changes: 106 additions & 0 deletions test/Html2Markdown.Test/Scheme/AbstractSchemeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Collections.Generic;
using Html2Markdown.Replacement;
using Html2Markdown.Scheme;

namespace Html2Markdown.Test.Scheme;

public class AbstractSchemeTests
{
[Test]
public void Replacers_WhenCalled_ReturnsReplacerCollection()
{
// arrange
const int expectedCount = 1;
var scheme = new TestScheme();

// act
var replacers = scheme.Replacers();

// assert
Assert.That(replacers.Count, Is.EqualTo(expectedCount));
}

[Test]
public void Replacers_WhenCalled_ReturnsReplacerCollectionWithTestReplacer()
{
// arrange
var scheme = new TestScheme();

// act
var replacers = scheme.Replacers();

// assert
Assert.That(replacers[0], Is.InstanceOf<TestReplacer>());
}

[Test]
public void Replacers_WhenCalled_ReturnsReplacerCollectionWithTestReplacerReplaceMethod()
{
// arrange
const string expected = "test";
var scheme = new TestScheme();

// act
var replacers = scheme.Replacers();
var result = replacers[0].Replace(string.Empty);

// assert
Assert.That(result, Is.EqualTo(expected));
}

[Test]
public void AddReplacer_WhenCalled_AddsReplacerToReplacerCollection()
{
// arrange
const int expectedCount = 2;
var scheme = new TestScheme();

// act
scheme.AddReplacer(new TestReplacer());
var replacers = scheme.Replacers();

// assert
Assert.That(replacers.Count, Is.EqualTo(expectedCount));
}

[Test]
public void AddReplacer_WhenCalled_AddsReplacerToReplacerCollectionWithTestReplacer()
{
// arrange
var scheme = new TestScheme();

// act
scheme.AddReplacer(new TestReplacer());
var replacers = scheme.Replacers();

// assert
Assert.That(replacers[1], Is.InstanceOf<TestReplacer>());
}
}

public class TestScheme : AbstractScheme
{
public TestScheme()
{
AddReplacementGroup(ReplacerCollection, new TestReplacementGroup());
}
}

public class TestReplacementGroup : IReplacementGroup
{
public IEnumerable<IReplacer> Replacers()
{
return new List<IReplacer>
{
new TestReplacer()
};
}
}

public class TestReplacer : IReplacer
{
public string Replace(string html)
{
return "test";
}
}

0 comments on commit 7c2f893

Please sign in to comment.