improve docs and readability

This commit is contained in:
dre 2021-07-11 17:12:57 +08:00
parent 5541aef0ca
commit 5c435c28b9
4 changed files with 10 additions and 4 deletions

View file

@ -1,9 +1,9 @@
# md2gmi
Convert Markdown to Gemini [gemtext](https://gemini.circumlunar.space/docs/gemtext.gmi) markup with
Convert Markdown to Gemini [gemtext](https://gemini.circumlunar.space/docs/gemtext.gmi) gemtext with
Go. Working with streams and pipes for UNIX like behavior utilizing Go channels. Processing streams
line by line is slightly more complex than it needs to be as I was toying with channels and state
machines.
line by line is probably slightly more complex than it needs to be as I was toying with channels and
state machines.
Internally md2gmi does a 1st pass that constructs the blocks of single lines for gemtext from one or
multiple lines of an input stream. These blocks are then streamed to the 2nd passes. The 2nd pass

View file

@ -10,7 +10,6 @@ import (
func FormatLinks(in chan pipe.StreamItem) chan pipe.StreamItem {
out := make(chan pipe.StreamItem)
go func() {
for b := range in {

View file

@ -57,6 +57,7 @@ func wrap(m *fsm, data []byte) (*fsm, []byte) {
if scount = countStart(data, "<!--"); scount > 0 {
m.multiLineBlockMode += scount
}
if ecount = countEnd(data, "-->"); ecount > 0 {
m.multiLineBlockMode -= ecount
}
@ -76,6 +77,7 @@ func wrap(m *fsm, data []byte) (*fsm, []byte) {
if ecount = countEnd(data, "-->"); ecount > 0 {
data = data[bytes.LastIndex(data, []byte("-->"))+3:]
}
return m, data
}
@ -100,6 +102,7 @@ func (m *fsm) softBlockFlush() {
if m.multiLineBlockMode > 0 {
return
}
m.blockFlush()
}
@ -123,6 +126,7 @@ func triggerBreak(data []byte) bool {
if len(data) == 0 || len(data) == 1 && data[0] == '\n' {
return true
}
switch data[len(data)-1] {
case '.':
fallthrough
@ -131,6 +135,7 @@ func triggerBreak(data []byte) bool {
case ':':
return true
}
return false
}
@ -192,6 +197,7 @@ func normalText(m *fsm, data []byte) stateFn {
m.blockBuffer = append(m.blockBuffer, append(data, '\n')...)
m.softBlockFlush()
return normal
}

View file

@ -29,6 +29,7 @@ func newItem(ctx context.Context, index int, payload []byte) StreamItem {
payload: make([]byte, len(payload)),
}
copy(s.payload, payload)
return s
}