add html format, handle lazy loading images

This commit is contained in:
lapwat
2022-08-09 18:21:18 +02:00
parent 97e7d7a5bb
commit d73ae0a73b
8 changed files with 137 additions and 19 deletions

View File

@@ -43,7 +43,7 @@ func init() {
getCmd.PersistentFlags().StringVarP(&getOpts.name, "name", "n", "", "book name (default: page title)")
getCmd.PersistentFlags().StringVarP(&getOpts.author, "author", "a", "", "book author")
getCmd.PersistentFlags().StringVarP(&getOpts.Format, "format", "f", "md", "file format [md, epub, mobi]")
getCmd.PersistentFlags().StringVarP(&getOpts.Format, "format", "f", "md", "file format [md, html, epub, mobi]")
getCmd.PersistentFlags().StringVarP(&getOpts.output, "output", "", "", "file name (default: book name)")
getCmd.PersistentFlags().BoolVarP(&getOpts.stdout, "stdout", "", false, "print to standard output")
getCmd.PersistentFlags().BoolVarP(&getOpts.images, "images", "", false, "retrieve images only")
@@ -74,6 +74,7 @@ var getCmd = &cobra.Command{
formatEnum := map[string]bool{
"md": true,
"html": true,
"epub": true,
"mobi": true,
}
@@ -178,6 +179,21 @@ var getCmd = &cobra.Command{
}
}
if getOpts.Format == "html" {
filename := book.ToHtml(c, getOpts.output)
if getOpts.stdout {
bytesRead, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(bytesRead))
} else {
fmt.Printf("Html saved to \"%s\"\n", filename)
}
}
if getOpts.Format == "epub" {
filename := book.ToEpub(c, getOpts.output)

View File

@@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of papeer",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("papeer v0.5.5")
fmt.Println("papeer v0.5.6")
},
}