[valadoc] libvaladoc/content: SourceCode: Strip leading and trailing empty lines
- From: Florian Brosch <flobrosch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [valadoc] libvaladoc/content: SourceCode: Strip leading and trailing empty lines
- Date: Mon, 19 Nov 2012 01:46:01 +0000 (UTC)
commit 9cb89acac0adf0ee111ffc6e52115966c549690a
Author: Florian Brosch <flo brosch gmail com>
Date: Sat Nov 17 03:50:16 2012 +0100
libvaladoc/content: SourceCode: Strip leading and trailing empty lines
src/libvaladoc/content/sourcecode.vala | 26 +++++++++++++++++++++++++-
src/libvaladoc/html/htmlrenderer.vala | 4 ++--
2 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/src/libvaladoc/content/sourcecode.vala b/src/libvaladoc/content/sourcecode.vala
index 86ad66f..de3bdeb 100644
--- a/src/libvaladoc/content/sourcecode.vala
+++ b/src/libvaladoc/content/sourcecode.vala
@@ -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) {
diff --git a/src/libvaladoc/html/htmlrenderer.vala b/src/libvaladoc/html/htmlrenderer.vala
index 4bf69d7..513913f 100644
--- a/src/libvaladoc/html/htmlrenderer.vala
+++ b/src/libvaladoc/html/htmlrenderer.vala
@@ -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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]