Skip to content

Commit

Permalink
Merge pull request #624 from fredrikekre/fe/deprecations
Browse files Browse the repository at this point in the history
fix some deprecations
  • Loading branch information
mortenpi authored Jan 17, 2018
2 parents 40e12fa + b9e881f commit 5593b8f
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 68 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
Compat 0.41.0
Compat 0.46.0
DocStringExtensions 0.2
3 changes: 2 additions & 1 deletion docs/src/man/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ Code blocks may have some content that does not need to be displayed in the fina

````markdown
```@example
srand(1) # hide
using Documenter # hide
Documenter.Random.srand(1) # hide
A = rand(3, 3)
b = [1, 2, 3]
A \ b
Expand Down
10 changes: 5 additions & 5 deletions src/CrossReferences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ end
const NAMED_XREF = r"^@ref (.+)$"

function xref(link::Markdown.Link, meta, page, doc)
link.url == "@ref" ? basicxref(link, meta, page, doc) :
ismatch(NAMED_XREF, link.url) ? namedxref(link, meta, page, doc) : nothing
link.url == "@ref" ? basicxref(link, meta, page, doc) :
contains(link.url, NAMED_XREF) ? namedxref(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 All @@ -54,7 +54,7 @@ function basicxref(link::Markdown.Link, meta, page, doc)
elseif isa(link.text, Vector)
# No `name` was provided, since given a `@ref`, so slugify the `.text` instead.
text = strip(sprint(Markdown.plain, Markdown.Paragraph(link.text)))
if ismatch(r"#[0-9]+", text)
if contains(text, r"#[0-9]+")
issue_xref(link, lstrip(text, '#'), meta, page, doc)
else
name = Utilities.slugify(text)
Expand Down Expand Up @@ -119,9 +119,9 @@ function docsxref(link::Markdown.Link, code, meta, page, doc)
ex = QuoteNode(keyword)
else
try
ex = parse(code)
ex = Meta.parse(code)
catch err
!isa(err, ParseError) && rethrow(err)
!isa(err, Meta.ParseError) && rethrow(err)
push!(doc.internal.errors, :cross_references)
Utilities.warn(page.source, "Unable to parse the reference '[`$code`](@ref)'.")
return
Expand Down
40 changes: 20 additions & 20 deletions src/DocChecks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ function doctest(block::Markdown.Code, meta::Dict, doc::Documents.Document, page
newmod
end
# Normalise line endings.
code = replace(block.code, "\r\n", "\n")
code = replace(block.code, "\r\n" => "\n")
if haskey(meta, :DocTestSetup)
expr = meta[:DocTestSetup]
Meta.isexpr(expr, :block) && (expr.head = :toplevel)
eval(sandbox, expr)
end
if ismatch(r"^julia> "m, code)
if contains(code, r"^julia> "m)
eval_repl(code, sandbox, meta, doc, page)
block.language = "julia-repl"
elseif ismatch(r"^# output$"m, code)
elseif contains(code, r"^# output$"m)
eval_script(code, sandbox, meta, doc, page)
block.language = "julia"
else
Expand Down Expand Up @@ -230,7 +230,7 @@ function filter_doctests(strings::NTuple{2, AbstractString},
local_filters == nothing && local_filters == []
for r in [doc.user.doctestfilters; local_filters]
if all(ismatch.(r, strings))
strings = replace.(strings, r, "")
strings = replace.(strings, r => "")
end
end
return strings
Expand All @@ -245,10 +245,10 @@ function checkresult(sandbox::Module, result::Result, meta::Dict, doc::Documents
# To avoid dealing with path/line number issues in backtraces we use `[...]` to
# mark ignored output from an error message. Only the text prior to it is used to
# test for doctest success/failure.
head = replace(split(result.output, "\n[...]"; limit = 2)[1], mod_regex, "")
head = replace(head, mod_regex_nodot, "Main")
str = replace(error_to_string(result.stdout, result.value, result.bt), mod_regex, "")
str = replace(str, mod_regex_nodot, "Main")
head = replace(split(result.output, "\n[...]"; limit = 2)[1], mod_regex => "")
head = replace(head, mod_regex_nodot => "Main")
str = replace(error_to_string(result.stdout, result.value, result.bt), mod_regex => "")
str = replace(str, mod_regex_nodot => "Main")

str, head = filter_doctests((str, head), doc, meta)
# Since checking for the prefix of an error won't catch the empty case we need
Expand All @@ -258,10 +258,10 @@ function checkresult(sandbox::Module, result::Result, meta::Dict, doc::Documents
end
else
value = result.hide ? nothing : result.value # `;` hides output.
output = replace(strip(sanitise(IOBuffer(result.output))), mod_regex, "")
str = replace(result_to_string(result.stdout, value), mod_regex, "")
output = replace(strip(sanitise(IOBuffer(result.output))), mod_regex => "")
str = replace(result_to_string(result.stdout, value), mod_regex => "")
# Replace a standalone module name with `Main`.
str = strip(replace(str, mod_regex_nodot, "Main"))
str = strip(replace(str, mod_regex_nodot => "Main"))
str, output = filter_doctests((str, output), doc, meta)
str == output || report(result, str, doc)
end
Expand Down Expand Up @@ -289,7 +289,7 @@ function error_to_string(buf, er, bt)
# Print a REPL-like error message.
disable_color() do
print(buf, "ERROR: ")
showerror(buf, er, index == 0 ? bt : bt[1:(index - 1)])
showerror(buf, er, (index != nothing && index > 0) ? bt[1:(index - 1)] : bt)
end
sanitise(buf)
end
Expand Down Expand Up @@ -337,7 +337,7 @@ end
# Remove terminal colors.

const TERM_COLOR_REGEX = r"\e\[[0-9;]*m"
remove_term_colors(s) = replace(s, TERM_COLOR_REGEX, "")
remove_term_colors(s) = replace(s, TERM_COLOR_REGEX => "")

# REPL doctest splitter.

Expand All @@ -351,12 +351,12 @@ function repl_splitter(code)
output = String[]
buffer = IOBuffer()
while !isempty(lines)
line = shift!(lines)
line = popfirst!(lines)
# REPL code blocks may contain leading lines with comments. Drop them.
# TODO: handle multiline comments?
# ANON_FUNC_DECLARATION deals with `x->x` -> `#1 (generic function ....)` on 0.7
# TODO: Remove this special case and just disallow lines with comments?
startswith(line, '#') && !ismatch(ANON_FUNC_DECLARATION, line) && continue
startswith(line, '#') && !contains(line, ANON_FUNC_DECLARATION) && continue
prompt = match(PROMPT_REGEX, line)
if prompt === nothing
source = match(SOURCE_REGEX, line)
Expand Down Expand Up @@ -384,8 +384,8 @@ end
function takeuntil!(r, buf, lines)
while !isempty(lines)
line = lines[1]
if !ismatch(r, line)
println(buf, shift!(lines))
if !contains(line, r)
println(buf, popfirst!(lines))
else
break
end
Expand Down Expand Up @@ -495,13 +495,13 @@ function linkcheck(link::Base.Markdown.Link, doc::Documents.Document)
return false
end
local STATUS_REGEX = r"^HTTP/1.1 (\d+) (.+)$"m
if ismatch(STATUS_REGEX, result)
if contains(result, STATUS_REGEX)
status = parse(Int, match(STATUS_REGEX, result).captures[1])
if status < 300
print_with_color(:green, INDENT, "$(status) ", link.url, "\n")
elseif status < 400
LOCATION_REGEX = r"^Location: (.+)$"m
if ismatch(LOCATION_REGEX, result)
if contains(result, LOCATION_REGEX)
location = strip(match(LOCATION_REGEX, result).captures[1])
print_with_color(:yellow, INDENT, "$(status) ", link.url, "\n")
print_with_color(:yellow, INDENT, " -> ", location, "\n\n")
Expand All @@ -522,7 +522,7 @@ end
linkcheck(other, doc::Documents.Document) = true

linkcheck_ismatch(r::String, url) = (url == r)
linkcheck_ismatch(r::Regex, url) = ismatch(r, url)
linkcheck_ismatch(r::Regex, url) = contains(url, r)

function disable_color(func)
orig = setcolor!(false)
Expand Down
12 changes: 9 additions & 3 deletions src/Documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module Documenter
using Compat, DocStringExtensions
import Compat.Base64: base64decode, base64encode

@static if VERSION < v"0.7.0-DEV.3406"
import Base.Random
else
import Random
end

# Submodules
# ----------

Expand Down Expand Up @@ -456,7 +462,7 @@ function git_push(
target_dir = abspath(target)

# The upstream URL to which we push new content and the ssh decryption commands.
upstream = "git@$(replace(repo, "github.com/", "github.com:"))"
upstream = "git@$(replace(repo, "github.com/" => "github.com:"))"

write(keyfile, String(base64decode(key)))
chmod(keyfile, 0o600)
Expand Down Expand Up @@ -501,7 +507,7 @@ function git_push(
Writers.HTMLWriter.generate_siteinfo_file(tagged_dir, tag)
# Build a `release-*.*` folder as well when the travis tag is
# valid, which it *should* always be anyway.
if ismatch(Base.VERSION_REGEX, tag)
if contains(tag, Base.VERSION_REGEX)
version = VersionNumber(tag)
release = "release-$(version.major).$(version.minor)"
gitrm_copy(target_dir, joinpath(dirname, release))
Expand Down Expand Up @@ -567,7 +573,7 @@ end

function getenv(regex::Regex)
for (key, value) in ENV
ismatch(regex, key) && return value
contains(key, regex) && return value
end
error("could not find key/iv pair.")
end
Expand Down
6 changes: 3 additions & 3 deletions src/Expanders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ end
# Utilities.
# ----------

iscode(x::Markdown.Code, r::Regex) = ismatch(r, x.language)
iscode(x::Markdown.Code, r::Regex) = contains(x.language, r)
iscode(x::Markdown.Code, lang) = x.language == lang
iscode(x, lang) = false

Expand All @@ -569,7 +569,7 @@ const NAMEDHEADER_REGEX = r"^@id (.+)$"
function namedheader(h::Markdown.Header)
if isa(h.text, Vector) && length(h.text) === 1 && isa(h.text[1], Markdown.Link)
url = h.text[1].url
ismatch(NAMEDHEADER_REGEX, url)
contains(url, NAMEDHEADER_REGEX)
else
false
end
Expand All @@ -579,7 +579,7 @@ end
function droplines(code; skip = 0)
buffer = IOBuffer()
for line in split(code, '\n')[(skip + 1):end]
ismatch(r"^(.*)# hide$", line) && continue
contains(line, r"^(.*)# hide$") && continue
println(buffer, rstrip(line))
end
strip(Utilities.takebuf_str(buffer), '\n')
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/DOM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ string is constructed with the characters escaped. The returned object should
always be treated as an immutable copy and compared using `==` rather than `===`.
"""
function escapehtml(text::AbstractString)
if ismatch(r"[<>&'\"]", text)
if contains(text, r"[<>&'\"]")
buffer = IOBuffer()
for char in text
char === '<' ? write(buffer, "&lt;") :
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/MDFlatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mdflatten(io, link::Link, parent) = mdflatten(io, link.text, link)
mdflatten(io, b::Bold, parent) = mdflatten(io, b.text, b)
mdflatten(io, i::Italic, parent) = mdflatten(io, i.text, i)
mdflatten(io, i::Image, parent) = print(io, "(Image: $(i.alt))")
mdflatten(io, m::LaTeX, parent) = print(io, replace(m.formula, r"[^()+\-*^=\w\s]", ""))
mdflatten(io, m::LaTeX, parent) = print(io, replace(m.formula, r"[^()+\-*^=\w\s]" => ""))
mdflatten(io, ::LineBreak, parent) = print(io, '\n')

# Is both inline and block
Expand Down
28 changes: 14 additions & 14 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ srcpath(source, root, file) = normpath(joinpath(relpath(root, source), file))
Slugify a string into a suitable URL.
"""
function slugify(s::AbstractString)
s = replace(s, r"\s+", "-")
s = replace(s, r"^\d+", "")
s = replace(s, r"&", "-and-")
s = replace(s, r"[^\p{L}\p{P}\d\-]+", "")
s = strip(replace(s, r"\-\-+", "-"), '-')
s = replace(s, r"\s+" => "-")
s = replace(s, r"^\d+" => "")
s = replace(s, r"&" => "-and-")
s = replace(s, r"[^\p{L}\p{P}\d\-]+" => "")
s = strip(replace(s, r"\-\-+" => "-"), '-')
end
slugify(object) = string(object) # Non-string slugifying doesn't do anything.

Expand Down Expand Up @@ -130,7 +130,7 @@ function parseblock(code::AbstractString, doc, page; skip = 0, keywords = true)
(QuoteNode(keyword), cursor + endof(line) + offset)
else
try
parse(code, cursor)
Meta.parse(code, cursor)
catch err
push!(doc.internal.errors, :parse_error)
Utilities.warn(doc, page, "Failed to parse expression.", err)
Expand Down Expand Up @@ -406,13 +406,13 @@ function url(repo, file; commit=nothing)
remote = getremote(dirname(file))
isempty(repo) && (repo = "https://github.com/$remote/blob/{commit}{path}")
# Replace any backslashes in links, if building the docs on Windows
file = replace(file, '\\', '/')
file = replace(file, '\\' => '/')
path = relpath_from_repo_root(file)
if path === nothing
nothing
else
repo = replace(repo, "{commit}", commit === nothing ? repo_commit(file) : commit)
repo = replace(repo, "{path}", string("/", path))
repo = replace(repo, "{commit}" => commit === nothing ? repo_commit(file) : commit)
repo = replace(repo, "{path}" => string("/", path))
repo
end
end
Expand All @@ -429,7 +429,7 @@ function url(remote, repo, mod, file, linerange)
end

# Replace any backslashes in links, if building the docs on Windows
file = replace(file, '\\', '/')
file = replace(file, '\\' => '/')
# Format the line range.
line = format_line(linerange, LineRangeFormatting(repo_host_from_url(repo)))
# Macro-generated methods such as those produced by `@deprecate` list their file as
Expand All @@ -452,9 +452,9 @@ function url(remote, repo, mod, file, linerange)
if path === nothing
nothing
else
repo = replace(repo, "{commit}", repo_commit(file))
repo = replace(repo, "{path}", string("/", path))
repo = replace(repo, "{line}", line)
repo = replace(repo, "{commit}" => repo_commit(file))
repo = replace(repo, "{path}" => string("/", path))
repo = replace(repo, "{line}" => line)
repo
end
end
Expand Down Expand Up @@ -624,7 +624,7 @@ end
Checks whether `url` is an absolute URL (as opposed to a relative one).
"""
isabsurl(url) = ismatch(ABSURL_REGEX, url)
isabsurl(url) = contains(url, ABSURL_REGEX)
const ABSURL_REGEX = r"^[[:alpha:]+-.]+://"

include("DOM.jl")
Expand Down
Loading

0 comments on commit 5593b8f

Please sign in to comment.