Fix smart annotations and links styling

This commit is contained in:
Urban Rotnik 2020-10-14 16:09:49 +02:00
parent a19e0ef846
commit e748e1eff3
7 changed files with 16 additions and 9 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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