diff --git a/README.md b/README.md index cfb2a79..f6496df 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/mdproc/links.go b/mdproc/links.go index 53c45fe..10f3d7d 100644 --- a/mdproc/links.go +++ b/mdproc/links.go @@ -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 { diff --git a/mdproc/preproc.go b/mdproc/preproc.go index 179e69e..1d1a1a5 100644 --- a/mdproc/preproc.go +++ b/mdproc/preproc.go @@ -57,6 +57,7 @@ func wrap(m *fsm, data []byte) (*fsm, []byte) { if scount = countStart(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 } diff --git a/pipe/streamitem.go b/pipe/streamitem.go index a9ed5fa..d8f7d70 100644 --- a/pipe/streamitem.go +++ b/pipe/streamitem.go @@ -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 }