try to convert markdown to gemtext
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f739fe0e6e
commit
58e868de80
3 changed files with 48 additions and 1 deletions
46
formatter.go
46
formatter.go
|
@ -1,12 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/n0x1m/md2gmi/mdproc"
|
||||
"github.com/n0x1m/md2gmi/pipe"
|
||||
)
|
||||
|
||||
func source(r io.Reader) pipe.Source {
|
||||
return func() chan pipe.StreamItem {
|
||||
data := make(chan pipe.StreamItem)
|
||||
s := bufio.NewScanner(r)
|
||||
|
||||
go func() {
|
||||
i := 0
|
||||
|
||||
for s.Scan() {
|
||||
data <- pipe.NewItem(i, s.Bytes())
|
||||
i++
|
||||
}
|
||||
close(data)
|
||||
}()
|
||||
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
func sink(w *bytes.Buffer) pipe.Sink {
|
||||
return func(dest chan pipe.StreamItem) {
|
||||
for b := range dest {
|
||||
_, err := fmt.Fprintf(w, string(b.Payload()))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (fileContent *FileContent) FormatContent() string {
|
||||
content := fileContent.Content
|
||||
badChars := make(map[string]string)
|
||||
|
@ -19,7 +57,13 @@ func (fileContent *FileContent) FormatContent() string {
|
|||
content = strings.ReplaceAll(content, k, v)
|
||||
}
|
||||
|
||||
return content
|
||||
var writer bytes.Buffer
|
||||
s := pipe.New()
|
||||
s.Use(mdproc.Preprocessor())
|
||||
s.Use(mdproc.FormatLinks)
|
||||
s.Handle(source(strings.NewReader(content)), sink(&writer))
|
||||
|
||||
return writer.String()
|
||||
}
|
||||
|
||||
func (file *TreeFile) CategoriesAsUrl() string {
|
||||
|
|
1
go.mod
1
go.mod
|
@ -5,6 +5,7 @@ go 1.18
|
|||
require (
|
||||
git.sr.ht/~adnano/go-gemini v0.2.3
|
||||
github.com/flosch/pongo2/v6 v6.0.0
|
||||
github.com/n0x1m/md2gmi v1.0.0
|
||||
google.golang.org/grpc v1.48.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
|
2
go.sum
2
go.sum
|
@ -51,6 +51,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
|||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/n0x1m/md2gmi v1.0.0 h1:T4FTIjojSutOvyh7okIO7N59sk7KD9XyQMx35JX5jjA=
|
||||
github.com/n0x1m/md2gmi v1.0.0/go.mod h1:q5iY7/I5QlC5bUrqmkXVA2FR2HOB9+PmqDhpCNHF/vc=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
|
|
Loading…
Reference in a new issue