From e748e1eff3b3fa94a08d2defd3a47ca00549e35c Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Wed, 14 Oct 2020 16:09:49 +0200 Subject: [PATCH] Fix smart annotations and links styling --- app/services/reports/docx/draw_experiment.rb | 3 ++- app/services/reports/docx/draw_my_module.rb | 3 ++- app/services/reports/docx/draw_result_comments.rb | 3 ++- app/services/reports/docx/draw_result_text.rb | 3 ++- app/services/reports/docx/draw_step.rb | 3 ++- app/services/reports/docx/draw_step_comments.rb | 3 ++- app/services/reports/html_to_word_converter.rb | 7 ++++--- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/services/reports/docx/draw_experiment.rb b/app/services/reports/docx/draw_experiment.rb index e43a08e97..b1aa74350 100644 --- a/app/services/reports/docx/draw_experiment.rb +++ b/app/services/reports/docx/draw_experiment.rb @@ -22,7 +22,8 @@ module Reports::Docx::DrawExperiment link_style end html = custom_auto_link(experiment.description, team: @report_team) - Reports::HtmlToWordConverter.new(@docx).html_to_word_converter(html) + Reports::HtmlToWordConverter.new(@docx, { scinote_url: scinote_url, + link_style: link_style }).html_to_word_converter(html) @docx.p subject['children'].each do |child| public_send("draw_#{child['type_of']}", child, experiment) diff --git a/app/services/reports/docx/draw_my_module.rb b/app/services/reports/docx/draw_my_module.rb index 0cd9d512f..c18b2896b 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -66,7 +66,8 @@ module Reports::Docx::DrawMyModule if my_module.description.present? html = custom_auto_link(my_module.description, team: @report_team) - Reports::HtmlToWordConverter.new(@docx).html_to_word_converter(html) + Reports::HtmlToWordConverter.new(@docx, { scinote_url: scinote_url, + link_style: link_style }).html_to_word_converter(html) else @docx.p I18n.t('projects.reports.elements.module.no_description') end diff --git a/app/services/reports/docx/draw_result_comments.rb b/app/services/reports/docx/draw_result_comments.rb index 67ddfee62..101290b24 100644 --- a/app/services/reports/docx/draw_result_comments.rb +++ b/app/services/reports/docx/draw_result_comments.rb @@ -17,7 +17,8 @@ module Reports::Docx::DrawResultComments date: I18n.l(comment_ts, format: :full_date), time: I18n.l(comment_ts, format: :time)), italic: true html = custom_auto_link(comment.message, team: @report_team) - Reports::HtmlToWordConverter.new(@docx).html_to_word_converter(html) + Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, + link_style: @link_style }).html_to_word_converter(html) @docx.p end end diff --git a/app/services/reports/docx/draw_result_text.rb b/app/services/reports/docx/draw_result_text.rb index 5ecc27158..33abb9867 100644 --- a/app/services/reports/docx/draw_result_text.rb +++ b/app/services/reports/docx/draw_result_text.rb @@ -17,7 +17,8 @@ module Reports::Docx::DrawResultText timestamp: I18n.l(timestamp, format: :full), user: result.user.full_name), color: color[:gray] end html = custom_auto_link(result_text.text, team: @report_team) - Reports::HtmlToWordConverter.new(@docx).html_to_word_converter(html) + Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, + link_style: @link_style }).html_to_word_converter(html) subject['children'].each do |child| public_send("draw_#{child['type_of']}", child, result) diff --git a/app/services/reports/docx/draw_step.rb b/app/services/reports/docx/draw_step.rb index 0bd9e924e..87ac65c7a 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -27,7 +27,8 @@ module Reports::Docx::DrawStep end if step.description.present? html = custom_auto_link(step.description, team: @report_team) - Reports::HtmlToWordConverter.new(@docx).html_to_word_converter(html) + Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, + link_style: @link_style }).html_to_word_converter(html) else @docx.p I18n.t 'projects.reports.elements.step.no_description' end diff --git a/app/services/reports/docx/draw_step_comments.rb b/app/services/reports/docx/draw_step_comments.rb index 12e5ed5ff..40bee154d 100644 --- a/app/services/reports/docx/draw_step_comments.rb +++ b/app/services/reports/docx/draw_step_comments.rb @@ -17,7 +17,8 @@ module Reports::Docx::DrawStepComments date: I18n.l(comment_ts, format: :full_date), time: I18n.l(comment_ts, format: :time)), italic: true html = custom_auto_link(comment.message, team: @report_team) - Reports::HtmlToWordConverter.new(@docx).html_to_word_converter(html) + Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, + link_style: @link_style }).html_to_word_converter(html) @docx.p end end diff --git a/app/services/reports/html_to_word_converter.rb b/app/services/reports/html_to_word_converter.rb index 8c0a43268..b5fa20d35 100644 --- a/app/services/reports/html_to_word_converter.rb +++ b/app/services/reports/html_to_word_converter.rb @@ -2,13 +2,15 @@ module Reports class HtmlToWordConverter - def initialize(document) + def initialize(document, options = {}) @docx = document + @scinote_url = options[:scinote_url] + @link_style = options[:link_style] end def html_to_word_converter(text) html = Nokogiri::HTML(text) - raw_elements = recursive_children(html.css('body').children, []) + raw_elements = recursive_children(html.css('body').children, []).compact # Combined raw text blocks in paragraphs elements = combine_docx_elements(raw_elements) @@ -106,7 +108,6 @@ module Reports elements.push(list_element(elem)) next end - elements = recursive_children(elem.children, elements) if elem.children end elements