From: Jean-Christophe Beaupré Date: Fri, 19 Dec 2014 16:25:32 +0000 (-0500) Subject: neo_doxygen: Add an API to process description markup. X-Git-Tag: v0.7~3^2 X-Git-Url: http://nitlanguage.org neo_doxygen: Add an API to process description markup. Signed-off-by: Jean-Christophe Beaupré --- diff --git a/contrib/neo_doxygen/src/doxml/doc_listener.nit b/contrib/neo_doxygen/src/doxml/doc_listener.nit index 2b9df04..05ecd35 100644 --- a/contrib/neo_doxygen/src/doxml/doc_listener.nit +++ b/contrib/neo_doxygen/src/doxml/doc_listener.nit @@ -16,6 +16,7 @@ module doxml::doc_listener import listener +import html # Processes documentation. class DocListener @@ -24,9 +25,70 @@ class DocListener # The read documentation. var doc = new Documentation is writable + # Mapping between the type of a Doxygen element and the corresponding + # factory. + private var factories = new HashMap[String, HtmlElementFactory] + + private var element_stack = new Array[HTMLTag] + + # Does the next block have to be added to the detailed description? + private var in_detailed_description = false + + redef fun listen_until(uri, local_name) do + super + if local_name == "briefdescription" then + in_detailed_description = false + else + in_detailed_description = true + end + end + + redef fun start_dox_element(local_name, atts) do + super + var factory = factories.get_or_null(local_name) + if factory == null then return + element_stack.push(factory.create_element(local_name, atts)) + end + + redef fun end_dox_element(local_name) do + super + if not factories.has_key(local_name) then return + if element_stack.is_empty then return + var current_element = element_stack.pop + current_element.append(flush_buffer.trim) + if element_stack.is_empty then add_block(current_element.write_to_string) + end + redef fun end_listening do super - var line = flush_buffer.trim - if not line.is_empty then doc.add(line) + if not element_stack.is_empty then + var current_element = element_stack.first.write_to_string + add_block(current_element) + end + add_block(flush_buffer.trim) + element_stack.clear end + + private fun add_block(block: String) do + if block.is_empty then return + if in_detailed_description then + doc.add(block) + else + doc.brief_description = block + in_detailed_description = true + end + end +end + +# Provides a mean to create a certain kind of HTML elements. +private abstract class HtmlElementFactory + # Create a new empty HTML element. + # + # Parameters: + # + # * `local_name`: Type of the Doxygen element that will be represented by + # the HTML element. + # * `attributes`: Attributes of the Doxygen element that will be + # represented by the HTML element. + fun create_element(local_name: String, attributes: Attributes): HTMLTag is abstract end