-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #425
- Loading branch information
Showing
36 changed files
with
346 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
namespace Html2Markdown.Replacement; | ||
/// <summary> | ||
/// Replaces an anchor tag with the link text and the link URL in Markdown format. | ||
/// </summary> | ||
public class AnchorTagReplacer : CustomReplacer | ||
namespace Html2Markdown.Replacement | ||
{ | ||
public AnchorTagReplacer() | ||
/// <summary> | ||
/// Replaces an anchor tag with the link text and the link URL in Markdown format. | ||
/// </summary> | ||
public class AnchorTagReplacer : CustomReplacer | ||
{ | ||
CustomAction = HtmlParser.ReplaceAnchor; | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AnchorTagReplacer"/> class. | ||
/// Sets the custom action to replace anchor tags with Markdown formatted links. | ||
/// </summary> | ||
public AnchorTagReplacer() | ||
{ | ||
CustomAction = HtmlParser.ReplaceAnchor; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 18 additions & 14 deletions
32
src/Html2Markdown/Replacement/CommonMark/CommonMarkLayoutReplacementGroup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
namespace Html2Markdown.Replacement.CommonMark; | ||
|
||
/// <summary> | ||
/// A group of IReplacer to deal with converting HTML that is | ||
/// used for layout | ||
/// A group of <see cref="IReplacer"/> to deal with converting HTML that is | ||
/// used for layout. | ||
/// </summary> | ||
public class CommonMarkLayoutReplacementGroup : IReplacementGroup | ||
{ | ||
private readonly IList<IReplacer> _replacements = new List<IReplacer> { | ||
new HorizontalRuleTagReplacer(), | ||
new CodeTagReplacer(true), | ||
new PreTagReplacer(), | ||
new ParagraphTagReplacer(), | ||
new BreakTagReplacer(), | ||
new BlockquoteTagReplacer() | ||
}; | ||
private readonly IList<IReplacer> _replacements = new List<IReplacer> { | ||
new HorizontalRuleTagReplacer(), | ||
new CodeTagReplacer(true), | ||
new PreTagReplacer(), | ||
new ParagraphTagReplacer(), | ||
new BreakTagReplacer(), | ||
new BlockquoteTagReplacer() | ||
}; | ||
|
||
public IEnumerable<IReplacer> Replacers() | ||
{ | ||
return _replacements; | ||
} | ||
/// <summary> | ||
/// Returns the list of <see cref="IReplacer"/> instances. | ||
/// </summary> | ||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="IReplacer"/>.</returns> | ||
public IEnumerable<IReplacer> Replacers() | ||
{ | ||
return _replacements; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
using JetBrains.Annotations; | ||
|
||
namespace Html2Markdown.Replacement; | ||
|
||
/// <summary> | ||
/// Allows custom replacement of HTML tags utilising external functions. | ||
/// Allows custom replacement of HTML tags utilizing external functions. | ||
/// </summary> | ||
public class CustomReplacer : IReplacer | ||
{ | ||
public string Replace(string html) | ||
{ | ||
return CustomAction.Invoke(html); | ||
} | ||
/// <summary> | ||
/// Replaces the HTML string using the custom action. | ||
/// </summary> | ||
/// <param name="html">The HTML string to process.</param> | ||
/// <returns>The processed HTML string with the custom replacement applied.</returns> | ||
public string Replace(string html) | ||
{ | ||
return CustomAction.Invoke(html); | ||
} | ||
|
||
public Func<string, string> CustomAction { get; init; } | ||
/// <summary> | ||
/// Gets or sets the custom action to be used for replacing HTML tags. | ||
/// </summary> | ||
[PublicAPI] | ||
public Func<string, string> CustomAction { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
namespace Html2Markdown.Replacement; | ||
|
||
/// <summary> | ||
/// A group of IReplacer to deal with converting HTML entities | ||
/// A group of <see cref="IReplacer"/> to deal with converting HTML entities. | ||
/// </summary> | ||
public class EntitiesReplacementGroup : IReplacementGroup | ||
{ | ||
private readonly IList<IReplacer> _replacements = new List<IReplacer> { | ||
new HtmlEntitiesReplacer() | ||
}; | ||
private readonly IList<IReplacer> _replacements = new List<IReplacer> { | ||
new HtmlEntitiesReplacer() | ||
}; | ||
|
||
public IEnumerable<IReplacer> Replacers() | ||
{ | ||
return _replacements; | ||
} | ||
/// <summary> | ||
/// Returns the list of <see cref="IReplacer"/> instances. | ||
/// </summary> | ||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="IReplacer"/>.</returns> | ||
public IEnumerable<IReplacer> Replacers() | ||
{ | ||
return _replacements; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
namespace Html2Markdown.Replacement; | ||
|
||
/// <summary> | ||
/// HTML Heading Tag Enum | ||
/// </summary> | ||
public enum Heading | ||
{ | ||
/// <summary> | ||
/// Represents an HTML H1 tag. | ||
/// </summary> | ||
H1 = 1, | ||
|
||
/// <summary> | ||
/// Represents an HTML H2 tag. | ||
/// </summary> | ||
H2 = 2, | ||
|
||
/// <summary> | ||
/// Represents an HTML H3 tag. | ||
/// </summary> | ||
H3 = 3, | ||
|
||
/// <summary> | ||
/// Represents an HTML H4 tag. | ||
/// </summary> | ||
H4 = 4, | ||
|
||
/// <summary> | ||
/// Represents an HTML H5 tag. | ||
/// </summary> | ||
H5 = 5, | ||
|
||
/// <summary> | ||
/// Represents an HTML H6 tag. | ||
/// </summary> | ||
H6 = 6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
namespace Html2Markdown.Replacement; | ||
|
||
/// <summary> | ||
/// A group of IReplacer to deal with converting HTML headers | ||
/// A group of <see cref="IReplacer"/> to deal with converting HTML headers. | ||
/// </summary> | ||
public class HeadingReplacementGroup : IReplacementGroup | ||
{ | ||
private readonly IList<IReplacer> _replacements = new List<IReplacer> { | ||
new HeadingTagReplacer(Heading.H1), | ||
new HeadingTagReplacer(Heading.H2), | ||
new HeadingTagReplacer(Heading.H3), | ||
new HeadingTagReplacer(Heading.H4), | ||
new HeadingTagReplacer(Heading.H5), | ||
new HeadingTagReplacer(Heading.H6) | ||
}; | ||
private readonly IList<IReplacer> _replacements = new List<IReplacer> { | ||
new HeadingTagReplacer(Heading.H1), | ||
new HeadingTagReplacer(Heading.H2), | ||
new HeadingTagReplacer(Heading.H3), | ||
new HeadingTagReplacer(Heading.H4), | ||
new HeadingTagReplacer(Heading.H5), | ||
new HeadingTagReplacer(Heading.H6) | ||
}; | ||
|
||
public IEnumerable<IReplacer> Replacers() | ||
{ | ||
return _replacements; | ||
} | ||
/// <summary> | ||
/// Returns the list of <see cref="IReplacer"/> instances. | ||
/// </summary> | ||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="IReplacer"/>.</returns> | ||
public IEnumerable<IReplacer> Replacers() | ||
{ | ||
return _replacements; | ||
} | ||
} |
Oops, something went wrong.