Kdwatch
Autoreloading display of kramdown-rfc document in browser
Installation
$ pip3 install --upgrade xml2rfc
$ gem update
$ gem install kdwatch
- For some reason, the initial
gem installtakes a couple of minutes, during the first few of which it may seem nothing happens. - If the above
pip3doesn't work, no problem: in a pinch, kdrfc will use the IETF web service for xml2rfc processing (but that may be a bit slower). - Depending on system configuration, add
sudo(but don't if it isn't actually needed).
Usage
- Open a separate terminal window/screen.
- Go to a directory that has a single draft-*.md (or select one by specifying the markdown file name on the command line) and run:
$ kdwatch
- After about 10 seconds, a browser will open (or an error message will pop up with the URL to use, which depends on the options given, but defaults to http://127.0.0.1:7991/).
Now, whenever you do an editor save of the markdown file, after a couple of seconds (1.6 s for my Intel Mac, 0.8 s for my M1 Mac) you see an updated HTML in the browser.
You will need to keep the kdwatch terminal/screen open to see
potential error messages, e.g., if you break the markdown in some way.
There can only be one (per host/port)
There can only be one kdwatch active on each host and port. You will need to specify a different port (or host!) to run more than one kdwatch at the same time.
-p portto select a port number (default: 7991)-1to6as a shortcut for-p 7991(default) to-p 7996(must be last option because of an idiosyncrasy of the optionparser library)
kdwatch has two flags to simplify handling servers that might be accumulating on one host/port:
-eto kill (SIGINT) any current holder of the port given and exit-rto do this, and to start a new instance as well
So the most likely use is going to be:
kdwatch -r
or maybe
kdwatch -r2
for the second draft you are editing at the same time,
or, if your drafts are weirdly named or you need to select one out of many
kdwatch -r5 weird-draft.md
(Glitches are to be expected if you start more than one server out of the same directory at the same instant; TODO; for now, wait 10 seconds before starting another from the same directory.)
7991, haven't I heard that number before?
The default port number was chosen after RFC 7991, the initial (no longer really authoritative) version of the v3 RFCXML specification, and the port shortcuts 1 to 6 point to this and further RFCs from this series. (7997 is a particularly lame RFC, so it cannot be chosen by a shortcut [actually: this port is already registered for something else].)
kdwatch is a web server
kdwatch essentially is a web server and can listen on any host interface you might have:
-o hostto select an interface address on the serving host (default: 127.0.0.1)-ias a shortcut for-o ::(istands for "on the Internet")
Unless used on 127.0.0.1 (or ::1), kdwatch is accessible to anyone who
can access your laptop over IP. That may be a security problem -- do
not specify a non-local interface unless you know you are not “on the
Internet” (or trust the way I cobble together software). If you are,
maybe kdwatch -e before going there!
The fun thing with the -i option is that you can replace the local
URL by filling in the hostname of the laptop and use the resulting URL
on a different browser (e.g., http://mylaptop.local:7991 on your iPad or
another laptop), and save some screen real-estate on your laptop.
With a globally routable address, kdwatch even can be used for joint
viewing in a team.
Feedback, please
This has only been tested on macOS and briefly on Linux. No idea about WSL. There is very little error handling yet, so restarts of the tool may be required, or sometimes reloading in the browser (CMD-R/F5) is all that is needed.
If you try it, please send feedback (and, in case of an error, all output on the kdwatch terminal window, please).
Bug reports, pull requests, or simple suggestions are welcome on GitHub at https://github.com/cabo/kdwatch, e.g., simply submit an issue or send me mail.
License
The gem is available as open source under the terms of the MIT License.