<commit_before>use v6;

#-------------------------------------------------------------------------------
unit package SxmlLib:auth<github:MARTIMM>;

use SemiXML::StringList;
use SemiXML::Text;
use SxmlLib::SxmlHelper;
use XML;

#-------------------------------------------------------------------------------
# Core module with common used methods
class Css {

  #-----------------------------------------------------------------------------
  method style (
    XML::Element $parent, Hash $attrs, XML::Node :$content-body
    --> XML::Node
  ) {

    # put everything into a style variable to prevent any escape substitutions
#`{{
    my XML::Element $var = append-element(
      $parent, 'sxml:variable', {name => 'style'}
    );
    my XML::Element $style = append-element( $var, 'style', :text("\n"));
    append-element( $parent, 'sxml:style');
}}
    my XML::Element $style = append-element( $parent, 'style', :text("\n"));

    drop-parent-container($content-body);
#note "\nContent0 $content-body";
    subst-variables($content-body);
#note "\nContent1 $content-body";

    self!css-blocks( $style, $content-body, '', ? ($attrs<compress>//0).Int);

#note "Result css\n", '-' x 80, "\n$style\n", '-' x 80;

    $parent
  }

  #-----------------------------------------------------------------------------
  method !css-blocks (
    XML::Element $style, XML::Element $css-block, Str $parent-select,
    Bool $compress
  ) {

    my Bool $is-block =
            (($css-block ~~ XML::Element) and ($css-block.attribs<s>:exists));
    my Str $css-body = '';

    # build current selector
    my Str $select = '';

    if $is-block {
      $select = [~] $parent-select,
                    (?$parent-select ?? ' ' !! ''),
                    $css-block.attribs<s>;
    }

    # do the textual parts first, then process rest
    for $css-block.nodes -> $node {
      if $node ~~ any(XML::Text, SemiXML::Text) {
        $css-body ~= $node.Str;
      }
    }

    # if the css body is not a string of only spaces, add it to the style
    if $is-block and $css-body !~~ m/^ \s* $/ {
note "Body: $css-body";

      $css-body ~~ s:g/ \s\s+ / /;
      $css-body ~~ s:g/ \n / /;
      if $compress {
        $css-body = "$select \{$css-body}\n";
      }<commit_msg>removed comment and css test is checked<commit_after>use v6;

#-------------------------------------------------------------------------------
unit package SxmlLib:auth<github:MARTIMM>;

use SemiXML::StringList;
use SemiXML::Text;
use SxmlLib::SxmlHelper;
use XML;

#-------------------------------------------------------------------------------
# Core module with common used methods
class Css {

  #-----------------------------------------------------------------------------
  method style (
    XML::Element $parent, Hash $attrs, XML::Node :$content-body
    --> XML::Node
  ) {

    # put everything into a style variable to prevent any escape substitutions
#`{{
    my XML::Element $var = append-element(
      $parent, 'sxml:variable', {name => 'style'}
    );
    my XML::Element $style = append-element( $var, 'style', :text("\n"));
    append-element( $parent, 'sxml:style');
}}
    my XML::Element $style = append-element( $parent, 'style', :text("\n"));

    drop-parent-container($content-body);
#note "\nContent0 $content-body";
    subst-variables($content-body);
#note "\nContent1 $content-body";

    self!css-blocks( $style, $content-body, '', ? ($attrs<compress>//0).Int);

#note "Result css\n", '-' x 80, "\n$style\n", '-' x 80;

    $parent
  }

  #-----------------------------------------------------------------------------
  method !css-blocks (
    XML::Element $style, XML::Element $css-block, Str $parent-select,
    Bool $compress
  ) {

    my Bool $is-block =
            (($css-block ~~ XML::Element) and ($css-block.attribs<s>:exists));
    my Str $css-body = '';

    # build current selector
    my Str $select = '';

    if $is-block {
      $select = [~] $parent-select,
                    (?$parent-select ?? ' ' !! ''),
                    $css-block.attribs<s>;
    }

    # do the textual parts first, then process rest
    for $css-block.nodes -> $node {
      if $node ~~ any(XML::Text, SemiXML::Text) {
        $css-body ~= $node.Str;
      }
    }

    # if the css body is not a string of only spaces, add it to the style
    if $is-block and $css-body !~~ m/^ \s* $/ {
#note "Body: $css-body";

      $css-body ~~ s:g/ \s\s+ / /;
      $css-body ~~ s:g/ \n / /;
      if $compress {
        $css-body = "$select \{$css-body}\n";
      }
{'fraction_non_alphanumeric': 0.2963696369636964, 'fraction_numerical': 0.0035203520352035203, 'mean_word_length': 1.6353623188405797, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3055822', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1357, 'n_words': 350}