jgm / cheapskate

Experimental markdown processor in Haskell
BSD 3-Clause "New" or "Revised" License
107 stars 18 forks source link

Output nicely indented HTML? #27

Open kindaro opened 6 years ago

kindaro commented 6 years ago

I am enjoying cheapskate very much, and I am very thankful to the authors and maintainers for creating such a great program.

I have a wish though. The usual output from cheapskate has linebreaks between tags, but it is flat, and this makes it hard to inspect visually. One solution is to pipe it through an additional device that does the indenting, such as the tidy command line application that is available quite widely. But I am thinking that maybe the same would not be too hard to bake into cheapskate. It would at least save one parse∘render round trip, and furthermore minimize the possibility of errors and other undesirable side effects.

Source:

Compiler interaction:
---------------------

* Make sure it is straightforward to inspect each invocation of an external program, particularly:
    - Command line.
    - Environment.

  This should save much confuson.

Through cheapskate:

<h2>Compiler interaction:</h2>
<ul>
<li><p>Make sure it is straightforward to inspect each invocation of an external program, particularly:</p>
<ul>
<li>Command line.</li>
<li>Environment.</li>
</ul>
<p>This should save much confuson.</p></li>
</ul>

Through cheapskate | tidy -i -:

line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 1 column 1 - Warning: inserting implicit <body>
line 1 column 1 - Warning: inserting missing 'title' element
Info: Document content looks like HTML5
Tidy found 3 warnings and 0 errors!

<!DOCTYPE html>
<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for HTML5 for Linux version 5.6.0">
  <title></title>
</head>
<body>
  <h2>Compiler interaction:</h2>
  <ul>
    <li>
      <p>Make sure it is straightforward to inspect each invocation
      of an external program, particularly:</p>
      <ul>
        <li>Command line.</li>
        <li>Environment.</li>
      </ul>
      <p>This should save much confuson.</p>
    </li>
  </ul>
</body>
</html>

About HTML Tidy: https://github.com/htacg/tidy-html5
Bug reports and comments: https://github.com/htacg/tidy-html5/issues
Official mailing list: https://lists.w3.org/Archives/Public/public-htacg/
Latest HTML specification: http://dev.w3.org/html5/spec-author-view/
Validate your HTML documents: http://validator.w3.org/nu/
Lobby your company to join the W3C: http://www.w3.org/Consortium

Do you speak a language other than English, or a different variant of
English? Consider helping us to localize HTML Tidy. For details please see
https://github.com/htacg/tidy-html5/blob/master/README/LOCALIZE.md

In my dream world:

  <h2>Compiler interaction:</h2>
  <ul>
    <li>
      <p>Make sure it is straightforward to inspect each invocation
      of an external program, particularly:</p>
      <ul>
        <li>Command line.</li>
        <li>Environment.</li>
      </ul>
      <p>This should save much confuson.</p>
    </li>
  </ul>