miki

Miki: personal wiki with the fmd markup format
git clone https://wtenison.com/repo/miki.git
Log | Files | Refs | README | LICENSE

commit d7a479f32ada12f0aa1a61bb6e4e94b3dc6d59de
parent f3251c218f13961bf386c10feffee09ab1be4fa5
Author: weetat <wtenison@protonmail.com>
Date:   Mon,  3 Mar 2025 17:37:12 +0000

Added 'code' operator for HTML code blocks.

Diffstat:
Msrc/fmd/fmd_test.go | 8++++----
Msrc/fmd/interpreter.go | 5++++-
Msrc/fmd/lexer.go | 11++++++-----
Msrc/fmd/parser.go | 9+++++----
4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/fmd/fmd_test.go b/src/fmd/fmd_test.go @@ -6,7 +6,7 @@ import ( ) func TestFMD(t *testing.T) { - _path := ("/home/weetat/projects/miki/data/fmd/home.fmd") + _path := ("/home/weetat/projects/miki/data/README.fmd") t.Log("Path:", _path) // WriteFMDToHTMLFile(_path, "/home/weetat/projects/miki/README.md") @@ -20,9 +20,9 @@ func TestFMD(t *testing.T) { _l := MakeLexer(_input) _tokens := _l.Exec() - for _, _t := range _tokens { - t.Log("Tokens:", _t) - } + // for _, _t := range _tokens { + // t.Log("Tokens:", _t) + // } _p := MakeParser(_tokens) _ast := _p.Exec() diff --git a/src/fmd/interpreter.go b/src/fmd/interpreter.go @@ -6,6 +6,7 @@ import ( ) // TODO: Implment better solution to sanitization. +// TODO: ALternative; move interpreter to client side via Web Assembly. // NOTE: Solution; move sanitization to separate package and let the interpreter work fast, then clean? var invalidHTML = []string{"<script>", "</script>", "<object>", "</object>", "<embed", "<link>", "</link>"} @@ -35,6 +36,8 @@ func interpret(n node) string { return "<h5>" + interpret(n.children[0]) + "</h5>" case "h6": return "<h6>" + interpret(n.children[0]) + "</h6>" + case "code": + return "<code>" + interpret(n.children[0]) + "</code>" case "@": return "<a>" + interpret(n.children[0]) + "</a>" case "img": @@ -62,7 +65,7 @@ func interpret(n node) string { case nSpacing: return n.value case nNewline: - if n.nParent.nType != nNewline { + if n.nPrev.nType != nNewline { return "<br>\n" } else { return "\n" diff --git a/src/fmd/lexer.go b/src/fmd/lexer.go @@ -44,11 +44,12 @@ var keywords = []string{ "b", // bold "i", // italic "h1", "h2", "h3", "h4", "h5", "h6", // header - "@", // link - "#", // tag - "col", // column container - "img", // image - "_", // empty container (<div>) + "code", // code element + "@", // link + "#", // tag + "col", // column container + "img", // image + "_", // empty container (<div>) } type lexer struct { diff --git a/src/fmd/parser.go b/src/fmd/parser.go @@ -27,7 +27,7 @@ const ( type node struct { nType nodeType value string - nParent *node + nPrev *node children []node } @@ -77,7 +77,7 @@ func (p *parser) parseCommand() node { } else if p.isTokenType(tLParen, 0) { _command.children = append(_command.children, p.parseParam()) } else if p.isTokenType(tLBrace, 0) { - _command.children = append(_command.nParent.children, p.parseBlock()) + _command.children = append(_command.nPrev.children, p.parseBlock()) } else { _command.children = append(_command.children, p.makeNode(nWord, p.consume(tWord))) } @@ -90,8 +90,9 @@ func (p *parser) parseParam() node { p.consume(tLParen) + // TODO: Implement parameter parsing. for p.pos < len(p.tokens) && p.peekToken(0).tType != tRParen { - + p.pos += 1 } p.consume(tRParen) @@ -179,7 +180,7 @@ func (p *parser) makeNode(nType nodeType, iToken token) node { _n = p.errorNode(iToken.value) } - _n.nParent = p.nPrev + _n.nPrev = p.nPrev p.nPrev = &_n return _n