From 7291b4a92863af167f31f5441c77803b7269e3b8 Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Sun, 29 Oct 2023 18:10:20 +0300 Subject: [PATCH] move GHToc into separate file; add some logging --- ghdoc.go | 8 +++++--- ghtoc.go | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 ghtoc.go diff --git a/ghdoc.go b/ghdoc.go index 0ce5a50..eb0faa3 100644 --- a/ghdoc.go +++ b/ghdoc.go @@ -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 { @@ -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 } diff --git a/ghtoc.go b/ghtoc.go new file mode 100644 index 0000000..1f0ebb5 --- /dev/null +++ b/ghtoc.go @@ -0,0 +1,4 @@ +package ghtoc + +// GHToc GitHub TOC +type GHToc []string