]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
gir-importer: docbook: resolve internal links
authorFlorian Brosch <flo.brosch@gmail.com>
Mon, 25 Aug 2014 23:45:24 +0000 (01:45 +0200)
committerFlorian Brosch <flo.brosch@gmail.com>
Fri, 29 Aug 2014 13:52:54 +0000 (15:52 +0200)
src/libvaladoc/documentation/documentationparser.vala
src/libvaladoc/documentation/gtkdoccommentparser.vala

index 4ca6aef2b6ee511478819676f728909fe0f3ddfd..481ba6fd4a8b0500ffe82b93452096c5eb734ad4 100644 (file)
@@ -82,7 +82,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                        GirMetaData metadata = get_metadata_for_comment (gir_comment);
 
                        if (metadata.is_docbook) {
-                               Comment doc_comment = gtkdoc_parser.parse (element, gir_comment, metadata);
+                               Comment doc_comment = gtkdoc_parser.parse (element, gir_comment, metadata, id_registrar);
                                return doc_comment;
                        } else {
                                Comment doc_comment = gtkdoc_markdown_parser.parse (element, gir_comment, metadata, id_registrar);
index a9553c8cbac03272290cb9415aee4455228e8f54..372b0590aa48f08d090a545c478ab65a6b7a68b2 100644 (file)
@@ -49,6 +49,7 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
        private Regex? is_numeric_regex = null;
        private Regex? normalize_regex = null;
 
+       private Importer.InternalIdRegistrar id_registrar = null;
        private GirMetaData? current_metadata = null;
 
        private inline string fix_resource_path (string path) {
@@ -114,9 +115,10 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                }
        }
 
-       public Comment? parse (Api.Node element, Api.GirSourceComment gir_comment, GirMetaData gir_metadata) {
+       public Comment? parse (Api.Node element, Api.GirSourceComment gir_comment, GirMetaData gir_metadata, Importer.InternalIdRegistrar id_registrar) {
                this.instance_param_name = gir_comment.instance_param_name;
                this.current_metadata = gir_metadata;
+               this.id_registrar = id_registrar;
                this.element = element;
 
                Comment? comment = this.parse_main_content (gir_comment);
@@ -295,7 +297,7 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
        // Rules, Ground:
        //
 
-       private Inline? parse_docbook_link_tempalte (string tagname) {
+       private Inline? parse_docbook_link_tempalte (string tagname, bool is_internal) {
                if (!check_xml_open_tag (tagname)) {
                        this.report_unexpected_token (current, "<%s>".printf (tagname));
                        return null;
@@ -320,6 +322,9 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                }
 
                var link = factory.create_link ();
+               if (is_internal) {
+                       link.id_registrar = id_registrar;
+               }
                link.url = url;
 
                if (builder.len == 0) {
@@ -386,8 +391,8 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                }
 
                string id = current.attributes.get ("id");
+               id_registrar.register_symbol (id, element);
                next ();
-               // TODO register xref
 
                if (!check_xml_close_tag ("anchor")) {
                        this.report_unexpected_token (current, "</anchor>");
@@ -397,7 +402,7 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                next ();
        }
 
-       private Run? parse_xref () {
+       private Link? parse_xref () {
                if (!check_xml_open_tag ("xref")) {
                        this.report_unexpected_token (current, "<xref>");
                        return null;
@@ -405,18 +410,19 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
 
                string linkend = current.attributes.get ("linkend");
                next ();
-               // TODO register xref
 
-               Run run = factory.create_run (Run.Style.ITALIC);
-               run.content.add (factory.create_text (linkend));
+               Link link = factory.create_link ();
+               link.content.add (factory.create_text (linkend));
+               link.id_registrar = id_registrar;
+               link.url = linkend;
 
                if (!check_xml_close_tag ("xref")) {
                        this.report_unexpected_token (current, "</xref>");
-                       return run;
+                       return link;
                }
 
                next ();
-               return run;
+               return link;
        }
 
        private Run? parse_highlighted_template (string tag_name, Run.Style style) {
@@ -837,8 +843,8 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                        return null;
                }
 
-               // TODO: register id
                string id = current.attributes.get ("id");
+               id_registrar.register_symbol (id, element);
                next ();
 
                parse_docbook_spaces ();
@@ -1111,6 +1117,7 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                }
 
                string id = current.attributes.get ("id");
+               id_registrar.register_symbol (id, element);
                next ();
 
                LinkedList<Block> content = parse_mixed_content ();
@@ -1482,9 +1489,9 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                        } else if (current.type == TokenType.XML_OPEN && current.content == "anchor") {
                                parse_anchor ();
                        } else if (current.type == TokenType.XML_OPEN && current.content == "link") {
-                               append_inline_content_not_null (run, parse_docbook_link_tempalte ("link"));
+                               append_inline_content_not_null (run, parse_docbook_link_tempalte ("link", true));
                        } else if (current.type == TokenType.XML_OPEN && current.content == "ulink") {
-                               append_inline_content_not_null (run, parse_docbook_link_tempalte ("ulink"));
+                               append_inline_content_not_null (run, parse_docbook_link_tempalte ("ulink", false));
                        } else if (current.type == TokenType.XML_OPEN && current.content == "xref") {
                                append_inline_content_not_null (run, parse_xref ());
                        } else if (current.type == TokenType.XML_OPEN && current.content == "tag") {