diff --git a/app/controllers/plan_exports_controller.rb b/app/controllers/plan_exports_controller.rb index 46bcbef953..5684fd6521 100644 --- a/app/controllers/plan_exports_controller.rb +++ b/app/controllers/plan_exports_controller.rb @@ -78,8 +78,8 @@ def show_text def show_docx # Using and optional locals_assign export_format render docx: "#{file_name}.docx", - content: render_to_string(partial: 'shared/export/plan', - locals: { export_format: 'docx' }) + content: clean_html_for_docx_creation(render_to_string(partial: 'shared/export/plan', + locals: { export_format: 'docx' })) end def show_pdf @@ -136,4 +136,11 @@ def export_params :custom_sections, :research_outputs, formatting: [:font_face, :font_size, { margin: %i[top right bottom left] }]) end + + # A method to deal with problematic text combinations + # in html that break docx creation by htmltoword gem. + def clean_html_for_docx_creation(html) + # Replaces single backslash \ with \\ with gsub. + html.gsub(/\\/, '\&\&') + end end