Changeset 26 in code for trunk/zs_ext.go
- Timestamp:
- Aug 30, 2015, 12:42:22 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zs_ext.go
r24 r26 2 2 3 3 import ( 4 "bytes" 5 "os" 4 6 "strconv" 5 7 "strings" … … 7 9 8 10 "github.com/drhodes/golorem" 11 "github.com/google/gxui/math" 12 "github.com/jaytaylor/html2text" 9 13 ) 10 14 … … 71 75 } 72 76 } 77 78 // zs wc <file> -- returns word count in the file (markdown, html or amber) 79 func WordCount(args []string) int { 80 if os.Getenv("ZS_RECURSION") != "" { 81 return 0 82 } 83 if len(args) != 1 { 84 return 0 85 } 86 os.Setenv("ZS_RECURSION", "1") 87 out := &bytes.Buffer{} 88 if err := build(args[0], out, builtins(), globals()); err != nil { 89 return 0 90 } 91 if s, err := html2text.FromString(string(out.Bytes())); err != nil { 92 return 0 93 } else { 94 return len(strings.Fields(s)) 95 } 96 } 97 98 // zs timetoread <file> -- returns number of minutes required to read the text 99 func TimeToRead(args []string) int { 100 wc := WordCount(args) 101 return int(math.Round(float64(wc) / float64(200))) 102 }
Note:
See TracChangeset
for help on using the changeset viewer.