diff --git a/HtmlToMarkdown.Tests.ps1 b/HtmlToMarkdown.Tests.ps1 index c88c0e0..4ebb9c0 100644 --- a/HtmlToMarkdown.Tests.ps1 +++ b/HtmlToMarkdown.Tests.ps1 @@ -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 diff --git a/HtmlToMarkdown.csproj b/HtmlToMarkdown.csproj deleted file mode 100644 index dcb8cc5..0000000 --- a/HtmlToMarkdown.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - Template - 1.0 - HtmlToMarkdown - PowerShell binary module - Brian Lalonde - A template for creating a binary module for PowerShell. - dotnet-new;templates;powershell - netstandard2.0 - - true - false - content - - - - - - - - - diff --git a/HtmlToMarkdown.sln b/HtmlToMarkdown.sln deleted file mode 100644 index 857e482..0000000 --- a/HtmlToMarkdown.sln +++ /dev/null @@ -1,40 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 -MinimumVisualStudioVersion = 15.0.26124.0 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{75E8ACE7-9BE5-477B-8ECC-D13E4B6D0018}" -EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "HtmlToMarkdown", "src\HtmlToMarkdown\HtmlToMarkdown.fsproj", "{177D8365-0F55-48CD-A4BC-FF158A6D9AD5}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Debug|x64.ActiveCfg = Debug|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Debug|x64.Build.0 = Debug|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Debug|x86.ActiveCfg = Debug|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Debug|x86.Build.0 = Debug|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Release|Any CPU.Build.0 = Release|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Release|x64.ActiveCfg = Release|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Release|x64.Build.0 = Release|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Release|x86.ActiveCfg = Release|Any CPU - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {177D8365-0F55-48CD-A4BC-FF158A6D9AD5} = {75E8ACE7-9BE5-477B-8ECC-D13E4B6D0018} - EndGlobalSection -EndGlobal - diff --git a/HtmlToMarkdown.slnx b/HtmlToMarkdown.slnx new file mode 100644 index 0000000..baaaa03 --- /dev/null +++ b/HtmlToMarkdown.slnx @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/docs/Convert-HtmlToMarkdown.md b/docs/Convert-HtmlToMarkdown.md index e14b2de..c81d4ed 100644 --- a/docs/Convert-HtmlToMarkdown.md +++ b/docs/Convert-HtmlToMarkdown.md @@ -16,7 +16,8 @@ Converts HTML to Markdown. Convert-HtmlToMarkdown -Html [-DefaultCodeBlockLanguage ] [-GithubFlavored] [-ListBulletChar ] [-RemoveComments] [-SmartHrefHandling] [-UnknownTags ] [-PassThroughTags ] [-WhitelistUriSchemes ] - [-TableWithoutHeaderRowHandling ] [] + [-TableWithoutHeaderRowHandling ] [-ProgressAction ] + [] ``` ## DESCRIPTION @@ -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). diff --git a/src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs b/src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs index cb42934..2ed3612 100644 --- a/src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs +++ b/src/HtmlToMarkdown/ConvertHtmlToMarkdownCommand.fs @@ -1,92 +1,91 @@ -namespace HtmlToMarkdown - -open System.Management.Automation - -open ReverseMarkdown - -/// Converts HTML to Markdown. -[] -[)>] -[] -type ConvertHtmlToMarkdownCommand () = - inherit PSCmdlet () - - /// HTML to convert. - [] - [] - [] - 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. - [] - [] - [] - member val DefaultCodeBlockLanguage : string = null with get, set - - /// Github style markdown for br, pre and table. - [] - [] - member val GithubFlavored : SwitchParameter = SwitchParameter false with get, set - - /// Sets the bullet character to use for unordered lists. - [] - [] - member val ListBulletChar : char = '-' with get, set - - /// Remove comment tags with text. - [] - [] - 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. - [] - [] - 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. - [] - [] - member val UnknownTags : Config.UnknownTagsOption = Config.UnknownTagsOption.PassThrough with get, set - - /// Pass a list of tags to pass through as-is without any processing. - [] - [] - [] - 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. - [] - [] - 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. - [] - [] - 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. +[] +[)>] +[] +type ConvertHtmlToMarkdownCommand () = + inherit PSCmdlet () + + /// HTML to convert. + [] + [] + [] + 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. + [] + [] + [] + member val DefaultCodeBlockLanguage : string = null with get, set + + /// Github style markdown for br, pre and table. + [] + [] + member val GithubFlavored : SwitchParameter = SwitchParameter false with get, set + + /// Sets the bullet character to use for unordered lists. + [] + [] + member val ListBulletChar : char = '-' with get, set + + /// Remove comment tags with text. + [] + [] + 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. + [] + [] + 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. + [] + [] + member val UnknownTags : Config.UnknownTagsOption = Config.UnknownTagsOption.PassThrough with get, set + + /// Pass a list of tags to pass through as-is without any processing. + [] + [] + [] + 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. + [] + [] + 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. + [] + [] + 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, + GithubFlavored = x.GithubFlavored, + ListBulletChar = x.ListBulletChar, + RemoveComments = x.RemoveComments, + SmartHrefHandling = x.SmartHrefHandling, + UnknownTags = x.UnknownTags, + TableWithoutHeaderRowHandling = x.TableWithoutHeaderRowHandling) + Array.iter (cfg.PassThroughTags.Add >> ignore) x.PassThroughTags + Array.iter (cfg.WhitelistUriSchemes.Add >> ignore) x.WhitelistUriSchemes + 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 () diff --git a/src/HtmlToMarkdown/HtmlToMarkdown.dll-Help.xml b/src/HtmlToMarkdown/HtmlToMarkdown.dll-Help.xml index 2e0b5b0..fc57883 100644 --- a/src/HtmlToMarkdown/HtmlToMarkdown.dll-Help.xml +++ b/src/HtmlToMarkdown/HtmlToMarkdown.dll-Help.xml @@ -142,6 +142,18 @@ None + + ProgressAction + + {{ Fill ProgressAction Description }} + + ActionPreference + + ActionPreference + + + None + @@ -265,6 +277,18 @@ None + + ProgressAction + + {{ Fill ProgressAction Description }} + + ActionPreference + + ActionPreference + + + None + @@ -294,7 +318,7 @@ -------------------------- Example 1 -------------------------- - PS C:\> '<h1>On Board</h1><ul><li>Ford<li>Zaphod<li>Marvin</ul>' |Convert-HtmlToMarkdown + '<h1>On Board</h1><ul><li>Ford<li>Zaphod<li>Marvin</ul>' |Convert-HtmlToMarkdown # On Board @@ -305,6 +329,18 @@ + + -------------------------- Example 2 -------------------------- + 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&tab=wi) +3. [Maps](https://maps.google.com/maps?hl=en&tab=wl) +... + + + + diff --git a/src/HtmlToMarkdown/HtmlToMarkdown.fsproj b/src/HtmlToMarkdown/HtmlToMarkdown.fsproj index 8efd9ec..a6600be 100644 --- a/src/HtmlToMarkdown/HtmlToMarkdown.fsproj +++ b/src/HtmlToMarkdown/HtmlToMarkdown.fsproj @@ -1,55 +1,51 @@ - - - - netstandard2.0 - true - true - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + net10.0 + true + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/HtmlToMarkdown/HtmlToMarkdown.psd1 b/src/HtmlToMarkdown/HtmlToMarkdown.psd1 index b145d5f..26df98a 100644 --- a/src/HtmlToMarkdown/HtmlToMarkdown.psd1 +++ b/src/HtmlToMarkdown/HtmlToMarkdown.psd1 @@ -1,39 +1,39 @@ -# see https://docs.microsoft.com/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest -# and https://docs.microsoft.com/powershell/module/microsoft.powershell.core/new-modulemanifest -@{ -RootModule = 'HtmlToMarkdown.dll' -ModuleVersion = '1.1.5' -CompatiblePSEditions = @('Core','Desktop') -GUID = 'b9799ff4-2f34-4787-8e26-5f6f4db55e60' -Author = 'Brian Lalonde' -# CompanyName = 'Unknown' -Copyright = '(c) Brian Lalonde. All rights reserved.' -Description = 'Converts HTML to Markdown/CommonMark.' -PowerShellVersion = '5.1' -FunctionsToExport = @() -CmdletsToExport = @( - 'Convert-HtmlToMarkdown' -) -VariablesToExport = @() -AliasesToExport = @() -FileList = @( - 'HtmlToMarkdown.dll' - 'HtmlToMarkdown.dll-Help.xml' -) -PrivateData = @{ - PSData = @{ - Tags = @( - 'Markdown' - 'CommonMark' - 'HTML' - 'Windows' - 'Linux' - 'macOS' - ) - LicenseUri = 'https://github.com/brianary/HtmlToMarkdown/LICENSE' - ProjectUri = 'https://github.com/brianary/HtmlToMarkdown/' - IconUri = 'http://webcoder.info/images/HtmlToMarkdown.svg' - # ReleaseNotes = '' - } -} -} +# see https://docs.microsoft.com/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest +# and https://docs.microsoft.com/powershell/module/microsoft.powershell.core/new-modulemanifest +@{ +RootModule = 'HtmlToMarkdown.dll' +ModuleVersion = '1.2.0' +CompatiblePSEditions = @('Core','Desktop') +GUID = 'b9799ff4-2f34-4787-8e26-5f6f4db55e60' +Author = 'Brian Lalonde' +# CompanyName = 'Unknown' +Copyright = '(c) Brian Lalonde. All rights reserved.' +Description = 'Converts HTML to Markdown/CommonMark.' +PowerShellVersion = '7.3' +FunctionsToExport = @() +CmdletsToExport = @( + 'Convert-HtmlToMarkdown' +) +VariablesToExport = @() +AliasesToExport = @() +FileList = @( + 'HtmlToMarkdown.dll' + 'HtmlToMarkdown.dll-Help.xml' +) +PrivateData = @{ + PSData = @{ + Tags = @( + 'Markdown' + 'CommonMark' + 'HTML' + 'Windows' + 'Linux' + 'macOS' + ) + LicenseUri = 'https://github.com/brianary/HtmlToMarkdown/LICENSE' + ProjectUri = 'https://github.com/brianary/HtmlToMarkdown/' + IconUri = 'http://webcoder.info/images/HtmlToMarkdown.svg' + # ReleaseNotes = '' + } +} +}