using Gee;
-public class Valadoc.Content.ListItem : InlineContent {
- public List? sub_list { get; set; }
+public class Valadoc.Content.ListItem : BlockContent {
internal ListItem () {
base ();
}
public override void check (Api.Tree api_root, Api.Node container, string file_path, ErrorReporter reporter, Settings settings) {
- // Check inline content
+ // Check block content
base.check (api_root, container, file_path, reporter, settings);
-
- if (sub_list != null) {
- sub_list.check (api_root, container, file_path, reporter, settings);
- }
}
public override void accept (ContentVisitor visitor) {
public override void accept_children (ContentVisitor visitor) {
base.accept_children (visitor);
-
- if (sub_list != null) {
- sub_list.accept (visitor);
- }
}
}
private void new_list_item (Content.List.Bullet bullet) throws ParserError {
var new_item = _factory.create_list_item ();
+ var content = _factory.create_paragraph ();
+ new_item.content.add (content);
Content.List list = null;
if (levels.length >= 1) {
+ // Pop current content
+ pop ();
+
if (current_level > levels[levels.length - 1]) {
list = _factory.create_list ();
list.bullet = bullet;
var current_item = peek () as ListItem;
- current_item.sub_list = list;
+ current_item.content.add (list);
push (list);
levels += current_level;
list.items.add (new_item);
push (new_item);
+ push (content);
}
private string bullet_type_string (Content.List.Bullet bullet) {
}
private void finish_list () {
+ // pop content
+ pop ();
+
while (peek () is ListItem) {
pop ();
pop ();
.set_name ("IndentedItem")
.set_start (() => { current_level = 0; })
.set_reduce (() => {
- var content_list = ((ListItem) peek ()).content;
+ var content_list = ((InlineContent) peek ()).content;
if (content_list.size > 0 && content_list.last () is Text) {
((Text) content_list.last ()).content._chomp ();
}
}
#if DEBUG
- private void dump_stack () {
- message ("Dumping stack");
+ private void dump_stack (string title) {
+ message ("=== Dumping stack: %s ===", title);
foreach (Object object in _stack) {
message ("%s", object.get_type ().name ());
}
ListItem item = factory.create_list_item ();
while (current.type != TokenType.XML_CLOSE && current.type != TokenType.EOF) {
- if (current.type == TokenType.XML_OPEN && current.content == "para") {
- foreach (Block block in parse_docbook_para ()) {
- if (block is Paragraph) {
- if (item.content.size > 0) {
- item.content.add (factory.create_text ("\n"));
- }
-
- item.content.add_all (((Paragraph) block).content);
- } else {
- // TODO: extend me
- this.report_unexpected_token (current, "<para>|</listitem>");
- return null;
- }
- }
- } else {
- Token tmp_t = current;
- parse_inline_content ();
- if (tmp_t == current) {
- break;
- }
- }
+ item.content.add_all (parse_mixed_content ());
}
if (!check_xml_close_tag ("listitem")) {
}
LinkedList<Block> lst = parse_block_content ();
- if (lst != null && run.content.size > 0) {
+ if (lst != null && lst.size > 0) {
content.add_all (lst);
continue;
}
return content;
}
- private LinkedList<Block>? parse_docbook_para () {
- if (!check_xml_open_tag ("para")) {
- this.report_unexpected_token (current, "<para>");
+ private inline LinkedList<Block>? parse_docbook_simpara () {
+ return parse_docbook_para ("simpara");
+ }
+
+ private LinkedList<Block>? parse_docbook_para (string tag_name = "para") {
+ if (!check_xml_open_tag (tag_name)) {
+ this.report_unexpected_token (current, "<%s>".printf (tag_name));
return null;
}
LinkedList<Block> content = parse_mixed_content ();
- if (!check_xml_close_tag ("para")) {
- this.report_unexpected_token (current, "</para>");
+ // ignore missing </para> to match gtkdocs behaviour
+ if (!check_xml_close_tag (tag_name) && current.type != TokenType.EOF) {
+ this.report_unexpected_token (current, "</%s>".printf (tag_name));
return content;
}
this.append_block_content_not_null (content, parse_docbook_programlisting ());
} else if (current.type == TokenType.XML_OPEN && current.content == "para") {
this.append_block_content_not_null_all (content, parse_docbook_para ());
+ } else if (current.type == TokenType.XML_OPEN && current.content == "simpara") {
+ this.append_block_content_not_null_all (content, parse_docbook_simpara ());
} else if (current.type == TokenType.XML_OPEN && current.content == "informalexample") {
this.append_block_content_not_null_all (content, parse_docbook_informalexample ());
} else if (current.type == TokenType.XML_OPEN && current.content == "example") {
public override void visit_list_item (ListItem element) {
writer.start_tag ("li");
- element.accept_children (this);
+ Paragraph? first_para = (element.content.size > 0)? element.content[0] as Paragraph : null;
+ if (first_para != null) {
+ // We do not pick up alignments in gir-files.
+ first_para.accept_children (this);
+ bool first_entry = true;
+ foreach (var item in element.content) {
+ if (!first_entry) {
+ item.accept (this);
+ }
+ first_entry = false;
+ }
+ } else {
+ element.accept_children (this);
+ }
writer.end_tag ("li");
}