3

I'm writing reST in vim, which handles line breaks for me (after 80 chars). However, since I frequently go back and edit the text before, lines get ugly again. For example, in tables, it's sometimes annoying to re-format a complete table just because you need a line break in some place.

So I wish I had a program that reads my ugly-but-correct reStructuredText and outputs it nicely formatted and wrapped.

I found that pandoc in.rst -w rst mostly works, but it has some drawbacks. For example

:author: John Doe

becomes

author
    John Doe

and title formatting is changed as well. Sadly, there seems to be no rst2rst or something similar. Does anyone have some advice?

user49740
  • 3,220
  • 24
  • 30
wal-o-mat
  • 201
  • 2
  • 5
  • That's fatal if it converts field lists into block quotes. Field lists are the best feature of RST and I use them all the time. There is so much `:name: description` content in everything. That kind of breaks `pandoc` for this task altogether IMO. – NeilG May 31 '23 at 05:21

2 Answers2

1

You could use:

setlocal formatoptions+=a

to turn on automatic formatting of paragraphs in vim. Adding that line to the ftplugin/rst.vim file in your vim configuration directory should do it automatically whenever you start editing a .rst file.

If that reformats too much, it may improve things to also add the w option. That causes vim to only consider a paragraph to extend onto the next line when a line ends with a space. It will automatically put a space at the ends of lines that are automatically inserted.

qqx
  • 2,893
  • 19
  • 16
1

Use -s with pandoc if you want the title block to be handled better.

John MacFarlane
  • 1,646
  • 1
  • 12
  • 3