mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-21 23:54:17 +02:00
Support fetching markdown from arbitrary HTTP sources
This commit is contained in:
parent
08b62ec55e
commit
08dd80a922
1 changed files with 20 additions and 2 deletions
22
main.go
22
main.go
|
|
@ -5,7 +5,10 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
|
@ -31,11 +34,26 @@ func readerFromArgument(s string) (io.ReadCloser, error) {
|
|||
return os.Stdin, nil
|
||||
}
|
||||
|
||||
if isGitHubURL(s) {
|
||||
resp, err := findGitHubREADME(s)
|
||||
if u, err := url.ParseRequestURI(s); err == nil {
|
||||
if !strings.HasPrefix(u.Scheme, "http") {
|
||||
return nil, fmt.Errorf("%s is not a supported protocol", u.Scheme)
|
||||
}
|
||||
|
||||
if isGitHubURL(s) {
|
||||
resp, err := findGitHubREADME(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
resp, err := http.Get(u.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue