File 0628-erl_docgen-Fix-generating-docs-chunk-entry-for-seeer.patch of Package erlang

From 2879af76e761faec3abb0af385a184da0f923fcf Mon Sep 17 00:00:00 2001
From: Wojtek Mach <wojtek@wojtekmach.pl>
Date: Wed, 18 Aug 2021 13:39:26 +0200
Subject: [PATCH] erl_docgen: Fix generating docs chunk entry for `<seeerl>`

Before this patch, this XML:

    <!-- https://github.com/erlang/otp/blob/a40b5380e05a8b390c776556521b6e94e9e11b73/lib/stdlib/doc/src/binary.xml#L472:L474 -->
    are also available in the
    <seeerl marker="erts:erlang"><c>erlang</c></seeerl>
    module under the names

Produced this chunk entry:

    <<" are also available in the ">>,
    {a,[{href,<<"stdlib:binary#erts:erlang">>},
        {rel,<<"https://erlang.org/doc/link/seeerl">>}],
       [{code,[],[<<"erlang">>]}]},
    <<" module under the names ">>,

Note the `stdlib:binary#erts:erlang` instead of the expected
`stdlib:binary`.

With this patch we have the following behaviour. Say, we are generating
docs for the app `myapp` and the module `mymod`:

    "app:mod#anchor" => "app:mod#anchor"
    "mod#anchor"     => "myapp:mod#anchor"
    "app:mod"        => "app:mod"
    "mod"            => "myapp:mod"
---
 lib/erl_docgen/src/docgen_xml_to_chunk.erl | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/erl_docgen/src/docgen_xml_to_chunk.erl b/lib/erl_docgen/src/docgen_xml_to_chunk.erl
index 634013922e..2d34350618 100644
--- a/lib/erl_docgen/src/docgen_xml_to_chunk.erl
+++ b/lib/erl_docgen/src/docgen_xml_to_chunk.erl
@@ -639,17 +639,22 @@ transform_datatype(Dom,_Acc) ->
 
 transform_see({See,[{marker,Marker}],Content}) ->
     AbsMarker =
-        case string:lexemes(Marker,"#") of
-            [Link] -> [get(application),":",get(module),"#",Link];
-            [AppMod, Link] ->
-                case string:lexemes(AppMod,":") of
-                    [Mod] -> [get(application),":",Mod,"#",Link];
-                    [App, Mod] -> [App,":",Mod,"#",Link]
-                end
+        case string:split(Marker, "#") of
+            [AppFile] -> marker_defaults(AppFile);
+            [AppFile, Anchor] -> [marker_defaults(AppFile), "#", Anchor]
         end,
+
     {a, [{href,iolist_to_binary(AbsMarker)},
          {rel,<<"https://erlang.org/doc/link/",(atom_to_binary(See))/binary>>}], Content}.
 
+marker_defaults("") ->
+    [get(application), ":", get(module)];
+marker_defaults(AppFile) ->
+    case string:split(AppFile, ":") of
+        [File] -> [get(application), ":", File];
+        [App, File] -> [App, ":", File]
+    end.
+
 to_chunk(Dom, Source, Module, AST) ->
     [{module,MAttr,Mcontent}] = Dom,
 
-- 
2.31.1

openSUSE Build Service is sponsored by