From 95de8eb141bb474dd1e483c94676b1fb02b3718b Mon Sep 17 00:00:00 2001 From: mark <> Date: Thu, 7 May 2026 22:07:37 +0200 Subject: [PATCH] feat: add @ and ! to inline formatting --- example.mharkup | 2 ++ src/doc.rs | 6 +++++- src/main.rs | 2 +- src/parse.rs | 10 +++++++++- src/to/html.rs | 19 ++++++++++++++++++- src/to/plain.rs | 12 ++++++++++++ 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/example.mharkup b/example.mharkup index 9b15b36..43b4ab2 100644 --- a/example.mharkup +++ b/example.mharkup @@ -96,6 +96,8 @@ here's a list of things the backtick can do: ` highlight a `_(special) element: ``_(special) ` add emphasis to `+(something): ``+(something) ` highlight something `*(important): ``*(important) +` mark a non-word or name, like `@(mharkup): ``@(mharkup) +` use monospace for `!(code): ``!(code) ` insert raw `{`text`}: `<`{`text`}>: `2{`<`{`text`}>}}: `2<`2{`<`{`text`}>}}>>: ... ` link `/here(somewhere): ``/here(somewhere) ` use an extension: ``\spec{...} or ``\spec<...> diff --git a/src/doc.rs b/src/doc.rs index c517dd2..952262a 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -28,6 +28,8 @@ pub enum Component<'a> { Special(Text<'a>), Emphasis(Text<'a>), Important(Text<'a>), + Name(Text<'a>), + Code(Text<'a>), Link(&'a str, Text<'a>), Ext(&'a str, &'a str), } @@ -46,7 +48,9 @@ impl<'a> Component<'a> { | Component::Wrong(t) | Component::Special(t) | Component::Emphasis(t) - | Component::Important(t) => t.is_empty(), + | Component::Important(t) + | Component::Name(t) + | Component::Code(t) => t.is_empty(), Component::Link(target, t) => target.is_empty() && t.is_empty(), Component::Ext(_, _) => false, } diff --git a/src/main.rs b/src/main.rs index 15d53df..228bd81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ fn main() { eprintln!("Usage: .mharkup [specs...]"); eprintln!("output formats and (available specs)"); eprintln!("` html: a static html+css document (html, texm)"); - eprintln!("` html-http: html with auto-refresh"); + eprintln!("` html-http: html with auto-refresh (same as html)"); return; } let specs = &args[2..]; diff --git a/src/parse.rs b/src/parse.rs index 2c8ae11..0811209 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -234,6 +234,12 @@ pub fn parse_text_impl<'a>( '*' if opt.is_empty() => { inner = Ok(text(inner, Component::Important)); } + '@' if opt.is_empty() => { + inner = Ok(text(inner, Component::Name)); + } + '!' if opt.is_empty() => { + inner = Ok(text(inner, Component::Code)); + } '/' if !opt.is_empty() => { inner = Ok(text(inner, |v| Component::Link(opt, v))); } @@ -250,7 +256,9 @@ pub fn parse_text_impl<'a>( | Component::Wrong(text) | Component::Special(text) | Component::Emphasis(text) - | Component::Important(text) => inner = &mut text.0[0], + | Component::Important(text) + | Component::Name(text) + | Component::Code(text) => inner = &mut text.0[0], Component::Char(_) | Component::Ext(_, _) => { unreachable!() } diff --git a/src/to/html.rs b/src/to/html.rs index 09f0937..46acb1e 100644 --- a/src/to/html.rs +++ b/src/to/html.rs @@ -40,7 +40,7 @@ pub fn page_to<'a>( {} @@ -425,6 +432,16 @@ fn text_to<'a: 'b, 'b>( text_to(text, specs, out, args); out.push_str(""); } + Component::Name(text) => { + out.push_str(r#""#); + text_to(text, specs, out, args); + out.push_str(""); + } + Component::Code(text) => { + out.push_str(r#"
"#);
+                text_to(text, specs, out, args);
+                out.push_str("
"); + } Component::Link(target, text) => { let link_target: Option<&'a Document<'a>> = args .max_len diff --git a/src/to/plain.rs b/src/to/plain.rs index 9dfa1c2..ac9defb 100644 --- a/src/to/plain.rs +++ b/src/to/plain.rs @@ -66,6 +66,18 @@ fn text_to(text: &Text<'_>, complete: bool, specs: &[impl Spec], out: &mut Strin out.push('*'); } } + Component::Name(text) => { + text_to(text, complete, specs, out); + } + Component::Code(text) => { + if complete { + out.push('`'); + } + text_to(text, complete, specs, out); + if complete { + out.push('`'); + } + } Component::Link(target, text) => { if complete { out.push('_');