<commit_before>module QaePdfForms::CustomQuestions::Textarea

  LIST_TAGS = ["ul", "ol"]

  MAIN_CONTENT_BLOCKS = ["p"] + LIST_TAGS

  SUPPORTED_TAGS = MAIN_CONTENT_BLOCKS + [
    "li", "a", "em", "strong", "text", "br"
  ]

  def render_wysywyg_content
    if display_wysywyg_q?
      if this_is_wysywyg_content?
        wysywyg_entries.each do |child|
          t_name = wysywyg_get_tag_name(child)

          if MAIN_CONTENT_BLOCKS.include?(t_name)
            render_wysywyg_line(
              {
                "<" + t_name + ">" => {
                  style: wysywyg_get_style(child),
                  content: wysywyg_get_item_content(child)
                }
              }
            )
          end
        end
      else
        form_pdf.render_standart_answer_block(humanized_answer)
      end
    end
  end

  private

  def display_wysywyg_q?
    q_visible? && humanized_answer.present?
  end

  def this_is_wysywyg_content?
    SUPPORTED_TAGS.any? do |tag|
      humanized_answer.include?("<#{tag}>")
    end
  end

  def wysywyg_entries
    Nokogiri::HTML.parse(
      humanized_answer
    ).children[1]
     .children[0]
     .children
  end

  def wysywyg_get_tag_name(tag)
    tag.name
  end

  def render_wysywyg_line(line)
    tag_abbr = line.keys[0]

    if tag_abbr == "<p>"
      lines_style = styles_picker(wysywyg_get_style_values(line).split(", "))
      print_pdf(wysywyg_get_values_content(line).join(""), lines_style)

    elsif wysywyg_list_leading_tag?(tag_abbr)
      wysywyg_print_lists(tag_abbr, line)
    end
  end

  def wysywyg_list_leading_tag?(tag_abbr)
    LIST_TAGS.include?(tag_abbr.gsub(/(\<|\>)/, ""))
  end

  def wysywyg_list_ending_tag?(tag_abbr)
    tag_abbr == "</ul>" || tag_abbr == "</ol>"
  end

  def wysywyg_print_lists(key, line)
    wysywyg_list_content_generator(wysywyg_prepare_list_content(line),<commit_msg>[PDF GENERATION] fixed issue with wrong BR tags<commit_after>module QaePdfForms::CustomQuestions::Textarea

  LIST_TAGS = ["ul", "ol"]

  MAIN_CONTENT_BLOCKS = ["p"] + LIST_TAGS

  SUPPORTED_TAGS = MAIN_CONTENT_BLOCKS + [
    "li", "a", "em", "strong", "text", "br"
  ]

  def render_wysywyg_content
    if display_wysywyg_q?
      if this_is_wysywyg_content?
        wysywyg_entries.each do |child|
          t_name = wysywyg_get_tag_name(child)

          if MAIN_CONTENT_BLOCKS.include?(t_name)
            render_wysywyg_line(
              {
                "<" + t_name + ">" => {
                  style: wysywyg_get_style(child),
                  content: wysywyg_get_item_content(child)
                }
              }
            )
          end
        end
      else
        form_pdf.render_standart_answer_block(humanized_answer)
      end
    end
  end

  private

  def display_wysywyg_q?
    q_visible? && humanized_answer.present?
  end

  def this_is_wysywyg_content?
    SUPPORTED_TAGS.any? do |tag|
      humanized_answer.include?("<#{tag}>")
    end
  end

  def wysywyg_entries
    Nokogiri::HTML.parse(
      humanized_answer
    ).children[1]
     .children[0]
     .children
  end

  def wysywyg_get_tag_name(tag)
    tag.name
  end

  def render_wysywyg_line(line)
    tag_abbr = line.keys[0]

    if tag_abbr == "<p>"
      lines_style = styles_picker(wysywyg_get_style_values(line).split(", "))
      content = wysywyg_get_values_content(line).join("")
      content = content.gsub("<br>", "").gsub("</br>", "")

      print_pdf(content, lines_style)

    elsif wysywyg_list_leading_tag?(tag_abbr)
      wysywyg_print_lists(tag_abbr, line)
    end
  end

  def wysywyg_list_leading_tag?(tag_abbr)
    LIST_TAGS.include?(tag_abbr.gsub(/(\<|\>)/, ""))
  end

  def wysywyg_list_ending_tag?(tag_abbr)
    tag_abbr == "</ul>" || tag_abbr == "</ol>"
  end

  def wysywyg_print_lists(key, line)
    wysywyg_list_content_generator(wysywyg_prepare_list_content(line),
{'fraction_non_alphanumeric': 0.11211807353702745, 'fraction_numerical': 0.0015535991714137752, 'mean_word_length': 2.714423076923077, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7485982', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1501, 'n_words': 211}