Fix line wrapping (#180)

* Fix line wrapping

* Don't chop from tail

* Test wrapping unicode
pull/185/merge
Matti Pastell 2019-02-26 00:09:40 +02:00 committed by GitHub
parent cb791e8b69
commit 7587b4f9cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -317,12 +317,12 @@ function wraplines(text, line_width=75)
end
function wrapline(text, line_width=75)
result = ""
result = ""
while length(text) > line_width
result*= text[1:line_width] * "\n"
text = text[(line_width+1):end]
result*= first(text, line_width) * "\n"
text = chop(text, head=line_width, tail=0)
end
result *= text
result *= text
end
function latex(io::IO, tex::Markdown.LaTeX)

View File

@ -80,3 +80,17 @@ and some text
"""
@test htext.content[1].content == h_ref
# Test wrapping
cows = repeat("🐄", 100)
testcows = """
🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄
🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄"""
wcows = Weave.wrapline(cows)
@test wcows == testcows
@test length(split(wcows, "\n")[1]) == 75
@test length(split(wcows, "\n")[2]) == 25