diff --git a/src/MfGames.Nitride.Html/IdentifyHtml.cs b/src/MfGames.Nitride.Html/IdentifyHtml.cs
new file mode 100644
index 0000000..52b82a3
--- /dev/null
+++ b/src/MfGames.Nitride.Html/IdentifyHtml.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+
+using FluentValidation;
+
+using MfGames.Gallium;
+using MfGames.Nitride.Contents;
+using MfGames.Nitride.Generators;
+
+using Zio;
+
+namespace MfGames.Nitride.Html;
+
+///
+/// An operation that identifies Markdown files by their common extensions
+/// and converts them to text input while also adding the IsMarkdown
+/// component to identify them.
+///
+[WithProperties]
+public partial class IdentifyHtml : IOperation
+{
+ private readonly IValidator validator;
+
+ public IdentifyHtml(IValidator validator)
+ {
+ this.validator = validator;
+ }
+
+ public Func IsHtmlTest { get; set; } = null!;
+
+ ///
+ public IEnumerable Run(
+ IEnumerable input,
+ CancellationToken cancellationToken = default)
+ {
+ this.validator.ValidateAndThrow(this);
+
+ return input.SelectEntity(this.MarkTextEntities)
+ .SelectEntity(this.MarkBinaryEntities);
+ }
+
+ private Entity MarkBinaryEntities(
+ Entity entity,
+ UPath path,
+ IBinaryContent binary)
+ {
+ // If we aren't a Markdown file, then there is nothing we can do about that.
+ if (!this.IsHtmlTest(entity, path))
+ {
+ return entity;
+ }
+
+ // Convert the file as a binary.
+ if (binary is ITextContentConvertable textConvertable)
+ {
+ entity = entity.SetTextContent(textConvertable.ToTextContent())
+ .SetIsHtml();
+ }
+ else
+ {
+ throw new InvalidOperationException(
+ "Cannot convert a binary content to a text without ITextContentConvertable.");
+ }
+
+ return entity;
+ }
+
+ private Entity MarkTextEntities(
+ Entity entity,
+ UPath path,
+ ITextContent _)
+ {
+ return this.IsHtmlTest(entity, path)
+ ? entity.SetIsHtml()
+ : entity;
+ }
+}
diff --git a/src/MfGames.Nitride.Html/IdentifyHtmlFromPath.cs b/src/MfGames.Nitride.Html/IdentifyHtmlFromPath.cs
new file mode 100644
index 0000000..19c3d41
--- /dev/null
+++ b/src/MfGames.Nitride.Html/IdentifyHtmlFromPath.cs
@@ -0,0 +1,29 @@
+using FluentValidation;
+
+using MfGames.Gallium;
+
+using Zio;
+
+namespace MfGames.Nitride.Html;
+
+public class IdentifyHtmlFromPath : IdentifyHtml
+{
+ public IdentifyHtmlFromPath(IValidator validator)
+ : base(validator)
+ {
+ this.IsHtmlTest = DefaultIsHtml;
+ }
+
+ private static bool DefaultIsHtml(
+ Entity entity,
+ UPath path)
+ {
+ return (path.GetExtensionWithDot() ?? string.Empty).ToLowerInvariant()
+ switch
+ {
+ ".htm" => true,
+ ".html" => true,
+ _ => false,
+ };
+ }
+}
diff --git a/src/MfGames.Nitride.Html/MfGames.Nitride.Html.csproj b/src/MfGames.Nitride.Html/MfGames.Nitride.Html.csproj
index b780b76..d9ed940 100644
--- a/src/MfGames.Nitride.Html/MfGames.Nitride.Html.csproj
+++ b/src/MfGames.Nitride.Html/MfGames.Nitride.Html.csproj
@@ -9,7 +9,7 @@
-
+
@@ -25,7 +25,7 @@
-
+
diff --git a/src/MfGames.Nitride.Html/Validators/IdentifyHtmlValidator.cs b/src/MfGames.Nitride.Html/Validators/IdentifyHtmlValidator.cs
new file mode 100644
index 0000000..ab9e1ae
--- /dev/null
+++ b/src/MfGames.Nitride.Html/Validators/IdentifyHtmlValidator.cs
@@ -0,0 +1,12 @@
+using FluentValidation;
+
+namespace MfGames.Nitride.Html.Validators;
+
+public class IdentifyHtmlValidator : AbstractValidator
+{
+ public IdentifyHtmlValidator()
+ {
+ this.RuleFor(x => x.IsHtmlTest)
+ .NotNull();
+ }
+}
diff --git a/src/MfGames.Nitride.Markdown/IdentifyMarkdown.cs b/src/MfGames.Nitride.Markdown/IdentifyMarkdown.cs
index c76018b..d40de12 100644
--- a/src/MfGames.Nitride.Markdown/IdentifyMarkdown.cs
+++ b/src/MfGames.Nitride.Markdown/IdentifyMarkdown.cs
@@ -71,16 +71,8 @@ public partial class IdentifyMarkdown : IOperation
UPath path,
ITextContent _)
{
- // If we aren't a Markdown file, then there is nothing
- // we can do about that.
- if (!this.IsMarkdownTest(entity, path))
- {
- return entity;
- }
-
- // We are already text, so just mark it as Markdown.
- entity = entity.Set(IsMarkdown.Instance);
-
- return entity;
+ return this.IsMarkdownTest(entity, path)
+ ? entity.SetIsMarkdown()
+ : entity;
}
}
diff --git a/src/MfGames.Nitride.Markdown/MfGames.Nitride.Markdown.csproj b/src/MfGames.Nitride.Markdown/MfGames.Nitride.Markdown.csproj
index 4f95341..d2e64f9 100644
--- a/src/MfGames.Nitride.Markdown/MfGames.Nitride.Markdown.csproj
+++ b/src/MfGames.Nitride.Markdown/MfGames.Nitride.Markdown.csproj
@@ -10,17 +10,17 @@
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
diff --git a/src/MfGames.Nitride.Markdown/ConvertMarkdownToBaseValidator.cs b/src/MfGames.Nitride.Markdown/Validators/ConvertMarkdownToBaseValidator.cs
similarity index 84%
rename from src/MfGames.Nitride.Markdown/ConvertMarkdownToBaseValidator.cs
rename to src/MfGames.Nitride.Markdown/Validators/ConvertMarkdownToBaseValidator.cs
index e49872e..fc5da66 100644
--- a/src/MfGames.Nitride.Markdown/ConvertMarkdownToBaseValidator.cs
+++ b/src/MfGames.Nitride.Markdown/Validators/ConvertMarkdownToBaseValidator.cs
@@ -1,6 +1,6 @@
using FluentValidation;
-namespace MfGames.Nitride.Markdown;
+namespace MfGames.Nitride.Markdown.Validators;
public class ConvertMarkdownToBaseValidator
: AbstractValidator
diff --git a/src/MfGames.Nitride.Markdown/IdentifyMarkdownValidator.cs b/src/MfGames.Nitride.Markdown/Validators/IdentifyMarkdownValidator.cs
similarity index 82%
rename from src/MfGames.Nitride.Markdown/IdentifyMarkdownValidator.cs
rename to src/MfGames.Nitride.Markdown/Validators/IdentifyMarkdownValidator.cs
index db4c2ba..747dff2 100644
--- a/src/MfGames.Nitride.Markdown/IdentifyMarkdownValidator.cs
+++ b/src/MfGames.Nitride.Markdown/Validators/IdentifyMarkdownValidator.cs
@@ -1,6 +1,6 @@
using FluentValidation;
-namespace MfGames.Nitride.Markdown;
+namespace MfGames.Nitride.Markdown.Validators;
public class IdentifyMarkdownValidator : AbstractValidator
{