From 35013b0676d54b69afc812b3027d0c421884d996 Mon Sep 17 00:00:00 2001 From: kp2pml30 Date: Sun, 8 Feb 2026 03:33:18 +0900 Subject: [PATCH] feat: add meta tag --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ exe/yamd | 17 +++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/README.md b/README.md index e69de29..fdb4ea4 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,63 @@ +# YAMD + +Indentation-based markup language that compiles to HTML via Ruby codegen. + +## Syntax + +Structure is defined by indentation (tabs). Lines at a given indent level belong to the enclosing directive. + +### Directives (line-start only) + +| Syntax | Description | +|--------|-------------| +| `#% ` | Metadata / Ruby statement. e.g. `#% meta "date", "2025 01 01"` | +| `#! ` | Block wrapper. Evaluates `expr` as a Ruby method call, content is passed as a block. e.g. `#! tag('h1')` | +| `#$ ` | Raw block. Like `#!` but inner lines are passed as a raw string (no YAMD parsing). Used for code blocks. e.g. `#$ code` | +| `#. ` | List item. Must appear inside a `#! list(...)` block | + +### Inline constructs + +| Syntax | Description | +|--------|-------------| +| `` #`...` `` | Inline code | +| `#{expr}` | Ruby expression interpolation (result converted to string) | +| `#(expr)` | Inline math (AsciiMath, rendered to MathML) | +| `#name(args)` | Method call. e.g. `#link("url")` | +| `#name(args)#{ content }#` | Method call with content block. e.g. `#link("url")#{ click here }#` | +| `##` | Escaped literal `#` | +| `}#` | Closes a `#{` content block | + +### Comments + +Lines matching `#` followed by nothing or a space (i.e. `#` or `# ...`) are comments and are skipped. + +### Available renderer methods + +These are defined by `HTMLRenderer` in `exe/yamd`: + +| Method | Usage | +|--------|-------| +| `tag(name, **attrs)` | HTML element. `#! tag('h2')` | +| `list(numbering)` | List. numbering: `"-"` (ul), `"1"`, `"a"`, `"A"`, `"i"`, `"I"` (ol). Dot-separated for nested: `"-.1"` | +| `link(url)` | Anchor tag. `#link("https://example.com")#{ text }#` | +| `code(lang: Lang::DEFAULT)` | Code block (used via `#$`). Optional `lang:` for highlighting rules | +| `meta(name, value)` | HTML `` tag. Used via `#%` | +| `inline_code(text)` | Inline ``. Used via `` #`...` `` | +| `inline_math(text)` | AsciiMath to MathML. Used via `#(...)` | + +### Example + +``` +#% meta "date", "2025 01 01" + +#! tag('h1') + Title + +Paragraph text with #`inline code` and #link("https://example.com")#{ a link }#. + +#! list('-') + #. First item + #. Second item with sub-content + #$ code + x = 1 +``` diff --git a/exe/yamd b/exe/yamd index 6b6b94d..e160705 100755 --- a/exe/yamd +++ b/exe/yamd @@ -91,6 +91,23 @@ class HTMLRenderer < YAMD::Renderer } end + def single_tag(name, **attrs) + @buf << "<#{name}" + attrs.each { |k, v| + @buf << " " + if k.kind_of? Symbol + k = k.to_s + end + @buf << k + @buf << "=" << v.dump + } + @buf << "/>" + end + + def meta(name, value) + single_tag('meta', name: name, content: value) + end + def tag(name, **attrs) @buf << "<#{name}" attrs.each { |k, v|