readme.md支持图片相对路径
This commit is contained in:
parent
7f1b95c7d7
commit
fa6f015128
|
@ -48,13 +48,16 @@ module RepositoriesHelper
|
||||||
def readme_render_decode64_content(str, owner, repo, ref, path)
|
def readme_render_decode64_content(str, owner, repo, ref, path)
|
||||||
return nil if str.blank?
|
return nil if str.blank?
|
||||||
begin
|
begin
|
||||||
content = Base64.decode64(str).force_encoding('UTF-8')
|
# content = Base64.decode64(str).force_encoding('UTF-8')
|
||||||
|
content = "# CMSIS-NN cifar10 example\n<img src=\"../5.jpg\"/><img src='../4.jpg'/>(https://github.com/ARM-software)/**[ML-examples](https://github.com/ARM-software/ML-examples)**] and can be deployed on Arm Cortex-M CPUs using [CMSIS-NN](https://github.com/ARM-software/CMSIS_5).\n\n## Requirements:\n- CMSIS-NN in Framework/knowing/cmsis_5\n- TJpgDec in Framework/knowing/image_processing\n- Enough stack size (recommend 10240) for finsh thread which can be changed in \"RT-Thread Components->Command shell->finsh shell\" by menuconfig.\n\n## To run this demo:\n- Place the photo where you want\n- Run demo by type the command\n ``` \n cmsisnn_demo /path/to/photo"
|
||||||
|
|
||||||
c_regex = /\!\[.*?\]\((.*?)\)/
|
c_regex = /\!\[.*?\]\((.*?)\)/
|
||||||
src_regex = /src=\"(.*?)\"/
|
src_regex = /src=\"(.*?)\"/
|
||||||
|
src2_regex = /src='(.*?)'/
|
||||||
ss = content.to_s.scan(c_regex)
|
ss = content.to_s.scan(c_regex)
|
||||||
ss_src = content.to_s.gsub("'","\"").scan(src_regex)
|
ss_src = content.scan(src_regex)
|
||||||
total_images = ss + ss_src
|
ss_src2 = content.scan(src2_regex)
|
||||||
|
total_images = ss + ss_src + ss_src2
|
||||||
if total_images.length > 0
|
if total_images.length > 0
|
||||||
total_images.each do |s|
|
total_images.each do |s|
|
||||||
image_title = /\"(.*?)\"/
|
image_title = /\"(.*?)\"/
|
||||||
|
@ -70,7 +73,7 @@ module RepositoriesHelper
|
||||||
relative_path_length = r_content.split("../").size - 1
|
relative_path_length = r_content.split("../").size - 1
|
||||||
path_pre = path.split("/").size - 1 - relative_path_length
|
path_pre = path.split("/").size - 1 - relative_path_length
|
||||||
path_pre = 0 if path_pre < 0
|
path_pre = 0 if path_pre < 0
|
||||||
path_current = path.split("/")[0..path_pre].join("/")
|
path_current = path_pre == 0 ? "" : path.split("/")[0..path_pre].join("/")
|
||||||
path_last = r_content.split("../").last
|
path_last = r_content.split("../").last
|
||||||
elsif r_content.start_with?("/") # 根路径处理
|
elsif r_content.start_with?("/") # 根路径处理
|
||||||
path_last = r_content[1..r_content.size]
|
path_last = r_content[1..r_content.size]
|
||||||
|
@ -88,7 +91,7 @@ module RepositoriesHelper
|
||||||
# new_r_content = "#{path}" + new_r_content
|
# new_r_content = "#{path}" + new_r_content
|
||||||
new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{path_current}/#{path_last}&ref=#{ref}"].join
|
new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{path_current}/#{path_last}&ref=#{ref}"].join
|
||||||
end
|
end
|
||||||
content = content.gsub(/src=\"#{r_content}\"/, "src=\"#{new_r_content}\"")
|
content = content.gsub(/src=\"#{r_content}\"/, "src=\"#{new_r_content}\"").gsub(/src='#{r_content}'/, "src=\"#{new_r_content}\"")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue