Codebase list erlang-asciideck / f2779d1
Ensure explicit line breaks are at end of line Loïc Hoguin 5 years ago
1 changed file(s) with 30 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
360360 -define(IS_WS(C), (C =:= $\s) or (C =:= $\t)).
361361
362362 %% Asciidoc User Guide 10.3
363 line_break(<<C, "+", Rest0/bits>>, _) when ?IS_WS(C) ->
364 %% @todo Rest0 until \r or \n is whitespace.
365 {ok, {line_break, #{}, <<>>, inline}, Rest0}.
363 line_break(<<WS, "+", Rest0/bits>>, _) when ?IS_WS(WS) ->
364 {Eol, Rest} = case while(fun(C) -> (C =/= $\r) andalso (C =/= $\n) end, Rest0) of
365 {Eol0, <<"\r\n", Rest1/bits>>} -> {Eol0, Rest1};
366 {Eol0, <<"\n", Rest1/bits>>} -> {Eol0, Rest1};
367 Tuple -> Tuple
368 end,
369 <<>> = trim(Eol),
370 {ok, {line_break, #{}, <<>>, inline}, Rest}.
371
372 -ifdef(TEST).
373 line_break_test() ->
374 [
375 <<"Plus at the end of the line">>,
376 {line_break, #{}, <<>>, inline},
377 <<"should work">>
378 ] = inline(<<"Plus at the end of the line +\nshould work">>),
379 [
380 <<"Plus at the end of the line ">>,
381 {line_break, #{}, <<>>, inline},
382 <<"should work">>
383 ] = inline(<<"Plus at the end of the line +\nshould work">>),
384 [
385 <<"Plus at the end of the line">>,
386 {line_break, #{}, <<>>, inline},
387 <<"should work">>
388 ] = inline(<<"Plus at the end of the line +\r\nshould work">>),
389 <<"Plus in the middle + should not.">>
390 = inline(<<"Plus in the middle + should not.">>),
391 ok.
392 -endif.