Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion HtmlToMarkdown.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pester tests, see https://github.com/Pester/Pester/wiki
Import-LocalizedData -BindingVariable manifest -BaseDirectory ./src/* -FileName (Split-Path $PWD -Leaf)
$psd1 = Resolve-Path ./src/*/bin/Debug/*/*.psd1
$psd1 = Resolve-Path ./src/*/bin/*/net*/publish/*.psd1
if(1 -lt ($psd1 |Measure-Object).Count) {throw "Too many module binaries found: $psd1"}
$module = Import-Module "$psd1" -PassThru -vb
$eol = [Environment]::NewLine
Expand Down
24 changes: 0 additions & 24 deletions HtmlToMarkdown.csproj

This file was deleted.

40 changes: 0 additions & 40 deletions HtmlToMarkdown.sln

This file was deleted.

10 changes: 10 additions & 0 deletions HtmlToMarkdown.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Solution>
<Configurations>
<Platform Name="Any CPU" />
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Folder Name="/src/">
<Project Path="src/HtmlToMarkdown/HtmlToMarkdown.fsproj" />
</Folder>
</Solution>
18 changes: 17 additions & 1 deletion docs/Convert-HtmlToMarkdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Converts HTML to Markdown.
Convert-HtmlToMarkdown -Html <String> [-DefaultCodeBlockLanguage <String>] [-GithubFlavored]
[-ListBulletChar <Char>] [-RemoveComments] [-SmartHrefHandling] [-UnknownTags <UnknownTagsOption>]
[-PassThroughTags <String[]>] [-WhitelistUriSchemes <String[]>]
[-TableWithoutHeaderRowHandling <TableWithoutHeaderRowHandlingOption>] [<CommonParameters>]
[-TableWithoutHeaderRowHandling <TableWithoutHeaderRowHandlingOption>] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -203,6 +204,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -ProgressAction
{{ Fill ProgressAction Description }}

```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

Expand Down
183 changes: 91 additions & 92 deletions src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs
Original file line number Diff line number Diff line change
@@ -1,92 +1,91 @@
namespace HtmlToMarkdown

open System.Management.Automation

open ReverseMarkdown

/// Converts HTML to Markdown.
[<Cmdlet(VerbsData.Convert, "HtmlToMarkdown")>]
[<OutputType(typeof<string>)>]
[<Alias("Convert-HtmlToCommonMark")>]
type ConvertHtmlToMarkdownCommand () =
inherit PSCmdlet ()

/// HTML to convert.
[<Parameter(Mandatory=true,ValueFromPipeline=true,ValueFromPipelineByPropertyName=true)>]
[<ValidateNotNullOrEmpty>]
[<Alias("InputObject","OuterHtml")>]
member val Html : string = null with get, set

/// Option to set the default code block language for Github style markdown if class based language markers are not available.
[<Parameter>]
[<ValidateNotNullOrEmpty>]
[<Alias("CodeDefault")>]
member val DefaultCodeBlockLanguage : string = null with get, set

/// Github style markdown for br, pre and table.
[<Parameter>]
[<Alias("GFM")>]
member val GithubFlavored : SwitchParameter = SwitchParameter false with get, set

/// Sets the bullet character to use for unordered lists.
[<Parameter>]
[<Alias("Bullets")>]
member val ListBulletChar : char = '-' with get, set

/// Remove comment tags with text.
[<Parameter>]
[<Alias("StripComments")>]
member val RemoveComments : SwitchParameter = SwitchParameter false with get, set

/// Outputs link as auto-linking text (not an explicit link) when the text matches the link.
[<Parameter>]
[<Alias("AutoLink")>]
member val SmartHrefHandling : SwitchParameter = SwitchParameter false with get, set

/// What to do with unknown tags: PassThrough includes it as is, Drop removes it, Bypass ignores it, and Raise throws an exception.
[<Parameter>]
[<Alias("UnknownElements")>]
member val UnknownTags : Config.UnknownTagsOption = Config.UnknownTagsOption.PassThrough with get, set

/// Pass a list of tags to pass through as-is without any processing.
[<Parameter>]
[<ValidateNotNullOrEmpty>]
[<Alias("PassThroughElements","KeepTags","KeepElements")>]
member val PassThroughTags : string[] = Array.empty with get, set

/// Specify which schemes (without trailing colon) are to be allowed for links and images. Empty string allows unknown schemes.
[<Parameter>]
[<Alias("AllowlistUriSchemes")>]
member val WhitelistUriSchemes : string[] = Array.empty with get, set

/// What to do about tables without a header row. Default: first row will be used as header row. EmptyRow: an empty header row is created.
[<Parameter>]
[<Alias("TableHeaderDefault")>]
member val TableWithoutHeaderRowHandling : Config.TableWithoutHeaderRowHandlingOption =
Config.TableWithoutHeaderRowHandlingOption.Default with get, set

member val Converter : Converter = null with get, set

// optional: setup before pipeline input starts (e.g. Name is set, InputObject is not)
override x.BeginProcessing () =
base.BeginProcessing ()
x.Converter
<- Converter
<| Config(DefaultCodeBlockLanguage = x.DefaultCodeBlockLanguage,
GithubFlavored = x.GithubFlavored,
ListBulletChar = x.ListBulletChar,
RemoveComments = x.RemoveComments,
SmartHrefHandling = x.SmartHrefHandling,
UnknownTags = x.UnknownTags,
PassThroughTags = x.PassThroughTags,
WhitelistUriSchemes = x.WhitelistUriSchemes,
TableWithoutHeaderRowHandling = x.TableWithoutHeaderRowHandling)

// optional: handle each pipeline value (e.g. InputObject)
override x.ProcessRecord () =
base.ProcessRecord ()
x.Converter.Convert(x.Html) |> x.WriteObject

// optional: finish after all pipeline input
override x.EndProcessing () =
base.EndProcessing ()
namespace HtmlToMarkdown

open System.Management.Automation

open ReverseMarkdown

/// Converts HTML to Markdown.
[<Cmdlet(VerbsData.Convert, "HtmlToMarkdown")>]
[<OutputType(typeof<string>)>]
[<Alias("Convert-HtmlToCommonMark")>]
type ConvertHtmlToMarkdownCommand () =
inherit PSCmdlet ()

/// HTML to convert.
[<Parameter(Mandatory=true,ValueFromPipeline=true,ValueFromPipelineByPropertyName=true)>]
[<ValidateNotNullOrEmpty>]
[<Alias("InputObject","OuterHtml")>]
member val Html : string = null with get, set

/// Option to set the default code block language for Github style markdown if class based language markers are not available.
[<Parameter>]
[<ValidateNotNullOrEmpty>]
[<Alias("CodeDefault")>]
member val DefaultCodeBlockLanguage : string = null with get, set

/// Github style markdown for br, pre and table.
[<Parameter>]
[<Alias("GFM")>]
member val GithubFlavored : SwitchParameter = SwitchParameter false with get, set

/// Sets the bullet character to use for unordered lists.
[<Parameter>]
[<Alias("Bullets")>]
member val ListBulletChar : char = '-' with get, set

/// Remove comment tags with text.
[<Parameter>]
[<Alias("StripComments")>]
member val RemoveComments : SwitchParameter = SwitchParameter false with get, set

/// Outputs link as auto-linking text (not an explicit link) when the text matches the link.
[<Parameter>]
[<Alias("AutoLink")>]
member val SmartHrefHandling : SwitchParameter = SwitchParameter false with get, set

/// What to do with unknown tags: PassThrough includes it as is, Drop removes it, Bypass ignores it, and Raise throws an exception.
[<Parameter>]
[<Alias("UnknownElements")>]
member val UnknownTags : Config.UnknownTagsOption = Config.UnknownTagsOption.PassThrough with get, set

/// Pass a list of tags to pass through as-is without any processing.
[<Parameter>]
[<ValidateNotNullOrEmpty>]
[<Alias("PassThroughElements","KeepTags","KeepElements")>]
member val PassThroughTags : string[] = Array.empty with get, set

/// Specify which schemes (without trailing colon) are to be allowed for links and images. Empty string allows unknown schemes.
[<Parameter>]
[<Alias("AllowlistUriSchemes")>]
member val WhitelistUriSchemes : string[] = Array.empty with get, set

/// What to do about tables without a header row. Default: first row will be used as header row. EmptyRow: an empty header row is created.
[<Parameter>]
[<Alias("TableHeaderDefault")>]
member val TableWithoutHeaderRowHandling : Config.TableWithoutHeaderRowHandlingOption =
Config.TableWithoutHeaderRowHandlingOption.Default with get, set

member val Converter : Converter = null with get, set

// optional: setup before pipeline input starts (e.g. Name is set, InputObject is not)
override x.BeginProcessing () =
base.BeginProcessing ()
let cfg = Config(DefaultCodeBlockLanguage = x.DefaultCodeBlockLanguage,

Check warning on line 73 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Formatting.DefaultCodeBlockLanguage.

Check warning on line 73 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Formatting.DefaultCodeBlockLanguage.

Check warning on line 73 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Formatting.DefaultCodeBlockLanguage.

Check warning on line 73 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Formatting.DefaultCodeBlockLanguage.
GithubFlavored = x.GithubFlavored,
ListBulletChar = x.ListBulletChar,

Check warning on line 75 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Formatting.ListBulletChar.

Check warning on line 75 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Formatting.ListBulletChar.

Check warning on line 75 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Formatting.ListBulletChar.

Check warning on line 75 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Formatting.ListBulletChar.
RemoveComments = x.RemoveComments,

Check warning on line 76 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Formatting.RemoveComments.

Check warning on line 76 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Formatting.RemoveComments.
SmartHrefHandling = x.SmartHrefHandling,

Check warning on line 77 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Links.SmartHref.

Check warning on line 77 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Links.SmartHref.
UnknownTags = x.UnknownTags,

Check warning on line 78 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Tags.Unknown.

Check warning on line 78 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Tags.Unknown.
TableWithoutHeaderRowHandling = x.TableWithoutHeaderRowHandling)

Check warning on line 79 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Tables.WithoutHeaderRow.

Check warning on line 79 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Tables.WithoutHeaderRow.
Array.iter (cfg.PassThroughTags.Add >> ignore) x.PassThroughTags

Check warning on line 80 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Tags.PassThrough.

Check warning on line 80 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Tags.PassThrough.
Array.iter (cfg.WhitelistUriSchemes.Add >> ignore) x.WhitelistUriSchemes

Check warning on line 81 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest)

This construct is deprecated. Use Links.WhitelistedSchemes.

Check warning on line 81 in src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest)

This construct is deprecated. Use Links.WhitelistedSchemes.
x.Converter <- Converter <| cfg

// optional: handle each pipeline value (e.g. InputObject)
override x.ProcessRecord () =
base.ProcessRecord ()
x.Converter.Convert(x.Html) |> x.WriteObject

// optional: finish after all pipeline input
override x.EndProcessing () =
base.EndProcessing ()
38 changes: 37 additions & 1 deletion src/HtmlToMarkdown/HtmlToMarkdown.dll-Help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
Expand Down Expand Up @@ -265,6 +277,18 @@
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters>
<command:inputTypes>
<command:inputType>
Expand Down Expand Up @@ -294,7 +318,7 @@
<command:examples>
<command:example>
<maml:title>-------------------------- Example 1 --------------------------</maml:title>
<dev:code>PS C:\&gt; '&lt;h1&gt;On Board&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;Ford&lt;li&gt;Zaphod&lt;li&gt;Marvin&lt;/ul&gt;' |Convert-HtmlToMarkdown
<dev:code>'&lt;h1&gt;On Board&lt;/h1&gt;&lt;ul&gt;&lt;li&gt;Ford&lt;li&gt;Zaphod&lt;li&gt;Marvin&lt;/ul&gt;' |Convert-HtmlToMarkdown

# On Board

Expand All @@ -305,6 +329,18 @@
<maml:para></maml:para>
</dev:remarks>
</command:example>
<command:example>
<maml:title>-------------------------- Example 2 --------------------------</maml:title>
<dev:code>Invoke-RestMethod https://google.com/ |Convert-HtmlToCommonMark -UnknownTags Bypass

1. [Search](https://www.google.com/webhp?tab=ww)
2. [Images](https://www.google.com/imghp?hl=en&amp;tab=wi)
3. [Maps](https://maps.google.com/maps?hl=en&amp;tab=wl)
...</dev:code>
<dev:remarks>
<maml:para></maml:para>
</dev:remarks>
</command:example>
</command:examples>
<command:relatedLinks />
</command:command>
Expand Down
Loading
Loading