From f2779d1fd0f2bf62fb06d19d578c392c3f6845d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 27 Jun 2018 11:06:44 +0200 Subject: Ensure explicit line breaks are at end of line --- src/asciideck_inline_pass.erl | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/asciideck_inline_pass.erl b/src/asciideck_inline_pass.erl index e14f31e..d190641 100644 --- a/src/asciideck_inline_pass.erl +++ b/src/asciideck_inline_pass.erl @@ -361,6 +361,33 @@ inline_literal_passthrough_test() -> -define(IS_WS(C), (C =:= $\s) or (C =:= $\t)). %% Asciidoc User Guide 10.3 -line_break(<>, _) when ?IS_WS(C) -> - %% @todo Rest0 until \r or \n is whitespace. - {ok, {line_break, #{}, <<>>, inline}, Rest0}. +line_break(<>, _) when ?IS_WS(WS) -> + {Eol, Rest} = case while(fun(C) -> (C =/= $\r) andalso (C =/= $\n) end, Rest0) of + {Eol0, <<"\r\n", Rest1/bits>>} -> {Eol0, Rest1}; + {Eol0, <<"\n", Rest1/bits>>} -> {Eol0, Rest1}; + Tuple -> Tuple + end, + <<>> = trim(Eol), + {ok, {line_break, #{}, <<>>, inline}, Rest}. + +-ifdef(TEST). +line_break_test() -> + [ + <<"Plus at the end of the line">>, + {line_break, #{}, <<>>, inline}, + <<"should work">> + ] = inline(<<"Plus at the end of the line +\nshould work">>), + [ + <<"Plus at the end of the line ">>, + {line_break, #{}, <<>>, inline}, + <<"should work">> + ] = inline(<<"Plus at the end of the line +\nshould work">>), + [ + <<"Plus at the end of the line">>, + {line_break, #{}, <<>>, inline}, + <<"should work">> + ] = inline(<<"Plus at the end of the line +\r\nshould work">>), + <<"Plus in the middle + should not.">> + = inline(<<"Plus in the middle + should not.">>), + ok. +-endif. -- cgit v1.2.3