Skip to content
This repository has been archived by the owner on May 3, 2020. It is now read-only.

Improve hyperlinks handling #500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions helpers/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,22 @@ def find_headers_footers(docx)
def updateHyperlinks(xmlText)
retHash = {}
# Find urls
urls = xmlText.scan(/<w:t>{{.*}}<\/w:t>/)
urls = xmlText.scan(/<w:t.*>{{.*}}<\/w:t>/)
# Resources for <Resources> tag
retHash['urls'] = []
retHash['id'] = []
i = 25
urls.each do |url|
cleanUrl = url.gsub('{{', '').gsub('}}', '').tr(' ', '_')
cleanUrl = url.gsub('{{', '').gsub('}}', '').tr(' ', '%20')
# set resourceId and xmlText
resourceId = "r:id=\"rId#{i}\""
p_id = "d#{rand(36**7).to_s(36)}"
resourceId = "r:id=\"rId#{p_id}\""
xmlText = xmlText.gsub(url, "<w:hyperlink #{resourceId} w:history=\"1\"><w:r w:rsidRPr=\"00720130\"><w:rPr><w:rStyle w:val=\"Hyperlink\"/></w:rPr>#{cleanUrl}</w:r></w:hyperlink>")
# remove tags
cleanUrl = cleanUrl.gsub('<w:t>', '')
cleanUrl = cleanUrl.gsub(/<w:t.*?>/, '')
cleanUrl = cleanUrl.gsub("<\/w:t>", '')
# put urls in resources
retHash['urls'].push(cleanUrl)
retHash['id'].push("rId#{i}")
i += 1
retHash['id'].push("rId#{p_id}")
end
retHash['xmlText'] = xmlText
retHash
Expand Down
2 changes: 1 addition & 1 deletion views/report_edit.haml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
%label.col-md-3{ :for => "report_name" }
Title
%td{ :style => "width: 70%" }
%input#report_name{ :type => "text", :style => "width: 90%", :name => "report_name", :value => "#{@report.report_name}" }
%input#report_name{ :type => "text", :style => "width: 90%", :name => "report_name", :value => "#{CGI.unescapeHTML(@report.report_name)}" }
%tr
%td{ :style => "width: 30%" }
%label.col-md-3{ :for => "assessment_type" }
Expand Down