Created
April 8, 2024 18:35
-
-
Save astrolox/d8cd0af9bae40a1eda2cea79daf8472e to your computer and use it in GitHub Desktop.
Basic HTML to Markdown convertor for CLI use
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
package main | |
import ( | |
"github.com/JohannesKaufmann/html-to-markdown" | |
"io" | |
"log" | |
"os" | |
"strings" | |
) | |
func main() { | |
input, err := io.ReadAll(os.Stdin) | |
if err != nil { | |
return | |
} | |
converter := md.NewConverter("", true, nil) | |
markdown, err := converter.ConvertString(string(input)) | |
fatalIf(err) | |
if !strings.HasSuffix(markdown, "\n") { | |
markdown += "\n" | |
} | |
_, err = os.Stdout.Write([]byte(markdown)) | |
fatalIf(err) | |
} | |
func fatalIf(err error) { | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Author
astrolox
commented
Apr 8, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment