From 6137e94a25d18a48298c0130724441c83d9649e7 Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Thu, 16 Jul 2015 10:46:39 -0700 Subject: [PATCH] (PDOC-30) Fix Markdown parsing lists parsing The transformer comment matching regex matched all whitespace after a comment. Lines which were effectively "blank" and just had a comment would be erased. Markdown lists need to end with a blank line. This messed up markdown formatting. The culprit is the regex /^\s*#\s/ which matches all of the comment ' #\n', however we want to leave the newline alone for markdown to parse. We replace the regex with /^\s*#[ \t]/ which will only match tabs or spaces after the hash and leave our beloved newline alone. --- lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb | 9 ++++++++- .../puppetlabs/strings/yard/defined_type_handler_spec.rb | 2 +- .../puppetlabs/strings/yard/host_class_handler_spec.rb | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb b/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb index 927131916..f978d2c0d 100644 --- a/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb +++ b/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb @@ -58,7 +58,14 @@ def extract_comments # FIXME: The gsub trims comments, but is extremely optimistic: It # assumes only one space separates the comment body from the # comment character. - comments.unshift line.gsub(/^\s*#\s/, '') + # NOTE: We cannot just trim any amount of whitespace as indentation + # is sometimes significant in markdown. We would need a real parser. + + # Comments which begin with some whitespace, a hash and then some + # tabs and spaces should be scrubbed. Comments which just have a + # solitary hash then a newline should keep that newline since newlines + # are significant in markdown. + comments.unshift line.gsub(/^\s*#[\t ]/, '').gsub(/^\s*#\n/, "\n") else # No comment found on this line. We must be done piecing together a # comment block. diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/defined_type_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/defined_type_handler_spec.rb index 542393c84..8ba38f776 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/defined_type_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/defined_type_handler_spec.rb @@ -32,7 +32,7 @@ def the_definedtype() parse(puppet_code, :puppet) - comment = "Definition: foo::bar\nThis class does some stuff" + comment = "Definition: foo::bar\n\nThis class does some stuff" expect(the_definedtype).to document_a(:type => :definedtype, :docstring => comment) end diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb index d92667215..6759d22c4 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb @@ -31,7 +31,7 @@ class foo::bar { } parse(puppet_code, :puppet) - comment = "Class: foo::bar\nThis class does some stuff" + comment = "Class: foo::bar\n\nThis class does some stuff" expect(the_hostclass).to document_a(:type => :hostclass, :docstring => comment) end