anchor.diff:  headerEnd(<<>>, _) ->
       {true, <<>>};
   headerEnd(<<13, 10, Rest/binary>>, _) ->
  +    {true, <<13, 10, Rest/binary>>};
  +headerEnd(<<10, Rest/binary>>, _) ->
       {true, <<13, 10, Rest/binary>>};
   headerEnd(<<$#, Rest/binary>>, start) ->
       headerEnd(Rest, start);
  
positive.code: convert(MDText) when is_list(MDText) ->
      convert(unicode:characters_to_binary(MDText));
  convert(MDText) when is_binary(MDText) ->
      convert(MDText, #{state        => text,
                        currentToken => <<>>,
                        lastLine     => <<>>,
                        html         => <<>>,
                        rest         => <<>>}).
  
  %% Support systems with only \n.
  convert(<<10, Rest/binary>>, State) ->
      convert(<<13, 10, Rest/binary>>, State);
  
  %% Headers
  convert(<<"#", Rest/binary>>, State = #{state := text, currentToken := CT})
      when (CT == <<>>)     or
           (CT == <<" ">>)  or
           (CT == <<"  ">>) or
           (CT == <<"   ">>) ->
      case headerStart(<<"#", Rest/binary>>) of
          {true, Tag, Rest2} ->
              convert(Rest2, State#{state        := Tag,
                                    currentToken :=  <<>>});
          false ->
              convert(Rest, State#{currentToken := <<CT/binary, "#">>,
                                   rest         := <<>>})
      end;
  
  %% Header end by end of data
  convert(<<>>, #{state        := Tag,
                  currentToken := CT,
                  lastLine     := <<>>,
                  html         := Html,
                  rest         := Rest})
      when (Tag == h6) or (Tag == h5) or (Tag == h4) or
           (Tag == h3) or (Tag == h2) or (Tag == h1) ->
      BinTag = makeTag(Tag, CT),
      <<Html/binary, BinTag/binary, Rest/binary>>;
  convert(<<>>, #{state        := Tag,
                  currentToken := CT,
                  lastLine     := LL,
                  html         := Html,
                  rest         := Rest})
      when (Tag == h6) or (Tag == h5) or (Tag == h4) or
           (Tag == h3) or (Tag == h2) or (Tag == h1) ->
      BinTag = makeTag(Tag, CT),
      <<Html/binary, LL/binary, ?brTag, BinTag/binary, Rest/binary>>;
  
  %% Header end by #...
  convert(<<" #", Rest/binary>>, State = #{state        := Tag,
                                           currentToken := CT,
                                           html         := Html})
      when (Tag == h6) or (Tag == h5) or (Tag == h4) or
           (Tag == h3) or (Tag == h2) or (Tag == h1) ->
      case headerEnd(Rest) of
          {true, Rest2} ->
              convert(<<Rest2/binary>>, State#{state        := Tag,
                                               currentToken := CT,
                                               html         := Html});
          false ->
              convert(Rest, State#{currentToken := <<CT/binary, " #">>,
                                   rest         := <<>>})
      end;
  
  %% Header end by line end.
  convert(<<13, 10, Rest/binary>>, State = #{state        := Tag,
                                             currentToken := CT,
                                             html         := Html})
      when (Tag == h6) or (Tag == h5) or (Tag == h4) or
           (Tag == h3) or (Tag == h2) or (Tag == h1) ->
      {LineEnding, Rest2} = getLineEnding(Rest),
      BinTag = makeTag(Tag, CT),
      Html2  = <<Html/binary, BinTag/binary, LineEnding/binary>>,
      convert(Rest2, State#{state        := text,
                            currentToken := <<>>,
                            html         := Html2,
                            rest         := <<>>});
  
  %% Parse header text
  convert(<<Char:8, Rest/binary>>, State = #{state := Tag, currentToken := CT})
      when (Tag == h6) or (Tag == h5) or (Tag == h4) or
           (Tag == h3) or (Tag == h2) or (Tag == h1) ->
      convert(Rest, State#{currentToken := <<CT/binary, Char:8>>, rest := <<>>});
  
  %% Text line ending
  convert(<<13, 10, Rest/binary>>, State = #{state        := text,
                                             currentToken := CT,
                                             lastLine     := <<>>}) ->
              {LineEnding, Rest2} = getLineEnding(CT, Rest),
              convert(Rest2, State#{lastLine     := <<CT/binary>>,
                                    currentToken := <<>>,
                                    rest         := LineEnding});
  convert(<<13, 10, Rest/binary>>, State = #{state        := text,
                                             currentToken := CT,
                                             html         := Html,
                                             lastLine     := LL}) ->
      case header(CT, LL) of
          {true, Tag, Hdr} ->
              BinTag = makeTag(Tag, Hdr),
              Html2  = <<Html/binary, BinTag/binary, 13, 10>>,
              convert(Rest, State#{html         := Html2,
                                   lastLine     := <<>>,
                                   currentToken := <<>>,
                                   rest         := <<>>});
          false ->
              {LineEnding, Rest2} = getLineEnding(CT, Rest),
              Html2 = <<Html/binary, LL/binary, LineEnding/binary>>,
              convert(Rest2, State#{html         := Html2,
                                    lastLine     := CT,
                                    currentToken := <<>>,
                                    rest         := <<>>})
      end;
  
  %% Parse text
  convert(<<Char:8, Rest/binary>>, State = #{state        := text,
                                             currentToken := CT}) ->
      convert(Rest, State#{currentToken := <<CT/binary, Char:8>>, rest := <<>>});
  
  %% Text end by end of data
  convert(<<>>, #{state        := text,
                  currentToken := CT,
                  lastLine     := <<>>,
                  html         := Html,
                  rest         := Rest}) ->
      <<Html/binary, CT/binary, Rest/binary>>;
  convert(<<>>, #{state        := text,
                  currentToken := CT,
                  lastLine     := LL,
                  html         := Html,
                  rest         := Rest}) ->
      case header(CT, LL) of
          {true, Tag, Hdr} ->
              BinTag = makeTag(Tag, Hdr),
              <<Html/binary, BinTag/binary, Rest/binary>>;
          false ->
              <<Html/binary, LL/binary, ?brTag, CT/binary, Rest/binary>>
      end.
  
  makeTag(Tag, Content) ->
      BinTag = list_to_binary(atom_to_list(Tag)),
      <<$<, BinTag/binary, $>, Content/binary, $<, $/, BinTag/binary, $>>>.
  
  headerStart(<<"# ",      Rest/binary>>) -> {true, h1, Rest};
  headerStart(<<"## ",     Rest/binary>>) -> {true, h2, Rest};
  
negative.code: underline(_, _, _) ->
      false.
  
  insertBR(Content) ->
      insertBR(Content, <<>>).
  
  insertBR(<<32, 32, 13, 10, Rest/binary>>, SoFar) ->
      insertBR(Rest, <<SoFar/binary, ?brTag>>);
  insertBR(<<32, Rest/binary>>, <<>>) ->
      insertBR(Rest, <<>>);
  insertBR(<<Char:8, Rest/binary>>, SoFar) ->
      insertBR(Rest, <<SoFar/binary, Char:8>>);
  insertBR(<<>>, SoFar) ->
      SoFar.
  
  remBegWS(<<>>)                -> <<>>;
  remBegWS(<<13, Rest/binary>>) -> remBegWS(Rest);
  remBegWS(<<10, Rest/binary>>) -> remBegWS(Rest);
  remBegWS(<<32, Rest/binary>>) -> remBegWS(Rest);
  remBegWS(<<9,  Rest/binary>>) -> remBegWS(Rest);
  remBegWS(Content)             -> Content.
  
  