Skip to content

Commit

Permalink
move GHToc into separate file; add some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin committed Oct 29, 2023
1 parent e50e5d6 commit 7291b4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ghdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (
"strings"
)

// GHToc GitHub TOC
type GHToc []string

// Print TOC to the console
func (toc *GHToc) Print(w io.Writer) error {
for _, tocItem := range *toc {
Expand Down Expand Up @@ -103,16 +100,21 @@ func (doc *GHDoc) Convert2HTML() error {
doc.d("Convert2HTML: start.")
defer doc.d("Convert2HTML: done.")

// remote file may be of 2 types:
// - raw md file (we need to download it locally and convert t HTML)
// - html file (we need just to load it and parse TOC from it)
if doc.IsRemoteFile() {
htmlBody, ContentType, err := doc.httpGetter(doc.Path)
doc.d("Convert2HTML: remote file. content-type: " + ContentType)
if err != nil {
doc.d("Convert2HTML: err=" + err.Error())
return err
}

// if not a plain text - return the result (should be html)
if strings.Split(ContentType, ";")[0] != "text/plain" {
doc.html = string(htmlBody)
doc.d("Convert2HTML: not a plain text, body" + string(htmlBody)[:200])
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions ghtoc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ghtoc

// GHToc GitHub TOC
type GHToc []string

0 comments on commit 7291b4a

Please sign in to comment.