@@ -10,8 +10,8 @@ import (
1010 "path/filepath"
1111 "strings"
1212
13- "gitlab.com/golang-commonmark/markdown"
1413 "github.com/pkg/browser"
14+ "gitlab.com/golang-commonmark/markdown"
1515)
1616
1717const appVersion = "1.3.0"
@@ -20,8 +20,11 @@ func main() {
2020 var outfilePtr = flag .String ("o" , "" , "Output filename. (Optional)" )
2121 var versionPtr = flag .Bool ("version" , false , "Prints mdview version." )
2222 var helpPtr = flag .Bool ("help" , false , "Prints mdview help message." )
23+ var barePtr = flag .Bool ("bare" , false , "Bare HTML with no style applied." )
2324 flag .BoolVar (versionPtr , "v" , false , "Prints mdview version." )
2425 flag .BoolVar (helpPtr , "h" , false , "Prints mdview help message." )
26+ flag .BoolVar (barePtr , "b" , false , "Bare HTML with no style applied." )
27+
2528 flag .Parse ()
2629 inputFilename := flag .Arg (0 )
2730
@@ -57,7 +60,11 @@ func main() {
5760 f , err := os .Create (outfilePath )
5861 check (err )
5962 defer f .Close ()
60- _ , err = fmt .Fprintf (f , template , style , title , html )
63+ actualStyle := style
64+ if * barePtr {
65+ actualStyle = ""
66+ }
67+ _ , err = fmt .Fprintf (f , template , actualStyle , title , html )
6168 check (err )
6269 f .Sync ()
6370 err = browser .OpenFile (outfilePath )
@@ -88,7 +95,7 @@ func getTitle(tokens []markdown.Token) string {
8895 if len (tokens ) > 0 {
8996 for i := 0 ; i < len (tokens ); i ++ {
9097 if topLevelHeading , ok := tokens [i ].(* markdown.HeadingOpen ); ok {
91- for j := i + 1 ; j < len (tokens ); j ++ {
98+ for j := i + 1 ; j < len (tokens ); j ++ {
9299 if token , ok := tokens [j ].(* markdown.HeadingClose ); ok && token .Lvl == topLevelHeading .Lvl {
93100 break
94101 }
@@ -117,7 +124,7 @@ func getText(token markdown.Token) string {
117124
118125}
119126
120- const template = "<!DOCTYPE html><html><head><style>%s</style><title>%s</title></head><body class=\" markdown-body\" >%s</body></html>"
127+ const template = "<!DOCTYPE html><html><head><meta http-equiv= \" content-type \" content= \" text/html; charset=utf-8 \" > < style>%s</style><title>%s</title></head><body class=\" markdown-body\" >%s</body></html>"
121128
122129const style = `.markdown-body {box-sizing: border-box;min-width: 200px;max-width:
123130 980px;margin: 0 auto;padding: 45px;} @media (max-width: 767px) {.markdown-body
0 commit comments