From 7587b4f9cfbb3852c77888769ba0155123ad5d3d Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Tue, 26 Feb 2019 00:09:40 +0200 Subject: [PATCH] Fix line wrapping (#180) * Fix line wrapping * Don't chop from tail * Test wrapping unicode --- src/format.jl | 8 ++++---- test/formatter_test.jl | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/format.jl b/src/format.jl index 95b70be..bdcab67 100644 --- a/src/format.jl +++ b/src/format.jl @@ -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) diff --git a/test/formatter_test.jl b/test/formatter_test.jl index 0627987..41e7ae8 100644 --- a/test/formatter_test.jl +++ b/test/formatter_test.jl @@ -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