diff options
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | design/index.html | 2 | ||||
| -rw-r--r-- | design/log.html | 2 | ||||
| -rw-r--r-- | go.mod | 3 | ||||
| -rw-r--r-- | mardown/lexer.go | 72 |
5 files changed, 81 insertions, 3 deletions
@@ -12,7 +12,6 @@ It aims to be simple, minimalist, brutalist, indie, and personnal. ## How it works Backend written in modern Go. -[gomarkdown/markdown](https://github.com/gomarkdown/markdown) looks like to be a good library. Light CSS, light JS, runs everywhere. SSR first. @@ -29,3 +28,7 @@ This repository contains only the source code of the website, not the contents. Mock-ups are in `design`. Only HTML and raw CSS here. +This project uses a custom markdown parser. +It is located in `markdown`. +I made my custom parser because I have extended its specification. + diff --git a/design/index.html b/design/index.html index 64a8ed5..da598ec 100644 --- a/design/index.html +++ b/design/index.html @@ -58,7 +58,7 @@ </main> <footer> <p>© 2025 - Anhgelus Morhtuuzh</p> - <p>Une citation</p> + <p>« Une citation »</p> <p><a href="">Mentions légales</a></p> </footer> </body> diff --git a/design/log.html b/design/log.html index fd38f9a..709e918 100644 --- a/design/log.html +++ b/design/log.html @@ -88,7 +88,7 @@ func main() { </article> <footer> <p>© 2025 - Anhgelus Morthuuzh</p> - <p>Une citation</p> + <p>« Une citation »</p> <p><a href="">Mentions légales</a></p> </footer> </body> @@ -0,0 +1,3 @@ +module git.anhgelus.world/anhgelus/small-world + +go 1.25.1 diff --git a/mardown/lexer.go b/mardown/lexer.go new file mode 100644 index 0000000..a7b364d --- /dev/null +++ b/mardown/lexer.go @@ -0,0 +1,72 @@ +package mardown + +import "fmt" + +type lexerType string + +const ( + lexerBreak lexerType = "break" + + lexerModifier lexerType = "modifier" + lexerCode lexerType = "code" + lexerHeader lexerType = "header" + lexerQuote lexerType = "quote" + + lexerLiteral lexerType = "literal" +) + +type lexer struct { + Type lexerType + Value string +} + +func (l *lexer) String() string { + return fmt.Sprintf("%s(%s)", l.Type, l.Value) +} + +type lexers struct { + current int + lexers []lexer +} + +func (l *lexers) Next() lexer { + l.current++ + return l.lexers[l.current] +} + +func (l *lexers) Finished() bool { + return l.current+1 >= len(l.lexers) +} + +func lex(s string) *lexers { + lxs := &lexers{current: -1} + var lexs []lexer + var currentType lexerType + var previous string + fn := func(c rune, t lexerType) { + if currentType != t && len(previous) > 0 { + lexs = append(lexs, lexer{Type: currentType, Value: previous}) + previous = "" + } + currentType = t + previous += string(c) + } + for _, c := range []rune(s) { + switch c { + case '*', '_': + fn(c, lexerModifier) + case '`': + fn(c, lexerCode) + case '\n': + fn(c, lexerBreak) + case '#': + fn(c, lexerHeader) + case '>': + fn(c, lexerQuote) + default: + fn(c, lexerLiteral) + } + } + lxs.lexers = lexs + return lxs +} |
