fix: text tag syntax, table escaping, body parsing

This commit is contained in:
Artemy Egorov 2024-08-14 10:02:39 +03:00
parent 3438b2a375
commit 4e3cfc7fec
5 changed files with 31 additions and 18 deletions

View file

@ -34,9 +34,9 @@ meta "description": This document describes Daleth syntax and some tags
h1: TxtDot revolution
p: TxtDot is a cool project
# If no tag is specified, then the 'el' tag is placed
# If no tag is specified, but "- text" present, then the 'el' tag is placed
This is element
- This is element
br
# if no tag is specified but a '{- text}' is present, then the 'p' tag is placed
@ -55,7 +55,7 @@ row "center" [
btn "https://example.com/donate" [
# tag without body
img "https://example.com/donate.png"
Donate
- Donate
]
]
@ -63,19 +63,20 @@ row "center" [
row [
# if no tag is specified but a '[[]]' is present, then the 'el' tag
# with multiple tags body placed
[[
h2: Features
ul [
Server-side page simplification
Media proxy
Image compression with Sharp
Rendering client-side apps `Vanilla, React, Vue, etc` with webder
Search with SearXNG
Handy API endpoints
No client JavaScript
Some kind of Material Design 3
Customization with plugins, see @txtdot/sdk and @txtdot/plugins
- Server-side page simplification
- Media proxy
- Image compression with Sharp
- Rendering client-side apps `Vanilla, React, Vue, etc` with webder
- Search with SearXNG
- Handy API endpoints
- No client JavaScript
- Some kind of Material Design 3
- Customization with plugins, see @txtdot/sdk and @txtdot/plugins
]
]]

View file

@ -18,12 +18,22 @@ pub fn table_to_tag(rows: &Vec<TableCol>) -> Tag {
.map(|row| match row {
TableCol::Primary(row) => Tag::Tprow(
row.into_iter()
.map(|t| Tag::El(NNBody::Text(format!("{t}"))))
.map(|t| {
Tag::El(NNBody::Text(format!(
"{}",
t.replace("\\]", "]").replace("\\|", "|")
)))
})
.collect(),
),
TableCol::Secondary(row) => Tag::Trow(
row.into_iter()
.map(|t| Tag::El(NNBody::Text(format!("{t}"))))
.map(|t| {
Tag::El(NNBody::Text(format!(
"{}",
t.replace("\\]", "]").replace("\\|", "|")
)))
})
.collect(),
),
})

View file

@ -104,7 +104,9 @@ pub fn format<'src>(spanned_tokens: &Vec<Spanned<Token<'src>>>) -> String {
Token::MLRText(t) => format!(" {{#{t}}}\n"),
Token::Comment(c) => format!("{}\n", prepend_indent(&format!("#{c}"), current_indent)),
Token::TextTag(t) => format!("{}\n", prepend_indent(t, current_indent)),
Token::TextTag(t) => {
format!("{}\n", prepend_indent(&format!("- {}", t), current_indent))
}
Token::El => prepend_indent("el", current_indent),
Token::H => prepend_indent("h", current_indent),

View file

@ -122,8 +122,8 @@ fn textual<'src>() -> impl Parser<'src, &'src str, Token<'src>, extra::Err<Rich<
.map(Token::TextBody)
.labelled("One line text body");
let text_tag = text
.then_ignore(just('\n'))
let text_tag = just('-')
.ignore_then(text)
.map(Token::TextTag)
.labelled("Text tag");

View file

@ -47,7 +47,7 @@ pub fn tag<'tokens, 'src: 'tokens>(
.map(Body::Text)
.or(tags_body.clone().map(Body::Tags))
.or_not()
.to(Body::Null)
.map(|v| v.unwrap_or(Body::Null))
.labelled("Body");
let num_arg = select! {