Adds spacing to gemini docs to normalize the formatting with gopher docs #188

Merged
sloum merged 8 commits from gemini-gutter into release2.3.3 2020-11-01 14:10:04 +00:00
7 changed files with 16 additions and 5 deletions
Showing only changes of commit 01d071e510 - Show all commits

BIN
.client.go.swp Normal file

Binary file not shown.

BIN
.page.go.swp Normal file

Binary file not shown.

BIN
.url.go.swp Normal file

Binary file not shown.

View File

@ -977,6 +977,7 @@ func (c *client) handleGemini(u Url) {
case 2:
// Success
if capsule.MimeMaj == "text" || (c.Options["showimages"] == "true" && capsule.MimeMaj == "image") {
u.Mime = capsule.MimeMin
pg := MakePage(u, capsule.Content, capsule.Links)
pg.FileType = capsule.MimeMaj
pg.WrapContent(c.Width-1, (c.Options["theme"] == "color"))

BIN
gemini/.gemini.go.swp Normal file

Binary file not shown.

View File

@ -361,6 +361,7 @@ func parseGemini(b, currentUrl string) (string, []string) {
links := make([]string, 0, 10)
inPreBlock := false
spacer := " "
outputIndex := 0
for i, ln := range splitContent {
@ -371,7 +372,7 @@ func parseGemini(b, currentUrl string) (string, []string) {
alt := strings.TrimSpace(ln)
if len(alt) > 3 {
alt = strings.TrimSpace(alt[3:])
splitContent[outputIndex] = fmt.Sprintf("[ %s ]", alt)
splitContent[outputIndex] = fmt.Sprintf("%s[ALT][ %s ]", spacer, alt)
outputIndex++
}
} else if isPreBlockDeclaration {
@ -401,7 +402,12 @@ func parseGemini(b, currentUrl string) (string, []string) {
if inPreBlock && (BlockBehavior == "alt" || BlockBehavior == "neither") {
continue
}
splitContent[outputIndex] = ln
var leader, tail string = "", ""
if len(ln) > 0 && ln[0] == '#' {
leader = "\033[1m"
tail = "\033[0m"
}
splitContent[outputIndex] = fmt.Sprintf("%s%s%s%s", spacer, leader, ln, tail)
outputIndex++
}
}

10
page.go
View File

@ -72,7 +72,8 @@ func (p *Page) WrapContent(width int, color bool) {
}
width = min(width, 100)
counter := 0
spacer := " "
gopherspacer := " "
geminispacer := " "
var content strings.Builder
var esc strings.Builder
escape := false
@ -126,8 +127,11 @@ func (p *Page) WrapContent(width int, color bool) {
content.WriteRune('\n')
counter = 0
if p.Location.Mime == "1" {
Review

Maybe this if and else if block could be changed so we don't run strings.HasSuffix for each line of a document that isn't a gopher map.

The mime type check could be done before the loop in this function, followed by setting the appropriate spacer value for the document type. This block could then become a test of the spacer value itself. A bit like:

func (p *Page) WrapContent(width int, color bool) {
    ...
    spacer := 0
    if p.location.Mime == "1" { //gopher map
        spacer := "           "
    } else if strings.HasSuffix(p.Location.Mime, "gemini") { //gemini document
        spacer := "      "
    }
    ...
    for _, ch := range []rune(p.RawContent) {
        ...
        if spacer > 0 {
            content.WriteString(spacer)
            counter += len(spacer)
        }

I'm not sure if this is easy to understand, so I can make these changes for you to review if it helps.

Maybe this `if` and `else if` block could be changed so we don't run `strings.HasSuffix` for each line of a document that isn't a gopher map. The mime type check could be done before the loop in this function, followed by setting the appropriate spacer value for the document type. This block could then become a test of the spacer value itself. A bit like: ```Go func (p *Page) WrapContent(width int, color bool) { ... spacer := 0 if p.location.Mime == "1" { //gopher map spacer := " " } else if strings.HasSuffix(p.Location.Mime, "gemini") { //gemini document spacer := " " } ... for _, ch := range []rune(p.RawContent) { ... if spacer > 0 { content.WriteString(spacer) counter += len(spacer) } ``` I'm not sure if this is easy to understand, so I can make these changes for you to review if it helps.
Review

Setting the spacer to 0 to start with wont work due to typing issues, but aside from that this is a very practical change. I'll do this. 👍

Setting the spacer to `0` to start with wont work due to typing issues, but aside from that this is a very practical change. I'll do this. :+1:
Review

I have updated to more or less this exact thing and I just always write the spacer for each new with no link inside the for loop, it is just often set to "" and thus has no effect. This is much improved in a very confusing area of the codebase. Thanks for the suggestion!

I have updated to more or less this exact thing and I just always write the spacer for each new with no link inside the for loop, it is just often set to `""` and thus has no effect. This is _much_ improved in a very confusing area of the codebase. Thanks for the suggestion!
content.WriteString(spacer)
counter += len(spacer)
content.WriteString(gopherspacer)
counter += len(gopherspacer)
} else if strings.HasSuffix(p.Location.Mime, "gemini") {
content.WriteString(geminispacer)
counter += len(geminispacer)
}
content.WriteRune(ch)
counter++