Added Markdown support to wrap(1)

Paul J. Lucas paul at lucasmail.org
Thu May 5 00:16:27 EDT 2016


Hello -

I’ve been hacking on wrap(1) and wrapc(1) that are text and source-code-comment reformatters, respectively, for a long time.  I started them to scratch my particular itch, namely the ability to easily rewrap text (and, in particular, comments in source code) while in an editor.  See:

	https://github.com/paul-j-lucas/wrap

The relevance for this mailing list is that I’ve recently completed adding Markdown support since source-code-comment-formatting tools like Doxygen now support Markdown.  Unlike other Markdown formatters that convert Markdown into some other format (typically HTML), wrap does source-to-source reformatting, i.e., it rewraps Markdown text into nicer-looking Markdown text.

For example, if I had a Markdown comment like:

  //
  // While blank lines don't change state directly, we do have to keep track of
  // when we've seen one because:
  //
  //  + They help determine whether the line after the blank line is a
  //    continuation of the current state based on indentation.
  //  + They disambiguate "---" between a Setext 2nd-level header and a
  //    horizontal rule.
  //

and then I edit the comment by inserting text into the second bullet:

  //
  // While blank lines don't change state directly, we do have to keep track of
  // when we've seen one because:
  //
  //  + They help determine whether the line after the blank line is a
  //    continuation of the current state based on indentation.
  //  + They disambiguate "---" between a Setext 2nd-level header (that has to have a text line before it) and a
  //    horizontal rule (that doesn't).
  //

then the text of the bullet is too long.  To make it look nice, ordinarily I’ve have to insert a newline, add another //, and join the second line of the bullet.  Instead, while in vim (after having bound the key sequence `c for wrap comment), I can just type said sequence while the cursor is in that comment and it will instantly reformat the comment to:

  //
  // While blank lines don't change state directly, we do have to keep track of
  // when we've seen one because:
  //
  //  + They help determine whether the line after the blank line is a
  //    continuation of the current state based on indentation.
  //  + They disambiguate "---" between a Setext 2nd-level header (that
  //    has to have a text line before it) and a horizontal rule (that
  //    doesn't).
  //

- Paul



More information about the Markdown-Discuss mailing list