aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-09-30 16:35:46 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-09-30 16:35:46 +0200
commit34d16f28f2d85bc1762e65a73d426de4ac8c30ed (patch)
tree86c7d574aaafe68895cc39e322d461133262082c
parent802bcb5d2c815f89f5651adbe63707599f1d443f (diff)
feat(markdown): simple lexer
-rw-r--r--README.md5
-rw-r--r--design/index.html2
-rw-r--r--design/log.html2
-rw-r--r--go.mod3
-rw-r--r--mardown/lexer.go72
5 files changed, 81 insertions, 3 deletions
diff --git a/README.md b/README.md
index 32fe710..1eddd2b 100644
--- a/README.md
+++ b/README.md
@@ -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>&copy; 2025 - Anhgelus Morhtuuzh</p>
- <p>Une citation</p>
+ <p>«&thinsp;Une citation&thinsp;»</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>&copy; 2025 - Anhgelus Morthuuzh</p>
- <p>Une citation</p>
+ <p>«&thinsp;Une citation&thinsp;»</p>
<p><a href="">Mentions légales</a></p>
</footer>
</body>
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..37b3f25
--- /dev/null
+++ b/go.mod
@@ -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
+}