diff options
author | Loïc Hoguin <[email protected]> | 2018-06-27 11:06:44 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-06-27 11:25:03 +0200 |
commit | f2779d1fd0f2bf62fb06d19d578c392c3f6845d5 (patch) | |
tree | b4d478a8282c3c304c8e8740fa57e9e2095ea019 | |
parent | a272d0070e46d9be41aee6ce0b7143ca83d11027 (diff) | |
download | asciideck-f2779d1fd0f2bf62fb06d19d578c392c3f6845d5.tar.gz asciideck-f2779d1fd0f2bf62fb06d19d578c392c3f6845d5.tar.bz2 asciideck-f2779d1fd0f2bf62fb06d19d578c392c3f6845d5.zip |
Ensure explicit line breaks are at end of line
-rw-r--r-- | src/asciideck_inline_pass.erl | 33 |
1 files 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(<<C, "+", Rest0/bits>>, _) when ?IS_WS(C) -> - %% @todo Rest0 until \r or \n is whitespace. - {ok, {line_break, #{}, <<>>, inline}, Rest0}. +line_break(<<WS, "+", Rest0/bits>>, _) 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. |