Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested <programlisting> element in <para> in <listitem> not handled correctly #41

Closed
mrietveld opened this issue May 10, 2016 · 2 comments
Assignees
Labels

Comments

@mrietveld
Copy link
Contributor

mrietveld commented May 10, 2016

This is related to #25:

This is actually a bug.

The format_text method in lib/docbookrx/docbookrx_visitors.rb calls @lines.pop, which causes problems when we have nested elements.

For example:

   <listitem>
     <para>get all process definitions</para>
     <para>
       <programlisting>Collection definitions = runtimeDataService.getProcesses(new QueryContext());</programlisting>
     </para>
   </listitem>
   <listitem>
     <para>get active process instances
       <programlisting>Collection&lt;processinstancedesc> instances = runtimeDataService.getProcessInstances(new QueryContext());</programlisting></para>
   </listitem>

The first listitem is formatted correctly -- while the second is not. The problem is that the code doesn't expect the <para> element to contain the <programlisting>, and pops the formatting for the [source] ("----" in this case), so that you get something that looks like this:

* get all process definitions
+

[source]
----
Collection definitions = runtimeDataService.getProcesses(new QueryContext());
----



[source]
----
 Collection<processinstancedesc> instances = runtimeDataService.getProcessInstances(new QueryContext());
* ----
get active nodes for given process instance

The problem is that we have the following code in format_text:

    if node.is_a? ::Nokogiri::XML::Node
      append_blank_line
      proceed node
      @lines.pop
    else
      nil
    end

and in visit_listitem we have:

 def visit_listitem node
    elements = node.elements.to_a
    item_text = if elements.size > 0
      format_text elements.shift
    else
      format_text node
    end
    # create line with marker and item_text and append it.. 

This means that the text is appended to @lines, then the <programlisting> element is processed (and added to @lines by proceed node in format_text) and only then is the marker added.. which gives us the incorrect asciidoc shown above.

@mrietveld mrietveld changed the title Nested <programlisting> element in <para> not handled correctly Nested <programlisting> element in <para> in <listitem> not handled correctly May 10, 2016
@mrietveld
Copy link
Contributor Author

Fixed here: mrietveld@71f1dd6

@mrietveld mrietveld self-assigned this May 27, 2016
@mojavelinux
Copy link
Member

Thanks for this fix. What worries, me though, is that it seems like this is invalid DocBook and there are a lot of such scenarios that perhaps we shouldn't fix. Is it even valid to have a program listing inside a paragraph?

I'm okay with addressing corner cases that appear frequently, perhaps like this one, but I think we should have a least some restrictions on what DocBook we allow. We can expect some cleanup occur before we touch the DocBook. (Another goal, perhaps, for the planned contributing guide).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants