From adde673fa62f139172dcf2053e2bfb77290bdf82 Mon Sep 17 00:00:00 2001 From: dre Date: Sun, 4 Jul 2021 15:22:55 +0800 Subject: [PATCH] account for images and expand readme --- README.md | 21 +++++++++++++++++++-- proc.go | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3166c0b..50fb332 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ spec](https://gemini.circumlunar.space/docs/specification.gmi). Internally md2gmi does a 1st pass that constructs the core layout for gemtext. This is then streamed to the 2nd pass line by line. The 2nd pass will convert links and stream line by line to the output. -###Usage +### Usage ```plain Usage of ./md2gmi: @@ -27,4 +27,21 @@ Usage of ./md2gmi: go get github.com/n0x1m/md2gmi cat file.md | md2gmi - md2gmi -in file.md -out file.gmi \ No newline at end of file + md2gmi -in file.md -out file.gmi + +The top part of this readme parses to + +```md +## md2gmi + +Convert Markdown to Gemini gemtext[1] markup with Go. Working with streams and pipes for UNIX like behavior utilizing Go channels. Processing streams line by line is deliberately slightly more challenging than it needs to be to play around with go state machines. + +=> https://gemini.circumlunar.space/docs/gemtext.gmi 1: gemtext + + See the gemini protocol[1] and the protocol spec[2]. + +=> https://gemini.circumlunar.space/ 1: gemini protocol +=> https://gemini.circumlunar.space/docs/specification.gmi 2: protocol spec + +Internally md2gmi does a 1st pass that constructs the core layout for gemtext. This is then streamed to the 2nd pass line by line. The 2nd pass will convert links and stream line by line to the output. +``` \ No newline at end of file diff --git a/proc.go b/proc.go index 5d19773..2e4f809 100644 --- a/proc.go +++ b/proc.go @@ -29,7 +29,7 @@ func (m *proc) Process(in chan []byte) chan []byte { func (m *proc) process(data []byte) []byte { // find link name and url var buffer []byte - re := regexp.MustCompile(`\[([^\]*]*)\]\(([^)]*)\)`) + re := regexp.MustCompile(`!?\[([^\]*]*)\]\(([^)]*)\)`) for i, match := range re.FindAllSubmatch(data, -1) { replaceWithIndex := append(match[1], fmt.Sprintf("[%d]", i+1)...) data = bytes.Replace(data, match[0], replaceWithIndex, 1)