diff --git a/gemini.go b/gemini.go index 8cbd6df..858f91a 100644 --- a/gemini.go +++ b/gemini.go @@ -20,8 +20,9 @@ import ( "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/hyphae" - "github.com/bouncepaw/mycorrhiza/markup" "github.com/bouncepaw/mycorrhiza/util" + + "github.com/bouncepaw/mycomarkup/legacy" ) func geminiHomeHypha(w *gemini.ResponseWriter, rq *gemini.Request) { diff --git a/go.mod b/go.mod index 1fde72b..de01040 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( git.sr.ht/~adnano/go-gemini v0.1.13 github.com/adrg/xdg v0.2.2 - github.com/bouncepaw/mycomarkup v0.0.0-20210511092446-956f169b1499 + github.com/bouncepaw/mycomarkup v0.0.0-20210512131946-becfae76473f github.com/go-ini/ini v1.62.0 github.com/gorilla/feeds v1.1.1 github.com/kr/pretty v0.2.1 // indirect diff --git a/go.sum b/go.sum index 785a95f..a6fcdf1 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/bouncepaw/mycomarkup v0.0.0-20210502065108-4ddae294864d h1:H20wX93QMe github.com/bouncepaw/mycomarkup v0.0.0-20210502065108-4ddae294864d/go.mod h1:fx0FBKaCaV1fofgCQOu2lNIVB/5EoDg/83i8BgBdgpc= github.com/bouncepaw/mycomarkup v0.0.0-20210511092446-956f169b1499 h1:RLKVj992QuayqjpIJ7M2csRjfhAnu9EO2r1Bm4D/WlU= github.com/bouncepaw/mycomarkup v0.0.0-20210511092446-956f169b1499/go.mod h1:fx0FBKaCaV1fofgCQOu2lNIVB/5EoDg/83i8BgBdgpc= +github.com/bouncepaw/mycomarkup v0.0.0-20210512131946-becfae76473f h1:PgXG/AqO96jahMGQA81CWclIg90gsGt5kK4o7y0eZy8= +github.com/bouncepaw/mycomarkup v0.0.0-20210512131946-becfae76473f/go.mod h1:4Fz80hsrXi3lRVZuVfIk5+2xocp50CFAbJfGeJWb5aM= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-ini/ini v1.62.0 h1:7VJT/ZXjzqSrvtraFp4ONq80hTcRQth1c9ZnQ3uNQvU= @@ -62,6 +64,7 @@ golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/markup/hr.go b/markup/hr.go deleted file mode 100644 index 278138a..0000000 --- a/markup/hr.go +++ /dev/null @@ -1,34 +0,0 @@ -package markup - -import ( - "unicode" -) - -// MatchesHorizontalLine checks if the string can be interpreted as suitable for rendering as
. -// -// The rule is: if there are more than 4 characters "-" in the string, then make it a horizontal line. -// Otherwise it is a paragraph (

). -func MatchesHorizontalLine(line string) bool { - counter := 0 - - // Check initially that the symbol is "-". If it is not a "-", it is most likely a space or another character. - // With unicode.IsLetter() we can separate spaces and characters. - for _, ch := range line { - if ch == '-' { - counter++ - continue - } - // If we bump into any other character (letter) in the line, it is immediately an incorrect horizontal line. - // There is no point in counting further, we end the loop. - if unicode.IsLetter(ch) { - counter = 0 - break - } - } - - if counter >= 4 { - return true - } - - return false -} diff --git a/markup/img.go b/markup/img.go deleted file mode 100644 index 5c4b51b..0000000 --- a/markup/img.go +++ /dev/null @@ -1,203 +0,0 @@ -package markup - -import ( - "fmt" - "regexp" - "strings" - - "github.com/bouncepaw/mycomarkup/links" -) - -var imgRe = regexp.MustCompile(`^img\s+{`) - -func MatchesImg(line string) bool { - return imgRe.MatchString(line) -} - -type imgState int - -const ( - inRoot imgState = iota - inName - inDimensionsW - inDimensionsH - inDescription -) - -type Img struct { - entries []imgEntry - currEntry imgEntry - hyphaName string - state imgState -} - -func (img *Img) pushEntry() { - if strings.TrimSpace(img.currEntry.path.String()) != "" { - img.currEntry.srclink = links.From(img.currEntry.path.String(), "", img.hyphaName) - // img.currEntry.srclink.DoubtExistence() - img.entries = append(img.entries, img.currEntry) - img.currEntry = imgEntry{} - img.currEntry.path.Reset() - } -} - -func (img *Img) Process(line string) (shouldGoBackToNormal bool) { - stateToProcessor := map[imgState]func(rune) bool{ - inRoot: img.processInRoot, - inName: img.processInName, - inDimensionsW: img.processInDimensionsW, - inDimensionsH: img.processInDimensionsH, - inDescription: img.processInDescription, - } - for _, r := range line { - if shouldReturnTrue := stateToProcessor[img.state](r); shouldReturnTrue { - return true - } - } - return false -} - -func (img *Img) processInDescription(r rune) (shouldReturnTrue bool) { - switch r { - case '}': - img.state = inName - default: - img.currEntry.desc.WriteRune(r) - } - return false -} - -func (img *Img) processInRoot(r rune) (shouldReturnTrue bool) { - switch r { - case '}': - img.pushEntry() - return true - case '\n', '\r': - img.pushEntry() - case ' ', '\t': - default: - img.state = inName - img.currEntry = imgEntry{} - img.currEntry.path.Reset() - img.currEntry.path.WriteRune(r) - } - return false -} - -func (img *Img) processInName(r rune) (shouldReturnTrue bool) { - switch r { - case '}': - img.pushEntry() - return true - case '|': - img.state = inDimensionsW - case '{': - img.state = inDescription - case '\n', '\r': - img.pushEntry() - img.state = inRoot - default: - img.currEntry.path.WriteRune(r) - } - return false -} - -func (img *Img) processInDimensionsW(r rune) (shouldReturnTrue bool) { - switch r { - case '}': - img.pushEntry() - return true - case '*': - img.state = inDimensionsH - case ' ', '\t', '\n': - case '{': - img.state = inDescription - default: - img.currEntry.sizeW.WriteRune(r) - } - return false -} - -func (img *Img) processInDimensionsH(r rune) (shouldGoBackToNormal bool) { - switch r { - case '}': - img.pushEntry() - return true - case ' ', '\t', '\n': - case '{': - img.state = inDescription - default: - img.currEntry.sizeH.WriteRune(r) - } - return false -} - -func ImgFromFirstLine(line, hyphaName string) (img *Img, shouldGoBackToNormal bool) { - img = &Img{ - hyphaName: hyphaName, - entries: make([]imgEntry, 0), - } - line = line[strings.IndexRune(line, '{')+1:] - return img, img.Process(line) -} - -func (img *Img) pagePathFor(path string) string { - path = strings.TrimSpace(path) - if strings.IndexRune(path, ':') != -1 || strings.IndexRune(path, '/') == 0 { - return path - } else { - return "/page/" + xclCanonicalName(img.hyphaName, path) - } -} - -func parseDimensions(dimensions string) (sizeW, sizeH string) { - xIndex := strings.IndexRune(dimensions, '*') - if xIndex == -1 { // If no x in dimensions - sizeW = strings.TrimSpace(dimensions) - } else { - sizeW = strings.TrimSpace(dimensions[:xIndex]) - sizeH = strings.TrimSpace(strings.TrimPrefix(dimensions, dimensions[:xIndex+1])) - } - return -} - -func (img *Img) markExistenceOfSrcLinks() { - HyphaIterate(func(hn string) { - for _, entry := range img.entries { - if hn == entry.srclink.Address() { - entry.srclink.DestinationUnknown = false - } - } - }) -} - -func (img *Img) ToHtml() (html string) { - img.markExistenceOfSrcLinks() - isOneImageOnly := len(img.entries) == 1 && img.entries[0].desc.Len() == 0 - if isOneImageOnly { - html += `