seam

Symbolic-Expressions As Markup.
git clone git://git.knutsen.co/seam
Log | Files | Refs | README | LICENSE

commit 97069af77a3d0be2e4390b0e4e8d90beeec99396
parent b862381d54d9e9f7e7c211dbdbf768f3f48728ce
Author: Demonstrandum <moi@knutsen.co>
Date:   Mon, 22 Jun 2020 06:04:12 +0100

Add ability to strip attributes.

Diffstat:
Msrc/assemble/html.rs | 2+-
Msrc/parse/parser.rs | 9+++++----
Mtest.html | 2+-
Mtest.sex | 2+-
4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/assemble/html.rs b/src/assemble/html.rs @@ -28,7 +28,7 @@ impl Documentise for HTMLFormatter { if self.tree.is_empty() { return String::from(DEFAULT); } - let stripped = parser::strip(&self.tree); + let stripped = parser::strip(&self.tree, true); let mut current_node = stripped.get(0); // Check if <!DOCTYPE html> exists. diff --git a/src/parse/parser.rs b/src/parse/parser.rs @@ -157,18 +157,19 @@ pub fn parse_stream(tokens: tokens::TokenStream) Ok(tree) } -/// Strip any pure whitespace nodes from the tree. -pub fn strip(tree : &ParseTree) -> ParseTree { +/// Strip any pure whitespace (and annotation) nodes from the tree. +pub fn strip(tree : &ParseTree, strip_attributes : bool) -> ParseTree { let mut stripped = tree.to_owned(); stripped.retain(|branch| { match branch { - ParseNode::String(node) => !node.value.trim().is_empty(), + ParseNode::String(node) => !node.value.trim().is_empty(), + ParseNode::Attribute(_) => !strip_attributes, _ => true } }); for branch in stripped.iter_mut() { if let ParseNode::List(ref mut list) = branch { - *list = strip(list); + *list = strip(list, strip_attributes); } } stripped diff --git a/test.html b/test.html @@ -1,6 +1,6 @@ <!-- Generated from symbolic-expressions into HTML. --> <!DOCTYPE html> -<html><head><title>Example HTML Document</title></head> +<html lang="en"><head><title>Example HTML Document</title></head> <body><p id="hello">Hello, World!</p> <p>something something text...</p> <h1>A (big) Header!</h1> diff --git a/test.sex b/test.sex @@ -1,5 +1,5 @@ (!DOCTYPE html) -(html +(html :lang en (head (title Example HTML Document)) (body