Keep It Simple Text (KIST)

KIST combines the best elements of various plain text markup languages I’ve used or developed over the past forty years. I assume the source text must be easily understood by casual readers. To the extent possible I exploit conventions already used by plain text typists (in email for example). The most basic of these conventions are:

  • Separate paragraphs, headings, lists, etc. with blank lines.
  • Precede headings with pound signs (#).
  • Precede list items with tabs.
  • Bracket words for emphasis with asterisks (*).

KIST aspires to the “Minimal Ink Principle” proposed by Edward Tufte in 1983: “The ratio of ink that conveys information vs the total ink used should approach unity.”

KIST aspires to “fail gracefully” when something isn’t quite right.

Background

In the beginning there was Text. By “Text” I mean the digital representation of characters from the major phonetic languages in use today. And because I’m writing in English, I will focus there. Things first come into focus with the “American Standard Code for Information Interchange” (ASCII) back in 1961. It represented all the characters found on typewriters of the time (a-z, A-Z, 0-9, with assorted punctuation). ASCII is embedded in modern encoding schemes such as Unicode and UFT-8. Various systems evolved to process and display text on screens and paper.

Then there was HyperText–the ability to link words to information in other locations. Many developers proposed hypertext systems (myself included), but none dominated until “HyperText Markup Language” (HTML) came on the scene in 1980. After five major revisions it has become the de facto standard for most electronic publishing.

For all its strengths HTML is somewhat hard to write freehand. It has complex syntactical rules that are easy to break (the ubiquitous “unclosed tag” problem for example). Writers want to write–without focusing on a language intended to be read only by computers. So programmers immediately began inventing ways to generate HTML from other formats. This 1996 list from CERN has over 80 entries, including my own MTX.

Synthesis

KIST combines the best ideas from several sources:

  • MTX (paragraphs, headings, lists)
  • TSV (tab separated values, tables)
  • Email (block quoting)
  • Action Journaling (task lists)
  • HTML (hypertext, etc.)

Examples

A simple document structure:

  Title
  # Heading 1
  ...content...
  ## Subheading 1a
  ...content...
  #Heading 2
  ...etc...

Nested lists:

    Fruit
        apple
        banana
        orange
    Veggies
        carrot
        rutabaga

An inline image:

  ^Flower Photo(flower.jpg)

A hypertext link:

  A line with a ^link(more.html) to more info.

My History of Textual Tinkering

  • 1988 HYTEXT Hypertext Publishing System for MS-DOS
  • 1989 Conversion of Medical Textbooks with AWK (NLM Fellowship)
  • 1996 MTX Marked TeXt for Web Publishing (U of Fla)
  • 2000s Action Journaling for Paper, Computer & Web
  • 2016 TableTop – Table Manipulation App
  • 2020 Keep It Simple Text (KIST)

“Wisdom” Bot for Mastodon

I left the Birdsite about six months ago when the new owner started mucking about.

No regrets! Mastodon has been so much better! I decided to try my hand at creating an automated “robot” to post quotations alongside some of my photographs.

Wisdom in Space Posts Every Four Hours

Mastodon is much more civilized and well organized—including best practices for social media bots. There is even a server dedicated to bots called “botsin.space”–so I called my new bot “Wisdom in Space“.

There are many helpful websites to get started. Most use the mastodon interface package for Python. This is the first time I’ve written code in the python language, but fortunately the learning curve isn’t very steep. The biggest conceptual hurdle for me was understanding and using virtual environments on the shared server. Once I got those pesky details worked out I set up a cron job to post every four hours. The quotes are in a tab-delimited text file and the images are in a nearby directory. Note the development code below works locally on my laptop. The directory paths and other details are different on the server. I hope someone finds this useful!

#
#	wisdombot 0.2
#	quote of the day service for mastodon
#	copyright richard rathe 2023
#	(cc) attrib-noncomm-share-alike
#

import re

import glob

import random

from mastodon import Mastodon

quote_list = []

with open('wisdom.dat') as file:

	for line in file:

		line = line[:-1]  # remove newline

		quote_list.append(line)


qmax = str(len(quote_list))

image_list = glob.glob('images/*.jpg')

imax = str(len(image_list))

qrand = random.randrange(int(qmax))

line = quote_list[qrand]

line = line.replace('—'  , '--')	# fix entities
line = line.replace('"'   , '\"')
line = line.replace('é' , 'e')
line = line.replace('ø' , 'o')
line = line.replace('ö'   , 'o')
line = line.replace('&'    , '&')

data_list = line.split('\t\t')		# double tab delimited

irand = random.randrange(int(imax))	# pick image at random

img = image_list[irand]

match = re.search(r'^images/([a-z0-9-]+)', img, re.I)

if match:
	stem = match.group(1)
else:
	stem = ''

ikeyw = ''

for i in stem.split('-'):
	i = i[0].upper() + i[1:]	# capitalize
	ikeyw += " #" + i

ikeyw = ikeyw[1:]	# nuke leading space

keyw = ''

for i in data_list[2].split('/'):	# keywords are '/' delimited
	i = i.replace(' ', '')
	i = i.replace('-', '')
	keyw += " #" + i

keyw = keyw[1:]		# nuke leading space

quote = data_list[3]

name = data_list[0]				# author name

ntag = re.sub('[^0-9a-zA-Z]+', '', name)	# author hashtag
ntag = '#' + ntag

other = data_list[1]				# source info (if available)

if other == 'None':
	other = '';
else:
	other = ' (' + other + ')'

out = quote + '\n    -- ' + name + other + '\n\n'

out += '⬆ #Quotes ' + ntag + ' ' + keyw + '\n\n⬇ #Photography ' + ikeyw

if len(out) < 500:		# limited to 500 chars

	print('\n' + out + '\n')

	mastodon = Mastodon(
		access_token = 'token.secret',
		api_base_url = 'https://botsin.space/'
	)

	media = mastodon.media_post(img, description="photo by richard rathe")
 	mastodon.status_post(out, media_ids=[media])

Timezone Solution for mySQL

I am new to SQL languages and I recently spent about two hours trying to bring some order to timestamps in my PTM project. It was obvious that I should store universal UTC/GMT date/times in the database. It was not so clear how to convert these back to local time. Examples I found on the web were all commands typed at the mysql prompt, not database queries. After quite a bit of poking around I finally stumbled on the AS Keyword in mySQL. Seems to work well so I decided to share the solution here for the next newbie to learn from!

SELECT id, date, CONVERT_TZ(date,'+00:00','-04:00') AS corrected_date
FROM `some_table`
WHERE some_criteria = 'something'

This yields output that is nicely localized and completely abstracted from the actual data. Notice that the line for id=27 handles midnight properly.

Output
id date corrected_date
1 2012-06-24 11:46:15 2012-06-24 07:46:15
21 2012-04-23 18:22:21 2012-04-23 14:22:21
28 2011-06-24 11:12:44 2011-06-24 07:12:44
27 2012-04-23 01:53:51 2012-04-22 21:53:51
29 0000-00-00 00:00:00 NULL
30 2012-06-24 00:00:00 2012-06-23 20:00:00
10 2012-06-12 17:12:37 2012-06-12 13:12:37
31 2012-05-06 13:14:35 2012-05-06 09:14:35