redef fun add_image(v, link, name, comment) do
v.add "<img src=\""
append_value(v, link)
v.add "\" alt=\""
append_value(v, name)
v.add "\""
if comment != null and not comment.is_empty then
v.add " title=\""
append_value(v, comment)
v.add "\""
end
v.add "/>"
end
lib/markdown/markdown.nit:812,2--824,4
redef fun add_image(v, link, name, comment)
do
# Keep absolute links as is
if link.has_prefix("http://") or link.has_prefix("https://") then
super
return
end
do
# Get the directory of the doc object to deal with the relative link
var mdoc = current_mdoc
if mdoc == null then break
var source = mdoc.location.file
if source == null then break
var path = source.filename
var stat = path.file_stat
if stat == null then break
if not stat.is_dir then path = path.dirname
# Get the full path to the local resource
var fulllink = path / link.to_s
stat = fulllink.file_stat
if stat == null then break
# Get a collision-free catalog name for the resource
var hash = fulllink.md5
var ext = fulllink.file_extension
if ext != null then hash = hash + "." + ext
# Copy the local resource in the resource directory of the catalog
var res = catalog.outdir / "res" / hash
fulllink.file_copy_to(res)
# Hijack the link in the html.
link = ".." / "res" / hash
super(v, link, name, comment)
return
end
# Something went bad
catalog.modelbuilder.toolcontext.error(current_mdoc.location, "Error: cannot find local image `{link}`")
super
end
src/nitcatalog.nit:136,2--178,4