Skip to content

Commit

Permalink
Merge pull request #3207 from DMPRoadmap/bug_3203_error_in_docx_xml_w…
Browse files Browse the repository at this point in the history
…hen-dowloading_plans

Bug #3203 - Fix for download plans docx being malformed if it has
  • Loading branch information
briri authored Aug 30, 2022
2 parents 9a71eb2 + 563b882 commit 08853aa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/controllers/plan_exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 08853aa

Please sign in to comment.