account for images and expand readme

This commit is contained in:
dre 2021-07-04 15:22:55 +08:00
parent 10ed27bb77
commit adde673fa6
2 changed files with 20 additions and 3 deletions

View file

@ -28,3 +28,20 @@ Usage of ./md2gmi:
go get github.com/n0x1m/md2gmi
cat file.md | md2gmi
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.
```

View file

@ -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)