From 4e3cfc7fec8a0b515f60167bed6cdb22a9710b71 Mon Sep 17 00:00:00 2001 From: Artemy Egorov Date: Wed, 14 Aug 2024 10:02:39 +0300 Subject: [PATCH] fix: text tag syntax, table escaping, body parsing --- examples/daleth.dlth | 25 +++++++++++++------------ src/daleth/custom_parsers/mod.rs | 14 ++++++++++++-- src/daleth/format.rs | 4 +++- src/daleth/lexer/mod.rs | 4 ++-- src/daleth/parser/mod.rs | 2 +- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/examples/daleth.dlth b/examples/daleth.dlth index f30af78..96e7b47 100644 --- a/examples/daleth.dlth +++ b/examples/daleth.dlth @@ -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 ] ]] diff --git a/src/daleth/custom_parsers/mod.rs b/src/daleth/custom_parsers/mod.rs index c7c094f..c3098bb 100644 --- a/src/daleth/custom_parsers/mod.rs +++ b/src/daleth/custom_parsers/mod.rs @@ -18,12 +18,22 @@ pub fn table_to_tag(rows: &Vec) -> 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(), ), }) diff --git a/src/daleth/format.rs b/src/daleth/format.rs index 98f9d4a..b7acb9b 100644 --- a/src/daleth/format.rs +++ b/src/daleth/format.rs @@ -104,7 +104,9 @@ pub fn format<'src>(spanned_tokens: &Vec>>) -> 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), diff --git a/src/daleth/lexer/mod.rs b/src/daleth/lexer/mod.rs index dba40ed..202c3fc 100644 --- a/src/daleth/lexer/mod.rs +++ b/src/daleth/lexer/mod.rs @@ -122,8 +122,8 @@ fn textual<'src>() -> impl Parser<'src, &'src str, Token<'src>, extra::Err( .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! {