Skip to content

Indent a processing instruction in the Pretty formatter - #400

Open
mokshupadhyay wants to merge 1 commit into
ruby:masterfrom
mokshupadhyay:fix/pretty-indent-instruction
Open

mokshupadhyay wants to merge 1 commit into
ruby:masterfrom
mokshupadhyay:fix/pretty-indent-instruction

Conversation

@mokshupadhyay

Copy link
Copy Markdown
Contributor

REXML::Formatters::Pretty indents comments (write_comment) and CDATA sections (write_cdata) to the current nesting level, but a processing instruction inside an element was written at column 0, so it does not line up with its siblings.

Real output of REXML::Formatters::Pretty.new(2) for <a><?pi d?><!--c--><b/></a>, on master and with this change:

master:               after:
<a>                   <a>
<?pi d?>                <?pi d?>
  <!--c-->              <!--c-->
  <b/>                  <b/>
</a>                  </a>

The fix adds a write_instruction override that writes the indentation and then calls super, the same pattern as write_comment and write_cdata.

Test: PrettyFormatterTest::InstructionTest#test_instruction_is_indented_like_comment in test/formatter/test_pretty.rb. With this change bundle exec rake test gives 882 tests, 2816 assertions, 0 failures; on master the new test is the one failure (1 of 882). The repository has no linter configured, and I did not add a NEWS entry.

Comments and CDATA sections are indented to the nesting level, but a
processing instruction inside an element was written at column 0.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant