Handle siblings and add warning

This commit is contained in:
Ev Bogdanov 2018-01-20 21:45:26 +03:00
parent e5b40a3f7c
commit 3b1863798e

29
bin/em
View file

@ -1,5 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
## This script is not ready for prime time yet...
perl -ne ' perl -ne '
BEGIN { BEGIN {
my @SELF_CLOSING_TAGS = qw( my @SELF_CLOSING_TAGS = qw(
@ -121,27 +123,32 @@ BEGIN {
sub process_input { sub process_input {
my $input = shift; my $input = shift;
my $newline = "";
if ($input =~ /\n/) {
$newline = "\n";
}
chomp $input;
my ($whitespace) = $input =~ /^(\s*)/;
$input =~ s/^\s*//;
my $output; my $output;
if ($input eq "!") { if ($input eq "!") {
$output = build_html; $output = build_html;
} }
elsif ($input =~ /^[a-z0-9-_.]+\+/i) {
my @siblings = split /\+/, $input;
for my $s (@siblings) {
$output .= process_input($s);
}
}
else { else {
my $tag = get_tag $input; my $tag = get_tag $input;
my $content = get_content $input; my $content = get_content $input;
my @classes = get_classes $input; my @classes = get_classes $input;
$output = build_element $tag, $content, @classes; $output = build_element $tag, $content, @classes;
} }
return "$whitespace$output$newline"; return $output;
} }
} }
print process_input $_; my $newline = "";
$newline = "\n" if /\n/;
chomp;
my ($whitespace) = $_ =~ /^(\s*)/;
s/^\s*//;
my $output = process_input $_;
print "$whitespace$output$newline";
' "$@" ' "$@"