cortav  Check-in [3b2fea2df1]

Overview
Comment:tidy up repo, add freedesktop file format stuff and viewer handler script
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3b2fea2df1e5f43645d4cb8990d9bd891fa80ce4c8c869d02b6b21a990735016
User & Date: lexi on 2021-12-21 01:22:16
Other Links: manifest | tags
Context
2021-12-21
03:15
make names consistent, make view script customizable check-in: 13a73d4eb8 user: lexi tags: trunk
01:22
tidy up repo, add freedesktop file format stuff and viewer handler script check-in: 3b2fea2df1 user: lexi tags: trunk
2021-12-20
14:10
add weak modes that can be overridden by pragma check-in: c15ffd5fef user: lexi tags: trunk
Changes

Modified cortav.ct from [b7a7fbb952] to [e9d2ad32df].

     9      9   
    10     10   ## cortav vs. markdown
    11     11   the most important difference between cortav and markdown is that cortav is strictly line-oriented. this choice was made to ensure that cortav was relatively easy to parse. so while a simple [$.ct] file may look a bit like a [$.md] file, in reality it's a lot closer to gemtext than any flavor of markdown.
    12     12   
    13     13   ## encoding
    14     14   a cortav document is made up of a sequence of codepoints. UTF-8 must be supported, but other encodings (such as UTF-32 or C6B) may be supported as well. lines will be derived by splitting the codepoints at the linefeed character or equivalent. note that unearthly encodings like C6B or EBCDIC will need to select their own control sequences.
    15     15   
           16  +## file type
           17  +a cortav source file is identified using a file extension, file type, and/or magic byte sequence.
           18  +
           19  +three file extensions are defined as identifying a cortav source file. where relevant, all must be recognized as indicating a cortav source file.
           20  +* [$ct] is the shorthand extension
           21  +* [$cortav] is the canonical disambiguation extension, for use in circumstances where [$*.ct] is already defined to mean a different file format.
           22  +* [$] is the canonical Corran extension, a byte sequence comprising the unicode codepoints [$U+E3CE U+E3BD]. where the filesystem in question does not specify a filename encoding, the bytes should be expressed in UTF-8.
           23  +
           24  +three more extensions are reserved for identifying a cortav intent file.
           25  +* [$ctc] is the shorthand extension
           26  +* [$cortavcun] is the canonical disambiguation extension
           27  +* [$] is the canonical Corran extension, a byte sequence comprising the unicode codepoints [$U+E3CE U+E3BD U+E3CE]. where the filesystem in question does not specify a filename encoding, the bytes should be expressed in UTF-8.
           28  +
           29  +on systems which use metadata to encode filetype, two values are defined to identify cortav source files
           30  +* [$text/x-cortav] should be used when strings or arbitrary byte sequences are supported
           31  +* [$CTAV] (that is, the byte sequence [$0x43 0x54 0x41 0x56]) should be used on systems that support only 32-bit file types/4-character type codes like Classic Mac OS.
           32  +
           33  +two more values are defined to identify cortav intent files.
           34  +* [$text/x-cortav-intent] 
           35  +* [$CTVC] (the byte sequence [$0x43 0x54 0x56 0x43])
           36  +
           37  +on systems which do not define a canonical way of encoding the filetype but support extended attributes of some kind, such as linux, an attribute named [$mime] may be created and given the value [$text/x-cortav] or [$text/x-cortav-intent]; alternatively, extensions may be used.
           38  +
           39  +it is also possible to indicate the nature of a cortav file without using filesystem metadata. this is done by prefixing the file with a magic byte sequence. the sequence used depends on the encoding.
           40  +* for UTF-8 and ASCII, [$%ct[!\\n]] (that is, the byte sequence [$0x25 0x63 0x74 0x0A]) should be used
           41  +* for C6B, the file should begin with the word [$] (that is, the byte sequence [$0x03 0x07 0x3E 0x2D]).
           42  +consequently, this sequence should be ignored by a cortav parser at the start of a file (except as an indication of file format).
           43  +
           44  +for FreeDesktop-based systems, the [$velartrill-cortav.xml] file included in the repository supplies mappings for the extensions and magic byte sequences. a script is also included which can be registered with xdg-open so that double-clicking on a cortav file will render it out and open it in your default web browser.
           45  +
    16     46   ## structure
    17     47   cortav is based on an HTML-like block model, where a document consists of sections, which are made up of blocks, which may contain a sequence of spans. flows of text are automatically conjoined into spans, and blocks are separated by one or more newlines. this means that, unlike in markdown, a single logical paragraph [*cannot] span multiple ASCII lines. the primary purpose of this was to ensure ease of parsing, but also, both markdown and cortav are supposed to be readable from within a plain text editor. this is the 21st century. every reasonable text editor supports soft word wrap, and if yours doesn't, that's entirely your own damn fault.
    18     48   
    19     49   the first character(s) of every line (the "control sequence") indicates the role of that line. if no control sequence is recognized, the sequence [$.] is implied instead. the standard line classes and their associated control sequences are listed below. some control sequences have alternate forms, in order to support modern, readable unicode characters as well as plain ascii text.
    20     50   
    21     51   * paragraphs (. ¶ ❡): a paragraph is a simple block of text. the period control sequence is only necessary if the paragraph text begins with something that would otherwise be interpreted as a control sequence.
    22     52   * newlines (\\): inserts a line break into previous paragraph and attaches the following text. mostly useful for poetry or lyrics.
................................................................................
    95    125   	d: [$%[*[##1]]]
    96    126   * {d author} encodes document authorship
    97    127   * {d cols} specifies the number of columns the next object should be rendered with
    98    128   * {d include} transcludes another file
    99    129   * {d quote} transcludes another file, without expanding the text except for paragraphs 
   100    130   * {d embed}, where possible, embeds another file as an object within the current one. in HTML this could be accomplished with e.g. an iframe.
   101    131   * {d expand} causes the next object (usually a code block) to be fully expanded when it would otherwise not be
   102         -* {d pragma} supplies semantic data about author intent, the kind of information document contains and hints about how it should be displayed to the user. think of them like offhand remarks to the renderer -- there's no guarantee that it'll pay any attention, but if it does, your document will look better. pragmas have no scope; they affect the entire document. the pragma function exists primarily as a means to allow parameters that would normally need to be specified on e.g. the command line to be encoded in the document instead in a way that multiple implementations can understand. a few standard pragmas are defined
          132  +* {d pragma} supplies semantic data about author intent, the kind of information document contains and hints about how it should be displayed to the user. think of them like offhand remarks to the renderer -- there's no guarantee that it'll pay any attention, but if it does, your document will look better. pragmas have no scope; they affect the entire document. the pragma function exists primarily as a means to allow parameters that would normally need to be specified on e.g. the command line to be encoded in the document instead in a way that multiple implementations can understand. a few standard pragmas are defined.
   103    133   ** {d pragma layout} gives a hint on how the document should be layed out. the first hint that is understood will be applied; all others will be discarded. standard hints include:
   104    134   *** essay
   105    135   *** narrative
   106    136   *** screenplay: uses asides to denote actions, quotes for dialogue
   107    137   *** stageplay: uses asides to denote actions, quotes for dialogue
   108    138   *** manual
   109    139   *** glossary
   110    140   *** news
   111    141   ** {d pragma accent} specifies an accent hue (in degrees around the color wheel) for renderers which support colorized output
   112    142   ** {d pragma accent-spread} is a factor that controls the "spread" of hues used in the document. if 0, only the accent color will be used; if larger, other hues will be used in addition to the primary accent color.
   113    143   ** {d pragma dark-on-light on|off} controls whether the color scheme used should be light-on-dark or dark-on-light
   114    144   ** {d pragma page-width} indicates how wide the pages should be
          145  +
          146  +! note on pragmas: particularly when working with collections of documents, you should not keep formatting metadata in the documents themselves! the best thing to do is to have a makefile for compiling the documents using whatever tools you want to support, and encoding the rendering options in this file (for the reference implementation this currently means as command line arguments, but eventually it will support intent files as well) so they can all be changed in one place; pragmas should instead be used for per-document [*overrides] of default settings.
          147  +! a workaround for the lack of intent files in the reference implementation is to have a single pseudo-stylesheet that contains only {d pragma} statements, and then import this file from each individual source file using the {d include} directive. this is suboptimal and recommended only when you need to ensure compatibility between different implementations.
          148  +! when creating HTML files, an even better alternative may be to turn off style generation entirely and link in an external, hand-written CSS stylesheet. this is generally the way you should compile sources for existing websites if you aren't going to write your own extension.
   115    149   
   116    150   ##ex examples
   117    151   
   118    152   ~~~ blockquotes #bq [cortav] ~~~
   119    153   the following excerpts of text were recovered from a partially erased hard drive found in the Hawthorne manor in the weeks after the Incident. context is unknown.
   120    154   
   121    155   #>
................................................................................
   352    386   right now, the use of color in the HTML renderer is very unsatisfactory. the accent mechanism operates on the basis of the CSS HSL function, which is not perceptually uniform; different hues will present different mixes of brightness and some (yellows?) may be ugly or unreadable.
   353    387   
   354    388   the ideal solution would be to simply switch to using LCH based colors. unfortunately, only Safari actually supports the LCH color function right now, and it's unlikely (unless Lea Verou and her husband manage to work a miracle) that Colors Level 4 is going to be implemented very widely any time soon.
   355    389   
   356    390   this leaves us in an awkward position. we can of course do the math ourselves, working in LCH to implement the internal [$@tone] macro, and then "converting" these colors to HSL. unfortunately, you can't actually convert from LCH to HSL; it's like converting from pounds to kilograms. LCH can represent any color the human visual system can perceive; sRGB can't, and CSS HSL is implemented in sRGB. however, we could at least approximate something that would allow for perceptually uniform brightness, which would be an improvement, and this is probably the direction to go in, unless a miracle occurs and [$lch()] or [$color()] pop up in Blink.
   357    391   
   358    392   it may be possible to do a more reasonable job of handling colors in the postscript and TeX outputs. unsure about SVG but i assume it suffers the same problems HTML/CSS do. does groff even support color??
          393  +
          394  +### intent files
          395  +there's currently no standard way to describe the intent and desired formatting of a document besides placing pragmas in the source file itself. this is extremely suboptimal, as when generating collections of documents, it's ideal to be able to keep all formatting information in one place. users should also be able to specify their own styling overrides that describe the way they prefer to read [$cortav] files, especially for uses like gemini or gopher integration.
          396  +
          397  +at some point soon [$cortav] needs to address this by adding intent files that can be activated from outside the source file, such as with a command line flag or a configuration file setting. these will probably consist of lines that are interpreted as pragmata. in addition to the standard intent format however, individual implementations should feel free to provide their own ways to provide intent metadata; e.g. the reference implementation, which has a lua interpreter available, should be able to take a lua script that runs after the parse stage and generates . this will be particularly useful for the end-user who wishes to specify a particular format she likes reading her files in without forcing that format on everyone she sends the compiled document to, as it will be able to interrogate the document and make intelligent decisions about what pragmata to apply.

Modified cortav.lua from [cf364bf145] to [70cf5fbd0d].

   362    362   			section > figure.listing > hr {
   363    363   				border: none;
   364    364   				margin: 0;
   365    365   				height: 0.7em;
   366    366   				counter-increment: line-number;
   367    367   			}
   368    368   		]];
          369  +		toc = [[
          370  +
          371  +		]];
          372  +		tocFixed = [[
          373  +			@media (min-width: calc(@[width]:[100vw] + 20em)) {
          374  +				ol.toc {
          375  +					position: fixed;
          376  +					padding-top: 1em; padding-bottom: 1em;
          377  +					padding-right: 1em;
          378  +					margin-top: 0; margin-bottom: 0;
          379  +					right: 0; top: 0; bottom: 0;
          380  +					max-width: calc(50vw - ((@[width]:[0]) / 2) - 3.5em);
          381  +					overflow-y: auto;
          382  +				}
          383  +				@media (max-width: calc(@[width]:[100vw] + 30em)) {
          384  +					ol.toc {
          385  +						max-width: calc(100vw - ((@[width]:[0])) - 9.5em);
          386  +					}
          387  +					body {
          388  +						margin-left: 5em;
          389  +					}
          390  +				}
          391  +			}
          392  +		]];
   369    393   	}
   370    394   
   371    395   	local stylesNeeded = {}
   372    396   
   373    397   	local function getSpanRenderers(tag,elt)
   374    398   		local htmlDoc = function(title, head, body)
   375    399   			return [[<!doctype html>]] .. tag('html',nil,
................................................................................
   467    491   			htmlDoc = htmlDoc;
   468    492   		}
   469    493   	end
   470    494   
   471    495   
   472    496   	local function getBlockRenderers(tag,elt,sr,catenate)
   473    497   		local function insert_toc(b,s)
   474         -			local lst = {tag = 'ol', attrs={}, nodes={}}
          498  +			local lst = {tag = 'ol', attrs={class='toc'}, nodes={}}
          499  +			stylesNeeded.toc = true
          500  +			if opts['width'] then
          501  +				stylesNeeded.tocFixed = true
          502  +			end
   475    503   			local stack = {lst}
   476    504   			local top = function() return stack[#stack] end
   477    505   			local all = s.origin.doc.secorder
   478    506   			for i, sec in ipairs(all) do
   479    507   				if sec.heading_node then
   480    508   					local ent = tag('li',nil,
   481    509   						 catenate{tag('a', {href='#'..getSafeID(sec)},
................................................................................
   757    785   					l,sep,sat = param:match('^%('..string.rep('([^%s]*)%s*',i)..'%)$')
   758    786   					if l then break end
   759    787   				end
   760    788   				l = ss.math.lerp(tonumber(l), tbg, tfg)
   761    789   				return tone(l, tonumber(sat), tonumber(sep), tonumber(alpha))
   762    790   			end
   763    791   		end
          792  +		css = css:gsub('@(%b[]):(%b[])', function(v,d) return opts[v:sub(2,-2)] or v:sub(2,-2) end)
   764    793   		css = css:gsub('@(%w+)/([0-9.]+)(%b())', replace)
   765    794   		css = css:gsub('@(%w+)(%b())', function(a,b) return replace(a,nil,b) end)
   766    795   		css = css:gsub('@(%w+)/([0-9.]+)', replace)
   767    796   		css = css:gsub('@(%w+)', function(a,b) return replace(a,nil,b) end)
   768    797   		return (css:gsub('%s+',' '))
   769    798   	end
   770    799   

Added desk/cortav-view.desktop.tpl version [23a7388a52].

            1  +[Desktop Entry]
            2  +Encoding=UTF-8
            3  +Type=Application
            4  +Icon=accessories-text-editor
            5  +
            6  +Name=CortavView
            7  +Name[x-ranuir]=CortavLocmos

Added desk/cortav-view.sh version [a29a5961ee].

            1  +# note that this file lacks a shebang. there is no compatible way
            2  +# to write a shebang that works across distros, so we're generating
            3  +# the shebang and inserting it into the script at build time.
            4  +# we also do something similar with the path to cortav, in case the
            5  +# executable isn't in $PATH
            6  +
            7  +out=$(mktemp --suffix=.html)
            8  +
            9  +"$cortav_exec" "$1" -o "$out" -m html:width 35em
           10  +
           11  +if test "$BROWSER" != ""; then
           12  +	"$BROWSER" "file://$out"
           13  +else
           14  +	xdg-open "$out"
           15  +fi
           16  +
           17  +# clean up when the browser closes
           18  +sleep 1 # in case of tricksiness
           19  +rm "$out"

Name change from cortav.xml to desk/cortav.xml.


Added desk/velartrill-cortav.xml version [356c2a8842].

            1  +<?xml version="1.0"?>
            2  +<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
            3  +	<mime-type type="text/x-cortav">
            4  +		<comment xml:lang="en">Cortav rich text markup source file</comment>
            5  +		<comment xml:lang="de">Textauszeichnungsformat-Cortav-Datei</comment>
            6  +		<comment xml:lang="de-Latf">𝔗𝔢𝔵𝔱𝔞𝔲𝔰𝔷𝔢𝔦𝔠𝔥𝔫𝔲𝔫𝔤𝔰𝔣𝔬𝔯𝔪𝔞𝔱-ℭ𝔬𝔯𝔱𝔞𝔳-𝔇𝔞𝔱𝔢𝔦</comment>
            7  +		<comment xml:lang="x-ranuir-Latn">hurnim cordaii dalve Cortav</comment>
            8  +		<comment xml:lang="x-ranuir-CR8">   </comment>
            9  +
           10  +		<acronym xml:lang="x-ranuir-CR8"></acronym>
           11  +		<expanded-acronym xml:lang="x-ranuir-CR8"></expanded-acronym>
           12  +
           13  +		<expanded-acronym xml:lang="de-Latf">ℭ𝔬𝔯𝔱𝔞𝔳</expanded-acronym>
           14  +		<acronym xml:lang="de-Latf">ℭ𝔗</acronym>
           15  +
           16  +		<acronym>CT</acronym>
           17  +		<expanded-acronym>Cortav</expanded-acronym>
           18  +
           19  +		<generic-icon>x-office-document</generic-icon>
           20  +		<glob pattern="*.ct"/> <glob pattern="*."/>
           21  +		<glob pattern="*.cortav"/>
           22  +		<magic>
           23  +			<match value="%ct\n" offset="0" type="string"/>
           24  +			<match value="\x03\x07\x3E\x2D" offset="0" type="string"/>
           25  +		</magic>
           26  +	</mime-type>
           27  +	<mime-type type="text/x-cortav-intent">
           28  +		<comment xml:lang="en">Cortav rendering intent file</comment>
           29  +		<comment xml:lang="x-ranuir-Latn">tav cunloci Cortavi</comment>
           30  +		<comment xml:lang="x-ranuir-CR8">  </comment>
           31  +
           32  +		<acronym xml:lang="x-ranuir-CR8"></acronym>
           33  +		<expanded-acronym xml:lang="x-ranuir-CR8"></expanded-acronym>
           34  +
           35  +		<acronym>CTC</acronym>
           36  +		<expanded-acronym>Cortavcun</expanded-acronym>
           37  +
           38  +		<generic-icon>text-x-script</generic-icon>
           39  +		<glob pattern="*.ctc"/> <glob pattern="*."/>
           40  +		<glob pattern="*.cortavcun"/>
           41  +	</mime-type>
           42  +</mime-info>

Modified makefile from [5a68812ac4] to [be343fd9b7].

     1      1   lua != which lua
     2      2   luac != which luac
            3  +sh != which sh
     3      4   
     4      5   extens = $(wildcard ext/*.lua)
     5      6   extens_names ?= $(basename $(notdir $(extens)))
            7  +build = build
            8  +executable = cortav
            9  +
           10  +prefix = $(HOME)/.local
           11  +bin_prefix = $(prefix)/bin
           12  +share_prefix = $(prefix)/share/$(executable)
     6     13   
     7         -cortav: sirsem.lua cortav.lua $(extens) cli.lua
           14  +$(build)/$(executable): sirsem.lua cortav.lua $(extens) cli.lua | $(build)/
     8     15   	@echo ' » building with extensions $(extens_names)'
     9     16   	echo '#!$(lua)' > $@
    10     17   	luac -o - $^ >> $@
    11     18   	chmod +x $@
    12     19   
    13         -cortav.html: cortav.ct cortav
           20  +$(build)/cortav.html: cortav.ct $(build)/$(executable) | $(build)/
    14     21   	./cortav $< -o $@ -m render:format html -y html:fossil-uv
    15     22   
    16     23   .PHONY: syncdoc
    17         -syncdoc: cortav.html
           24  +syncdoc: $(build)/cortav.html
    18     25   	fossil uv add $<
    19     26   	fossil uv sync
           27  +
           28  +.PHONY: clean
           29  +clean:
           30  +	rm -f $(build)/cortav $(build)/cortav.html $(build)/velartrill-cortav-view.desktop $(build)/cortav-view.sh
           31  +
           32  +$(build)/%.sh: desk/%.sh
           33  +	echo >$@ "#!$(sh)"
           34  +	echo >>$@ 'cortav_exec="$(bin_prefix)/$(executable)"'
           35  +	cat $< >> $@
           36  +	chmod +x $@
           37  +
           38  +$(build)/velartrill-cortav-view.desktop: desk/cortav-view.desktop.tpl
           39  +	cp $< $@
           40  +	echo "Exec=$(bin_prefix)/cortav-view.sh" >>$@
           41  +
           42  +%/:
           43  +	mkdir -p $@
           44  +
           45  +.PHONY: install
           46  +install: $(build)/cortav $(build)/cortav-view.sh $(build)/velartrill-cortav-view.desktop | $(bin_prefix)/
           47  +	install $(build)/$(executable)  $(bin_prefix)
           48  +	install $(build)/cortav-view.sh $(bin_prefix)
           49  +	xdg-mime         install desk/velartrill-cortav.xml
           50  +	xdg-desktop-menu install $(build)/velartrill-cortav-view.desktop
           51  +	xdg-mime         default velartrill-cortav-view.desktop text/x-cortav
           52  +
           53  +.PHONY: excise
           54  +excise: $(build)/velartrill-cortav-view.desktop
           55  +	xdg-mime         uninstall desk/velartrill-cortav.xml
           56  +	xdg-desktop-menu uninstall $(build)/velartrill-cortav-view.desktop
           57  +	rm $(bin_prefix)/$(executable)
           58  +	rm $(bin_prefix)/cortav-view.sh
           59  +
           60  +.PHONY: wipe
           61  +wipe: excise clean