]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc/content: SourceCode: Strip leading and trailing empty lines
authorFlorian Brosch <flo.brosch@gmail.com>
Sat, 17 Nov 2012 02:50:16 +0000 (03:50 +0100)
committerFlorian Brosch <flo.brosch@gmail.com>
Mon, 19 Nov 2012 00:50:59 +0000 (01:50 +0100)
src/libvaladoc/content/sourcecode.vala
src/libvaladoc/html/htmlrenderer.vala

index 86ad66fd80f9607edf145cebbc4706ac2c3b870f..de3bdebe612d6d76a52c9a9c2f946a2eb2a21dce 100644 (file)
@@ -123,6 +123,29 @@ public class Valadoc.Content.SourceCode : ContentElement, Inline {
                }
        }
 
+       private inline bool is_empty_string (string line) {
+               for (int i = 0; line[i] != '\0'; i++) {
+                       if (line[i].isspace () == false) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
+
+       private string strip_code (string code) {
+               string[] lines = code.split ("\n");
+               for (int i = lines.length - 1; i >= 0 && is_empty_string (lines[i]); i--) {
+                       lines[i] = null;
+               }
+
+               string** _lines = lines;
+               for (int i = 0; lines[i] != null && is_empty_string (lines[i]); i++) {
+                       _lines = &lines[i + 1];
+               }
+
+               return string.joinv ("\n", (string[]) _lines);
+       }
        public override void check (Api.Tree api_root, Api.Node container, string file_path, ErrorReporter reporter, Settings settings) {
                string[] splitted = code.split ("\n", 2);
                if (splitted[0].strip () == "") {
@@ -140,10 +163,11 @@ public class Valadoc.Content.SourceCode : ContentElement, Inline {
                                if (_language == null && name != "none") {
                                        string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": ";
                                        reporter.simple_warning ("%s: %s{{{: warning: Unsupported programming language '%s'", file_path, node_segment, name);
-                                       return ;
                                }
                        }
                }
+
+               code = strip_code (code);
        }
 
        public override void accept (ContentVisitor visitor) {
index 4bf69d7427b74bee4920ef6192cca5424155bd6f..513913fb688acbe8937d1840e2e79bb53fa41f99 100644 (file)
@@ -463,11 +463,11 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
        }
 
        public override void visit_source_code (SourceCode element) {
-               writer.start_tag ("pre", {"class", "main_source"});
                writer.set_wrap (false);
+               writer.start_tag ("pre", {"class", "main_source"});
                write_string (element.code);
-               writer.set_wrap (true);
                writer.end_tag ("pre");
+               writer.set_wrap (true);
        }
 
        public override void visit_table (Table element) {