feat: add @ and ! to inline formatting
This commit is contained in:
@@ -96,6 +96,8 @@ here's a list of things the backtick can do:
|
|||||||
` highlight a `_(special) element: ``_(special)
|
` highlight a `_(special) element: ``_(special)
|
||||||
` add emphasis to `+(something): ``+(something)
|
` add emphasis to `+(something): ``+(something)
|
||||||
` highlight something `*(important): ``*(important)
|
` 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`}>}}>>: ...
|
` insert raw `{`text`}: `<`{`text`}>: `2{`<`{`text`}>}}: `2<`2{`<`{`text`}>}}>>: ...
|
||||||
` link `/here(somewhere): ``/here(somewhere)
|
` link `/here(somewhere): ``/here(somewhere)
|
||||||
` use an extension: ``\spec{...} or ``\spec<...>
|
` use an extension: ``\spec{...} or ``\spec<...>
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ pub enum Component<'a> {
|
|||||||
Special(Text<'a>),
|
Special(Text<'a>),
|
||||||
Emphasis(Text<'a>),
|
Emphasis(Text<'a>),
|
||||||
Important(Text<'a>),
|
Important(Text<'a>),
|
||||||
|
Name(Text<'a>),
|
||||||
|
Code(Text<'a>),
|
||||||
Link(&'a str, Text<'a>),
|
Link(&'a str, Text<'a>),
|
||||||
Ext(&'a str, &'a str),
|
Ext(&'a str, &'a str),
|
||||||
}
|
}
|
||||||
@@ -46,7 +48,9 @@ impl<'a> Component<'a> {
|
|||||||
| Component::Wrong(t)
|
| Component::Wrong(t)
|
||||||
| Component::Special(t)
|
| Component::Special(t)
|
||||||
| Component::Emphasis(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::Link(target, t) => target.is_empty() && t.is_empty(),
|
||||||
Component::Ext(_, _) => false,
|
Component::Ext(_, _) => false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ fn main() {
|
|||||||
eprintln!("Usage: <filename>.mharkup <format> [specs...]");
|
eprintln!("Usage: <filename>.mharkup <format> [specs...]");
|
||||||
eprintln!("output formats and (available specs)");
|
eprintln!("output formats and (available specs)");
|
||||||
eprintln!("` html: a static html+css document (html, texm)");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
let specs = &args[2..];
|
let specs = &args[2..];
|
||||||
|
|||||||
10
src/parse.rs
10
src/parse.rs
@@ -234,6 +234,12 @@ pub fn parse_text_impl<'a>(
|
|||||||
'*' if opt.is_empty() => {
|
'*' if opt.is_empty() => {
|
||||||
inner = Ok(text(inner, Component::Important));
|
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() => {
|
'/' if !opt.is_empty() => {
|
||||||
inner = Ok(text(inner, |v| Component::Link(opt, v)));
|
inner = Ok(text(inner, |v| Component::Link(opt, v)));
|
||||||
}
|
}
|
||||||
@@ -250,7 +256,9 @@ pub fn parse_text_impl<'a>(
|
|||||||
| Component::Wrong(text)
|
| Component::Wrong(text)
|
||||||
| Component::Special(text)
|
| Component::Special(text)
|
||||||
| Component::Emphasis(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(_, _) => {
|
Component::Char(_) | Component::Ext(_, _) => {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ pub fn page_to<'a>(
|
|||||||
<style>
|
<style>
|
||||||
@media (prefers-color-scheme: light) {{ :root {{ --bg: #FFF; --bg2: #FFF4F4; --fg: #000; }} }}
|
@media (prefers-color-scheme: light) {{ :root {{ --bg: #FFF; --bg2: #FFF4F4; --fg: #000; }} }}
|
||||||
@media (prefers-color-scheme: dark) {{ :root {{ --bg: #070002; --bg2: #070010; --fg: #E0B8A0; }} }}
|
@media (prefers-color-scheme: dark) {{ :root {{ --bg: #070002; --bg2: #070010; --fg: #E0B8A0; }} }}
|
||||||
:root {{ color: var(--fg); background: var(--bg);
|
:root {{ color: var(--fg); background: var(--bg); font-family: sans-serif;
|
||||||
--fgl: color-mix(var(--fg), var(--bg) 50%); --fgd: color-mix(var(--fg), var(--bg) 65%); --fgt: color-mix(var(--fg), var(--bg) 80%);
|
--fgl: color-mix(var(--fg), var(--bg) 50%); --fgd: color-mix(var(--fg), var(--bg) 65%); --fgt: color-mix(var(--fg), var(--bg) 80%);
|
||||||
--fsmall: 66%; --fless: 77%; --fmore: 110%; --ftitle: 132%; }}
|
--fsmall: 66%; --fless: 77%; --fmore: 110%; --ftitle: 132%; }}
|
||||||
/*
|
/*
|
||||||
@@ -192,6 +192,13 @@ pub fn page_to<'a>(
|
|||||||
.note, .lnref {{
|
.note, .lnref {{
|
||||||
font-size: var(--fsmall);
|
font-size: var(--fsmall);
|
||||||
}}
|
}}
|
||||||
|
.tname {{
|
||||||
|
font-family: serif;
|
||||||
|
font-style: oblique 3deg;
|
||||||
|
}}
|
||||||
|
.tcode {{
|
||||||
|
display: inline;
|
||||||
|
}}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
{}
|
{}
|
||||||
@@ -425,6 +432,16 @@ fn text_to<'a: 'b, 'b>(
|
|||||||
text_to(text, specs, out, args);
|
text_to(text, specs, out, args);
|
||||||
out.push_str("</strong>");
|
out.push_str("</strong>");
|
||||||
}
|
}
|
||||||
|
Component::Name(text) => {
|
||||||
|
out.push_str(r#"<span class="tname">"#);
|
||||||
|
text_to(text, specs, out, args);
|
||||||
|
out.push_str("</span>");
|
||||||
|
}
|
||||||
|
Component::Code(text) => {
|
||||||
|
out.push_str(r#"<pre class="tcode">"#);
|
||||||
|
text_to(text, specs, out, args);
|
||||||
|
out.push_str("</pre>");
|
||||||
|
}
|
||||||
Component::Link(target, text) => {
|
Component::Link(target, text) => {
|
||||||
let link_target: Option<&'a Document<'a>> = args
|
let link_target: Option<&'a Document<'a>> = args
|
||||||
.max_len
|
.max_len
|
||||||
|
|||||||
@@ -66,6 +66,18 @@ fn text_to(text: &Text<'_>, complete: bool, specs: &[impl Spec], out: &mut Strin
|
|||||||
out.push('*');
|
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) => {
|
Component::Link(target, text) => {
|
||||||
if complete {
|
if complete {
|
||||||
out.push('_');
|
out.push('_');
|
||||||
|
|||||||
Reference in New Issue
Block a user