Skip to content

Commit

Permalink
add @url
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 24, 2020
1 parent 6b3efa6 commit e4b13d4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/CrossReferences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ end
# -------------------------------------

const NAMED_XREF = r"^@ref (.+)$"
const URL_XREF = r"^@url (.+)\/(.+)$"

function xref(link::Markdown.Link, meta, page, doc)
link.url == "@ref" ? basicxref(link, meta, page, doc) :
occursin(NAMED_XREF, link.url) ? namedxref(link, meta, page, doc) : nothing
occursin(URL_XREF, link.url) ? urlxref(link, meta, page, doc) : nothing
return false # Stop `walk`ing down this `link` element.
end
xref(other, meta, page, doc) = true # Continue to `walk` through element `other`.
Expand Down Expand Up @@ -223,4 +225,15 @@ function issue_xref(link::Markdown.Link, num, meta, page, doc)
"https://github.com/$(doc.internal.remote)/issues/$num"
end

# Cross link.
# -----------------------------
function urlxref(link::Markdown.Link, meta, page, doc)
baseurls_dict = meta[:URLs]
m = match(r"@url (.+)\/(.+)", link.url)
key = m.captures[1]
base_url = baseurls_dict[key]
rest_url = m.captures[2]
link.url = "$base_url/$rest_url"
end

end

0 comments on commit e4b13d4

Please sign in to comment.