Overview
Comment: | various updates fuck man idr what all i did |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
c0bdfa46dfc5d4df9190c39199318c0e |
User & Date: | lexi on 2022-04-17 21:16:05 |
Other Links: | manifest | tags |
Context
2022-09-05
| ||
18:49 | add blockquote support for html, subdocument mechanisms, mode to generate epub-compatible XHTML5; various fixes and improvements check-in: 35ea3c5797 user: lexi tags: trunk | |
2022-04-17
| ||
21:16 | various updates fuck man idr what all i did check-in: c0bdfa46df user: lexi tags: trunk | |
2021-12-29
| ||
12:19 | continue iterating on groff renderer; add headings, basic formatting, beginnings of a footnote and link system, colors check-in: 7ba2577283 user: lexi tags: trunk | |
Changes
Modified cortav.ct from [7b2c420807] to [2cc3a528df].
17 17 * [*headings]: cortav uses almost the same syntax for headings that markdown does, except it only allows the "ATX style" headings, with one or more hash characters at the start of the line. the only differences from markdown are: 18 18 ** you can use the unicode section character [`§] instead of [`#] if you're feeling snobby 19 19 ** you must put a space between the control sequence (the sequence of hashes or section symbols, in this case) and the title text. [`# title] creates a section with the heading text "title", but [`#title] creates a new section with no heading at all; instead, it gives the anonymous section the ID [`title]. and of course, you can combine the two: [`#ttl title] creates a section with the heading text "title" and the ID [`ttl]. what are IDs for? we'll get to that in a little bit 20 20 * [*paragraphs] are mostly the same as in markdown, except that a paragraph break occurs after every newline character, not every blank line. paragraphs can be indented by however many spaces you like; such indentation will be ignored. (tabs have a special meaning, however). in cortav, you can also explicitly mark a line of text as a paragraph by preceding it with a period character ([`.]), which is useful if you want to start a paragraph with text that would otherwise be interpreted specially. 21 21 * [*italic text] -- or rather, [!emphasized] text -- is written as [`\[!my spiffy italic text\]]. in cortav, these spans can be nested within other spans (or titles, or table cells, or…), and the starting and ending point is unambiguous. 22 22 * [*bold text] -- or rather, [*strong] text -- is written as [`\[*my commanding bold text\]]. 23 23 * [*bold-italic text] -- or rather, [![*emphasized strong text]] -- has no specific notation. rather, you create it by nesting one span within the other, for instance: [`\[*[!my ostentatious bold-italic text\]]]. 24 -* [*links] are quite different from their markdown equivalents. cortav does not have inline links, as it is intended to be easily readable in both formatted and plain-text format, and long URLs rather disrupt the flow of reading. rather, a link tag is written with the notation [`\[>nifty-link my nifty link\]], where the word [`nifty-link] immediately following the arrow is an [!identifier] indicating the destination of the link. (instead of a greater-than sign, you can also use the unicode arrow symbol [`→].) if the identifier is the same as one you've assigned to a section, cortav produces a link within the document to that section. otherwise, it will look for a [!reference] to tell it the URI for the link. a reference is a key-value pair created by adding a line like [`nifty-link: https://zombo.com] [!indented by exactly one tab]. you can place this reference anywhere you like so long as it's in the same section; if you want to name a reference in another section, you have to prefix it with that section's ID, e.g. [`\[>spiffy-section.nifty-link my nifty link declared in a spiffy section\]]. 24 +* [*links] are quite different from their markdown equivalents. cortav does not have inline links, as it is intended to be easily readable in both formatted and plain-text format, and long URLs rather disrupt the flow of reading. rather, a link tag is written with the notation [`\[>nifty-link my nifty link\]], where the word [`nifty-link] immediately following the arrow is an [!identifier] indicating the destination of the link. (instead of a greater-than sign, you can also use the unicode arrow symbol [`→].) if the identifier is the same as one you've assigned to a document object, such as a section, cortav produces a link within the document to that object. otherwise, it will look for a [!reference] (or failing that, a [>rsrc resource]) to tell it the URI for the link. if nothing in the document matches the ID, an error will result and compilation will be aborted. (a reference is a key-value pair created by adding a line like [`nifty-link: https://zombo.com] [!indented by exactly one tab]. you can place this reference anywhere you like so long as it's in the same section; if you want to name a reference in another section, you have to prefix it with that section's ID, e.g. [`\[>spiffy-section.nifty-link my nifty link declared in a spiffy section\]].) 25 25 * [*lists] use a different syntax from markdown. you can start a line with a [`*] to create an unordered list, or [`:] to create an ordered list; indentation doesn't matter. if you want to nest list items, instead of putting two spaces before the child item, you just add another star or colon. and of course, you can nest lists of different kinds within one another. 26 -* [*horizontal rules] use roughly the same syntax: three or more hyphens on a line of their own ([`\---]). underlines also work ([`___], [`-_-], [`__-__-__] etc). 27 -* some markdown implementations support [*tables]. cortav does too, using a very simple notation. 26 +* [*horizontal rules] use roughly the same syntax: three or more hyphens on a line of their own ([`\---]). underlines also work ([`___], [`-_-], [`__-__-__] etc), as do horizontal unicode box drawing characters ([`─ ━ ┈] etc). 27 +* some markdown implementations support [*tables]. cortav does too, using a very simple notation similar to the usual notation used in markdown. a key difference, however, is that cortav table cells can contain any formatting a paragraph can. 28 28 * [*underlines] are supported by some markdown implementations. in cortav, you can apply them with the notation [`\[_my underlined text\]] -- please just use them sparingly when you render to HTML! 29 29 * [*strikethrough] is supported by some extended versions of markdown. cortav uses the notation [`\[~my deleted text\]], with the intended semantics of text that is being removed by some revision of a document. (you can also denote text that is being [!added] by using a plus sign instead of a tilde) 30 -* [*images] are a bit more complicated. see the section on [>rsrc resources] for an explanation. 30 +* [*images] are a bit more complicated, but much more versatile. see the section on [>rsrc resources] for an explanation. 31 31 * [*smart quotes] and [*em dashes] are inserted automatically, just as in markdown, provided you have the [>tsmog transmogrify] extension available. (it is part of the reference implementation and defined by the spec, but not required.) in fact, you can insert longer dashes than em dashes just by increasing the number of hyphens. the reference implementation's transmogrifier also translates ascii arrows like [`\-->] into their unicode equivalents ([`→]). 32 32 * [*literals] (also known as [*code text]) can be inserted with the [`\[`int main(void);] syntax. note however that literals are not protected from the transmogrifier, and are parsed like any other span, which may cause problems if the source code you're quoting makes use of such forbidden runes. in this case, you'll want to wrap the code span in a raw span. the syntax for this is [`\[`[\\int main(void);\]]], but since this is a bit unwieldy it can also be abbreviated as [`\[`\\int main(void);\]]. 33 33 34 34 of course, this is only a small taste of what cortav can do, not even touching on key features like macros, footnotes, or equation formatting. read the sections on [>onblocks blocks] and [>onspans spans] for all the gory details. 35 35 36 36 ## encoding 37 37 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. ................................................................................ 46 46 47 47 three more extensions are reserved for identifying a cortav intent file. 48 48 * [`ctc] is the shorthand extension 49 49 * [`cortavcun] is the canonical disambiguation extension 50 50 * [`] 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. 51 51 52 52 on systems which use metadata to encode filetype, two values are defined to identify cortav source files 53 -* [`text/x-cortav] should be used when strings or arbitrary byte sequences are supported 53 +* [`text/x.cortav] should be used when strings or arbitrary byte sequences are supported 54 54 * [`CTAV] (that is, the byte sequence [`0x43 54 41 56]) should be used on systems that support only 32-bit file types/4-character type codes like Classic Mac OS. 55 55 56 56 two more values are defined to identify cortav intent files. 57 -* [`text/x-cortav-intent] 57 +* [`text/x.cortav-intent] 58 58 * [`CTVC] (the byte sequence [`0x43 54 56 43]) 59 59 60 -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. 60 +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. 61 61 62 -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. 62 +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. currently, only sequences for UTF-8 and ASCII are defined, as these are the only encodings supported by the reference implementation. in the event that other implementations add support for other encodings, their sequences will be standardized here. 63 63 * for UTF-8 and ASCII plain text files, [`%ct[!\\n]] (that is, the byte sequence [`0x25 63 74 0A]) should be used 64 -* for C6B+PS files (parastream), the file should begin with the paragraph [`], which equates to the byte sequence [` 0x3E 2E 14 0C 01 04 00 00 00 03 07 3E 2D], including the parastream header). 65 64 consequently, this sequence should be ignored by a cortav parser at the start of a file (except as an indication of file format). 66 65 67 66 for FreeDesktop-based systems, the [`build/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. [`$ make install] will generate the necessary FreeDesktop XML files and register them, as well as install the script and the [`cortav] executable itself. for more information see [>refimpl-build building the reference implementation]. 68 67 68 +##levels levels 69 +not all of cortav's features make sense in every context. for this reason, cortav defines N [!levels] of compliance. for example, a social media platform that enables simple paragraph styling and linking using cortav syntax may claim to be "cortav level 1 compliant". every level [=N] is a strict superset of level [=N-1]. 70 +* level 1: [*styling]. simple inline formatting sequences like strong, emphatic, literal, links, etc. math equation styling need not be supported. paragraphs, lists, and references are the only block elements supported. suitable for styling tweets and other very short content. 71 +* level 2: [*layout]. implements header, paragraph, newline, directive, and reference block elements. supports resources at least for remote or attached images. suitable for longer social media posts. 72 +* level 3: [*publishing]. implements all currently standardized core behavior, including zero or more extensions. 73 +* level 4: [*reference]. implements all currently standardized behavior, including [!all] standardized extensions. 74 + 75 +! note that which translators are implemented is not specified by level, as this is, naturally, implementation-dependent. (it would make rather little sense for the blurb parser of a cortav-enabled blog engine to support generating PDFs, after all.) level encodes only which features of the cortav [!language] are supported. 76 + 69 77 ##onblocks structure 70 -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. 78 +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. hard-wrapping lines is incredibly user-hostile, especially to users on mobile devices with small screens. cortav does not allow it. 71 79 72 80 the first character(s) of every line (the "control sequence") indicates the role of that line. if no control sequence is recognized, the line is treated as a paragraph. the currently supported 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. 73 81 74 82 * [*paragraphs] ([`.] [` ¶] [`❡]): a paragraph is a simple block of text. the period control sequence is only necessary if the paragraph text starts with text that would be interpreted as a control sequence otherwise 75 83 * newlines [` \\]: inserts a line break into previous paragraph and attaches the following text. mostly useful for poetry or lyrics 76 -* [*section starts] [`#] [`§]: starts a new section. all sections have an associated depth, determined by the number of sequence repetitions (e.g. "###" indicates depth-three"). sections may have headers and IDs; both are optional. IDs, if present, are a sequence of raw-text immediately following the hash marks. if the line has one or more space character followed by styled-text, a header will be attached. the character immediately following the hashes can specify a particular type of section. e.g.: 84 +* [*section starts] [`#] [`§]: starts a new section. all sections have an associated depth, determined by the number of sequence repetitions (e.g. "###" indicates depth three). sections may have headers and IDs; both are optional. IDs, if present, are a sequence of raw-text immediately following the hash marks. if the line has one or more space character followed by styled-text, a header will be attached. the character immediately following the hashes can specify a particular type of section. e.g.: 77 85 ** [`#] is a simple section break. 78 86 ** [`#anchor] opens a new section with the ID [`anchor]. 79 87 ** [`# header] opens a new section with the title "header". 80 88 ** [`#anchor header] opens a new section with both the ID [`anchor] and the title "header". 81 -* [*nonprinting sections] ([`^]): sometimes, you'll want to create a namespace without actually adding a visible new section to the document. you can achieve this by creating a [!nonprinting section] and defining resources within it. nonprinting sections can also be used to store comments, notes, or other information that is useful to have in the source file without it becoming a part of the output 82 -* [*resource] ([`@]): defines a [!resource]. a resource is an file or object that exists outside of the document but which will be included in the document somehow. common examples of resources include images, videos, iframes, or headers/footers. see [>rsrc resources] for more information. 83 -* [*lists] ([`*] [`:]): these are like paragraph nodes, but list nodes that occur next to each other will be arranged so as to show they compose a sequence. depth is determined by the number of stars/colons. like headers, a list entry may have an ID that can be used to refer back to it; it is indicated in the same way. if colons are used, this indicates that the order of the items is signifiant. :-lists and *-lists may be intermixed; however, note than only the last character in the sequence actually controls the depth type. 84 -* [*directives] ([`%]): a directive issues a hint to the renderer in the form of an arbitrary string. directives are normally ignored if they are not supported, but you may cause a warning to be emitted where the directive is not supported with [`%!] or mark a directive critical with [`%!!] so that rendering will entirely fail if it cannot be parsed. 89 +* [*nonprinting sections] ([`^]): sometimes, you'll want to create a namespace without actually adding a visible new section to the document. you can achieve this by creating a [!nonprinting section] and defining resources within it. nonprinting sections can also be used to store comments, notes, to-dos, or other meta-information that is useful to have in the source file without it becoming a part of the output. nonprinting sections can be used for a sort of "literate markup," where resource and reference definitions can intermingle with human-readable narrative about those definitions. 90 +* [*resource] ([`@]): defines a [!resource]. a resource is a file or object that exists outside of the document but which will are to be included in the document somehow. common examples of resources include images, videos, iframes, or headers/footers. see [>rsrc resources] for more information. 91 +* [*lists] ([`*] [`:]): these are like paragraph nodes, but list nodes that occur next to each other will be arranged so as to show they compose a sequence. depth is determined by the number of stars/colons. like headers, a list entry may have an ID that can be used to refer back to it; it is indicated in the same way. if colons are used, this indicates that the order of the items is signifiant. [`:]-lists and [`*]-lists may be intermixed; however, note than only the last character in the sequence actually controls the type. a blank line terminates the current list. 92 +* [*directives] ([`%]): a directive issues a hint to the renderer in the form of an arbitrary string. directives are normally ignored if they are not supported, but you may cause a warning to be emitted where the directive is not supported with [`%!] or mark a directive critical with [`%!!] so that rendering will entirely fail if it cannot be obeyed. 85 93 * [*comments] ([`%%]): a comment is a line of text that is simply ignored by the renderer. 86 94 * [*asides] ([`!]): indicates text that diverges from the narrative, and can be skipped without interrupting it. think of it like block-level parentheses. asides which follow one another are merged as paragraphs of the same aside, usually represented as a sort of box. if the first line of an aside contains a colon, the stretch of styled-text from the beginning to the aside to the colon will be treated as a "type heading," e.g. "Warning:" 87 95 * [*code] ([`~~~]): a line beginning with ~~~ begins or terminates a block of code. code blocks are by default not parsed, but parsing can be activated by preceding the code block with an [`%[*expand]] directive. the opening line should look like one of the below 88 96 ** [`~~~] 89 97 ** [`~~~ language] (markdown-style shorthand syntax) 90 98 ** [`~~~ \[language\] ~~~] (cortav syntax) 91 99 ** [`~~~ \[language\] #id ~~~] ................................................................................ 92 100 ** [`~~~ title ~~~] 93 101 ** [`~~~ title \[language\] ~~~] 94 102 ** [`~~~ \[language\] title ~~~] 95 103 ** [`~~~ title \[language\] #id ~~~] 96 104 *[*reference] (tab): a line beginning with a tab is treated as a "reference." references hold out-of-line metadata for preceding text like links and footnotes. a reference consists of an identifier followed by a colon and an arbitrary number of spaces or tabs, followed by text. whether this text is interpreted as raw-text or styled-text depends on the context in which the reference is used. in encodings without tab characters, two preceding blanks can be used instead. 97 105 * [*quotation] ([`<]): a line of the form [`<[$name]> [$quote]] denotes an utterance by [$name]. 98 106 * [*blockquote] ([`>]): alternate blockquote syntax. can be nested by repeating the [`>] character. 99 -* [*subtitle] ([`--]): attaches a subtitle to the previous header 107 +* [*subtitle/caption] ([`\--]): attaches a subtitle to the previous header, or caption to the previous object 100 108 * [*embed] ([`&]): embeds a referenced object. can be used to show images or repeat previously defined objects like lists or tables, optionally with a caption. 101 109 ** [`&$[$macro] [$arg1]|[$arg2]|[$argn]…] invokes a block-level macro with the supplied arguments 102 110 *** [`&$mymacro arg 1|arg 2|arg 3] 103 111 ** [`&[$image]] embeds an image or other block-level object. [!image] can be a reference with a url or file path, or it can be an embed section (e.g. for SVG files) 104 112 ***[`&myimg All that remained of the unfortunate blood magic pageant contestants and audience (police photo)] 105 -** [`&-[$section] [$styled-text]] embeds a closed disclosure element. in interactive outputs, this will display as a block [!section] which can be clicked on to view the full contents of the referenced section; if [$styled-text] is present, it overrides the title of the section you are embedding. in static outputs, the disclosure object will display as an enclosed box with [$styled-text] as the title text 113 +** [`&-[$ident] [$styled-text]] embeds a closed disclosure element containing the text of the named object (a nonprinting section or cortav resource should usually be used to store the content; it can also name an image or video, of course). in interactive outputs, this will display as a block which can be clicked on to view the full contents of the referenced object [$ident]; if [$styled-text] is present, it overrides the title of the section you are embedding (if any). in static outputs, the disclosure object will display as an enclosed box with [$styled-text] as the title text 106 114 *** [`&-ex-a Prosecution Exhibit A (GRAPHIC CONTENT)] 107 115 ** [`&+[$section] [$styled-text]] is like the above, but the disclosure element is open by default 108 -* [*horizontal rule] ([`\---]): inserts a horizontal rule or other context break; does not end the section. must be followed by newline. underlines can also be used in place of dashes. 109 -* [*page break] ([`\^^]): for formats that support pagination, like HTML (when printed), indicates that the rest of the current page should be blank. for formats that do not, extra margins will be inserted. does not create a new section 110 -* [*page rule] ([`\^-^]): inserts a page break for formats that support them, and a horizontal rule for formats that do not. does not create a new section 116 +* [*horizontal rule] ([`\---]): inserts a horizontal rule or other context break; does not end the section. must be followed by newline. underlines can also be used in place of dashes ([`___], [`-_-], [`__-__-__] etc), as can horizontal unicode box drawing characters ([`─ ━ ┈] etc). 117 +* [*page break] ([`\^^]): for formats that support pagination, like EPUB or HTML (when printed), indicates that the rest of the current page should be blank. for formats that do not, extra margins will be inserted. does not create a new section 118 +* [*page rule] ([`\^-^]): inserts a page break for formats that support them, and a horizontal rule for formats that do not. does not create a new section. comprised of any number of horizontal rule characters surrounded by a pair of carets (e.g. [`^-^] [`^_^] [`^----^] [`^__--^] [`^┈┈┈┈┈^]) 111 119 * [*table cells] ([`+ |]): see [>ex.tab table examples]. 112 -* [*equations] ([`=]) block-level equations can be inserted with the [`=] 120 +* [*equations] ([`=]): block-level equations can be inserted with the [`=] sequence 121 +* [*cross-references] ([`=>] [`⇒]): inserts a block-level link. uses the same syntax as span links ([`⇒[$ident] [$styled-text]]). can be followed by a caption to add a longer descriptive text. especially useful for gemtext output. ident can be omitted to cross-reference, for example, a physical book. 113 122 * [*empty lines] (that is, lines consisting of nothing but whitespace) constitute a [!break], which terminates multiline objects that do not have a dedicated termination sequence, for example lists and asides. 114 123 115 124 ##onspans styled text 116 125 most blocks contain a sequence of spans. these spans are produced by interpreting a stream of [*styled-text] following the control sequence. styled-text is a sequence of codepoints potentially interspersed with escapes. an escape is formed by an open square bracket [`\[] followed by a [*span control sequence], and arguments for that sequence like more styled-text. escapes can be nested. 117 126 118 127 * strong {obj *|styled-text}: causes its text to stand out from the narrative, generally rendered as bold or a brighter color. 119 128 * emphatic {obj !|styled-text}: indicates that its text should be spoken with emphasis, generally rendered as italics ................................................................................ 121 130 * literal {obj `|styled-text}: indicates that its text is a reference to a literal sequence of characters or other discrete token. generally rendered in monospace 122 131 * variable {obj $|styled-text}: indicates that its text is a stand-in that will be replaced with what it names. generally rendered in italic monospace, ideally of a different color 123 132 * underline {obj _|styled-text}: underlines the text. use sparingly on text intended for webpages -- underlined text [!is] distinct from links, but underlining non-links is still a violation of convention. 124 133 * strikeout {obj ~|styled-text}: indicates that its text should be struck through or otherwise indicated for deletion 125 134 * insertion {obj +|styled-text}: indicates that its text should be indicated as a new addition to the text body. 126 135 ** consider using a macro definition [`\edit: [~[#1]][+[#2]]] to save typing if you are doing editing work 127 136 * link \[>[!ref] [!styled-text]\]: produces a hyperlink or cross-reference denoted by [$ref], which may be either a URL specified with a reference or the name of an object like an image or section elsewhere in the document. the unicode characters [`→] and [`🔗] can also be used instead of [`>] to denote a link. 128 -* footnote {span ^|ref|[$styled-text]}: annotates the text with a defined footnote. in interactive output media [`\[^citations.qtheo Quantum Theosophy: A Neophyte's Catechism]] will insert a link with the next [`Quantum Theosophy: A Neophyte's Catechism] that, when clicked, causes a footnote to pop up on the screen. for static output media, the text will simply have a superscript integer after it denoting where the footnote is to be found. 137 +* footnote {span ^|ref|[$styled-text]}: annotates the text with a defined footnote. in interactive output media [`\[^citations.qtheo Quantum Theosophy: A Neophyte's Catechism]] will insert a link with the text [`Quantum Theosophy: A Neophyte's Catechism] that, when clicked, causes a footnote to pop up on the screen. for static output media, the text will simply have a superscript integer after it denoting where the footnote is to be found. 129 138 * superscript {obj '|[$styled-text]} 130 139 * subscript {obj ,|[$styled-text]} 131 140 * raw {obj \\ |[$raw-text]}: causes all characters within to be interpreted literally, without expansion. the only special characters are square brackets, which must have a matching closing bracket, and backslashes. 132 141 * raw literal \[$\\[!raw-text]\]: shorthand for [\[$[\…]]] 133 -* macro [`\{[!name] [!arguments]\}]: invokes a [>ex.mac macro], specified with a reference 142 +* macro [` \{[!name] [!arguments]}]: invokes a [>ex.mac macro], specified with a reference 134 143 * argument {obj #|var}: in macros only, inserts the [$var]-th argument. otherwise, inserts a context variable provided by the renderer. 135 144 * raw argument {obj ##|var}: like above, but does not evaluate [$var]. 136 145 * term {obj &|name}, {span &|name|[$expansion]}: quotes a defined term with a link to its definition, optionally with a custom expansion of the term (for instance, to expand the first use of an acronym) 137 146 * inline image {obj &@|name}: shows a small image or other object inline. the unicode character [`🖼] can also be used instead of [`&@]. 138 147 * unicode codepoint {obj U+|hex-integer}: inserts an arbitrary UCS codepoint in the output, specified by [$hex-integer]. lowercase [`u] is also legal. 139 148 * math mode {obj =|equation}: activates additional transformations on the span to format it as a mathematical equation; e.g. [`*] becomes [`×] and [`/] --> [`÷]. 140 149 * extension {span %|ext|…}: invokes extension named in [$ext]. [$ext] will usually be an extension name followed by a symbol (often a period) and then an extension-specific directive, although for some simple extensions it may just be the plain extension name. further syntax and semantics depend on the extension. this syntax can also be used to apply formatting specific to certain renderers, such as assigning a CSS class in the [`html] renderer ([`\[%html.myclass my [!styled] text]]). ................................................................................ 158 167 159 168 ##ident identifiers 160 169 any identifier (including a reference) that is defined within a named section must be referred to from outside that section as [`[!sec].[!obj]], where [$sec] is the ID of the containing section and [$obj] is the ID of the object one wishes to reference. 161 170 162 171 ##rsrc resources 163 172 a [!resource] represents content that is not encoded directly into the source file, but which is embedded by some means in the output. resources can either be [!embedded], in which case they are compiled into the final document itself, or they can be [!linked], in which case the final document only contains a URI or similar tag referencing the resource. not all render backends support both linking and embedding embedding, nor do all backends support all object types (for instance, [`groff] does not support video embedding.) 164 173 165 -a resource definition is begun by line consisting of an [`@] sign and an [>ident identifier]. this line is followed by any number of parameters. a parameter is a line beginning with a single tab, a keyword, a colon, and a then a value. additional lines can be added to a parameter by following it with a line that consists of two tabs followed by the text you wish to add. (this is the same syntax used by references.) a resource definition is terminated by a break, or any line that does not begin with a tab 174 +a resource definition is begun by line consisting of an [`@] sign and an [>ident identifier]. this line is followed by any number of parameters. a parameter is a line beginning with a single tab, a keyword, a colon, and a then a value. additional lines can be added to a parameter by following it with a line that consists of two tabs followed by the text you wish to add. (this is the same syntax used by references.) a resource definition is terminated by a break, or any line that does not begin with a tab 166 175 167 176 a resource definition in use looks like this: 168 177 169 -~~~ 178 +~~~cortav 170 179 this is a demonstration of resources 171 180 @smiley 172 181 src: link image/webp http://cdn.example.net/img/smile.webp 173 182 link image/png file:img/smile.png 174 183 embed image/gif file img/smile.gif 175 184 desc: the Smiling Man would like to see you in his office 176 185 here is the resource in span context [&smiley] 177 186 and here it is in block context: 178 187 &smiley 179 188 ~~~ 180 189 181 190 rendered as HTML, this might produce the following: 182 191 183 -~~~ 192 +~~~html 184 193 <style> 185 194 .res-smiley { 186 195 content: image-set( 187 196 url(http://cdn.example.net/img/smile.webp) type(image/webp), 188 197 url(img/smile.png) type(image/png), 189 198 url(data:image/gif;base64,/* … */) type(image/gif) 190 199 ); /* this will actually be repeated with a -webkit- prefix */ ................................................................................ 193 202 <p>this is a demonstration of resources</p> 194 203 <p>here is the resource in span context: <span class="res-smiley"></span></p> 195 204 <p>and here it is in block context:</p> 196 205 <div class=".res-smiley"></div> 197 206 ~~~ 198 207 199 208 note that empty elements with CSS classes are used in the output, to avoid repeating long image definitions (especially base64 inline encoded ones!) 209 + 210 +in the opening line of a resource declaration, the identifier can be omitted. in this case, rather than registering a new resource in the current section, the resource will be inserted as a block at the position where it is defined. this is a shorthand for resources that are only used once. for resources used inline or multiple times, an identifier must be defined. 211 + 212 +as an additional shortcut, a resource with only one source file can place its source specification on the opening line, separated by whitespace from the opening sequence. this means that the following are identical. 213 + 214 +~~~cortav 215 +@smiley link image/webp file:smile.webp 216 + desc: the Smiling Man would like to see you in his office 217 + 218 +@smiley 219 + src: link image/webp file:smile.webp 220 + desc: the Smiling Man would like to see you in his office 221 +~~~ 222 + 223 +this can be combined with ID omission for a very concise block-level image syntax. 224 + 225 +~~~cortav 226 +@smiley 227 + src: link image/webp file:smile.webp 228 +&smiley 229 + 230 +%% is the same as 231 + 232 +@smiley link image/webp file:smile.webp 233 +&smiley 234 + 235 +%% is the same as 236 + 237 +@ link image/webp file:smile.webp 238 + 239 +%% is almost the same as 240 + 241 +@ image/webp;base64 (* 242 + %% inhuman gurgling in textual form 243 +*) 244 + 245 +%% (except that the last wil require embedding) 246 +~~~ 200 247 201 248 inline resources are defined a bit differently: 202 249 203 250 ~~~cortav 204 251 @smiling-man-business-card text/plain { 205 252 THE SMILING MAN | tel. 0-Ω00-666█ 206 253 if you can read this | email: nameless@smiles.gov ................................................................................ 209 256 @smiling-man-business-card image/png;base64 { 210 257 %% incomprehensible gibbering redacted 211 258 } 212 259 ~~~ 213 260 214 261 for an inline resource, the identifier is followed by a MIME type and an opening bracket. the opening bracket may be any of the characters [`\{][`\[][`(][`<], and can optionally be followed by additional characters to help disambiguate the closing bracket. the closing bracket is determined by "flipping" the opening bracket, producing bracket pairs like the following: 215 262 * [`\{:][`:}] 216 -* [`<!--] [`--!>] 263 +* [`\<!--] [`\--!>] 217 264 * [`(*<][`>*)] 218 265 * [`<>][`<>] [!(disables nesting!)] 219 -if the open and closing brackets are distinguishable, they will nest appropriately, meaning that [`{][`}] alone is very likely to be a safe choice to escape a syntactically correct C program (that doesn't abuse macros too badly). brackets are searched for during parsing; encoded resources are not decoded until a later stage, so a closing bracket character in a base64-encoded text file cannot break out of its escaping. 266 +if the open and closing brackets are distinguishable, they will nest appropriately, meaning that [`\{][`\}] alone is very likely to be a safe choice to escape a syntactically correct C program (that doesn't abuse macros too badly). brackets are searched for during parsing; encoded resources are not decoded until a later stage, so a closing bracket character in a base64-encoded text file cannot break out of its escaping. 220 267 221 268 as a convenience, if the first line of the resource definition begins with a single tab, one tab will be dropped from every following line in order to allow legible indentation. similarly, if an opening bracket is followed immediately by a newline, this newline is discarded. 222 269 223 -text within a resource definition body is not expanded unless the resource definition is preceded with an [`%[*expand]] directive. if an expand directive is found, the MIME type will be used to try and determine an appropriate type of formatting, potentially invoking a separate renderer. for example, [`text/html] will invoke the [`html] backend, and [`application/x-troff] will invoke the [`groff] backend. if no suitable renderer is available, expansions will generate only plain text. 270 +text within a resource definition body is not expanded unless the resource definition is preceded with an [`%[*expand]] directive or the resource MIME type is [`text/x.cortav]. if an expand directive is found, the MIME type will be used to try and determine an appropriate type of formatting, potentially invoking a separate renderer. for example, [`text/html] will invoke the [`html] backend, and [`application/x-troff] will invoke the [`groff] backend. if no suitable renderer is available, expansions will generate only plain text. 224 271 225 272 two suffixes are accepted: [`;base64] and [`;hex]. the former will decode the presented strings using the base64 algorithm to obtain the resources data; the second will ignore all characters but ASCII hexadecimal digits and derive the resource data byte-by-byte by reading in hexadecimal pairs. for instance, the following sections are equivalent: 226 273 227 -~~~ 274 +~~~cortav 228 275 @propaganda text/plain { 229 276 WORLDGOV SAYS 230 277 “don't waste time with unproductive thoughts 231 278 your wages will be docked accordingly” 232 279 } 233 280 ~~~ 234 -~~~ 281 +~~~cortav 235 282 @propaganda text/plain;hex { 236 283 574f 524c 4447 4f56 2053 4159 530a e280 9c64 6f6e 2774 2077 6173 237 284 7465 2074 696d 6520 7769 7468 2075 6e70 726f 6475 6374 6976 6520 238 285 7468 6f75 6768 7473 0a20 796f 7572 2077 6167 6573 2077 696c 6c20 239 286 6265 2064 6f63 6b65 6420 6163 636f 7264 696e 676c 79e2 809d 0a 240 287 } 241 288 ~~~ 242 -~~~ 289 +~~~cortav 243 290 @propaganda text/plain;base64 { 244 291 V09STERHT1YgU0FZUwrigJxkb24ndCB3YXN0ZSB0aW1lIHdpdGggdW5wcm9kdWN0aXZlIHRob3Vn 245 292 aHRzCiB5b3VyIHdhZ2VzIHdpbGwgYmUgZG9ja2VkIGFjY29yZGluZ2x54oCdCg== 246 293 } 247 294 ~~~ 248 295 249 -inline resources can also be (ab)used for multiline macros: 250 -~~~ 251 -@def text/x-cortav { 296 +inline resources can also offer a cleaner syntax for complex multiline macros. 297 +~~~cortav 298 +@def text/x.cortav { 252 299 * [*[#1]] [!([#2]) 253 300 *: [#3] 254 301 } 255 302 &def nuclear bunker|n|that which will not protect you from the Smiling Man 256 303 ~~~ 257 -to make this usage simpler, resources with a type of [`text/x-cortav] can omit the MIME type field. 304 +to make this usage simpler, resources with a type of [`text/x.cortav] can omit the MIME type field. 305 + 306 +inline resources are a great way to extend cortav with implementation-dependent features. say you want mathtex in your cortav renderer -- all you have to do is support a new MIME type [`text/x.mathtex], and then the users can embed their math equations like so: 307 + 308 +~~~cortav 309 +and as we see from the value of κ below, Bose-Fleischer-Kincaid entities of Carlyle subtype γ lack interaction with the putative "Higgs field" of Athabaskan Windchime Theory, seemingly ruling out any possibility of direct interaction with the spacetime metric, and consequently removing the maximal density "limitations" that exist for bosonic matter. 310 +@ text/x.mathtex {> 311 + %% divide subtract differentiate blah blah blah i don't know math 312 +<} 313 +given the selective cross-interaction of γ-BFKs, we conclude that, under the prevailing cosmocelestial paradigm, the answer to the age-old question of how many angels can dance on the head of a pin is "as many as would like to." 314 +~~~ 258 315 259 316 ### supported parameters 260 -* [`src] (all): specifies where to find the file, what it is, and how to embed it. each line of [`src] should consist of three whitespace-separated words: embed method, MIME type, and URI. 261 -** embed methods 262 -*** [`local]: loads the resource at build time and embeds it into the output file. not all implementations may allow loading remote network resources at build time. 263 -*** [`remote]: only embeds a reference to the location of the resource. use this for e.g. live iframes, dynamic images, or images hosted by a CDN. 264 -*** [`auto]: embeds a reference in file formats where that's practical, and use a remote reference otherwise. 317 +* [`src] (all): specifies where to find the file, what it is, and how to embed it. each line of [`src] should consist of two whitespace-separated words: MIME type and URI. the specification can also be prefixed with an extra word, [`auto], [`link], or [`embed], to control how the resource will be referenced from the output file. 318 +** reference mode: the optional first word; if the requested reference mode is not applicable or valid for the output format or URI given, the source line will be skipped over. 319 +*** [`embed]: loads the resource at build time and embeds it into the output file. not all implementations may allow loading remote network resources at build time. 320 +*** [`link]: only embeds a reference to the location of the resource. use this for e.g. live iframes, dynamic images, or images hosted by a CDN. 321 +*** [`auto]: embeds a reference in file formats where that's practical, and use a remote reference otherwise. [`auto] is the default if the first word is omitted. 265 322 ** MIME types: which file types are supported depends on the individual implementation and renderer backend; additionally, extensions can add support for extra types. MIME-types that have no available handler will, where possible, result in an attachment that can be extracted by the user, usually by clicking on a link. however, the following should be usable with all compliant implementations 266 323 *** [`image/*] (graphical outputs only) 267 324 *** [`video/*] (interactive outputs only) 268 325 *** [`image/svg+xml] is handled specially for HTML files, and may or may not be compatible with other renderer backends. 269 326 *** [`font/*] can be used with the HTML backend to reference a web font 270 327 *** [`font/woff2] can be used with the HTML backend to reference a web font 271 328 *** [`text/plain] (will be inserted as a preformatted text block) 272 329 *** [`text/css] (can be used when producing HTML files to link in an extra stylesheet, either by embedding it or referencing it from the header) 273 -*** [`text/x-cortav] (will be parsed and inserted as a formatted text block; context variables can be passed to the file with [`ctx.[$var]] parameters) 330 +*** [`text/x.cortav] (will be parsed and inserted as a formatted text block; context variables can be passed to the file by setting [`ctx.[$var]] parameters on the resource, e.g. [`ctx.recipient-name: Mr. Winthrop]) 274 331 *** [`application/x-troff] can be used to supply sections of text written in raw [`groff] syntax. these are ignored by other renderers. 275 -*** [`text/html] can be used to supply sections of text written in raw HTML. 332 +*** [`text/html] can be used to supply sections of text written in raw HTML. these are ignored by non-HTML outputs. 276 333 *** any MIME-type that matches the type of file being generated by the renderer can be used to include a block of data that will be passed directly to the renderer. 277 334 ** URI types: additional URI types can be added by extensions or different implementations, but every compliant implementation must support these URIs. 278 -*** [`http], [`https]: accesses resources over HTTP. add a [`file] fallback if possible for the benefit of renderers/viewers that do not have internet access abilities. 279 -*** [`file]: references local files. absolute paths should begin [`file:/]; the slash should be omitted for relative paths. note that this doesn't have quite the same meaning as in HTML -- [`file] can (and usually should be) used with HTML outputs to refer to resources that reside on the same server. a cortav URI of [`file:/etc/passwd] will actually result in the link [`/etc/passwd], not [`file:///etc/passwd] when converted to HTML. generally, you only should use [`http] when you're referring to a resource that exists on a different domain. 335 +*** [`http], [`https]/[`http+tls]: accesses resources over HTTP. add a [`file] fallback if possible for the benefit of renderers/viewers that do not have internet access abilities. 336 +*** [`file]: references local files. (the meaning of "local" varies depending on the translation format.) absolute paths should begin [`file:/]; the slash should be omitted for relative paths. note that this doesn't have quite the same meaning as in HTML -- [`file] can (and usually should be) used with HTML outputs to refer to resources that reside on the same server. a cortav URI of [`file:/etc/passwd] will actually result in the link [`/etc/passwd], not [`file:///etc/passwd] when converted to HTML. generally, you only should use [`http] when you're referring to a resource that exists on a different domain. 280 337 *** [`name]: a special URI used generally for referencing resources that are already installed on a target system and do not need to be embedded or linked, the name and type are enough for a renderer on another machine to locate the correct resource. this is useful mostly for [>fonts fonts], where it's more typical to refer to fonts that are installed on your system rather than providing paths to font files. 281 338 *** [`gemini]: accesses resources over the gemini protocol. currently you should really only use this for [`local] resources unless you're using the gemtext renderer backend, since nothing but gemini browsers are liable to support this protocol. 339 +*** [`role]: specifies an abstract resource determined by context, e.g. [`role:backdrop], [`role:body-font]. for use by translators to formats which make provisions for viewer control. a [`role] URI is special in that it is never embedded; it always depends on context — user preferences, environment variables, system stylesheets, what have you — at the time the output file is viewed, rather than the time of the input file being rendered. 282 340 * [`desc]: supplies a narrative description of the resources, for use as an "alt-text" when the image cannot be loaded and for screenreaders. 283 341 * [`detail]: supplies extra narrative commentary that is displayed contextually, e.g. when the user hovers her mouse cursor over the embedded object. also used for [`desc] if [`desc] is not supplied. 284 342 285 343 note that in certain cases, full MIME types do not need to be used. say you're defining a font with the [`name] URI -- you can't necessary know what file type the system fonts on another computer are going to be. in this case, you can just write [`font] instead of [`font/ttf] or [`font/woff2] or similar. all cortav needs to know in this case is what abstract kind of object you're referencing. [`groff] fonts (referenced with the [`dit] URI) don't have a specific MIME type either. 286 344 287 345 288 346 ##ctxvar context variables ................................................................................ 307 365 308 366 when a document parse begins, the font stack is empty (unless a default font has already been loaded by an intent file). 309 367 when the font stack is empty, cortav does not include font specifications in its output, and thus will use whatever the default of the various rendering programs is. 310 368 311 369 to use fonts, we first have to define the fonts as [>rsrc resources]. 312 370 313 371 ~~~cortav 314 -%% first, we create a new section to namespace the fonts 315 -#^fonts 316 -%% we then define each font as a resource 372 +%% first, we create a new nonprinting section to namespace the fonts 373 +^fonts 374 +we then define each font as a resource: 317 375 @serif 318 376 src: auto font name:Alegreya 319 377 embed font/ttf file:project-fonts/alegreya.ttf 320 378 link font/woff2 file:/assets/font/alegreya.woff2 321 379 auto font name:Times New Roman 322 380 auto font dit:TR/bold=TRB/italic=TRI/bold,italic=TRBI 323 381 @sans ................................................................................ 340 398 font-family: "fontdef-sans"; 341 399 src: local("Alegreya Sans"), 342 400 local("Open Sans"), 343 401 local("sans-serif"); 344 402 } 345 403 ~~~ 346 404 347 -there are two things that aren't super clear from the CSS, however. notice how we used [`auto] on a couple of those specs? this means it's up to the renderer to decide whether to link or embed the font. in HTML, a font specified by name can't really be embedded, but for some file formats, it can be. [`auto] lets us produce valid HTML while still taking advantage of font embedding in other formats. 405 +there are two things that aren't super clear from the CSS, however. notice how we used [`auto] on a couple of those specs? this means it's up to the renderer to decide whether to link or embed the font. [!in HTML], a font specified by name can't really be embedded, but for some translation formats such as PDF or PostScript, a system font can be selected by name and then embedded into the output. [`auto] lets us produce valid HTML while still taking advantage of font embedding in other formats. 348 406 349 -now that we have our font families defined, we can use their identifiers with the [`%[*font]] directive to control the font stack. the first thing we need to do is push a new font context. there's two ways we can do this: 407 +now that we have our font families defined, we can use their identifiers with the [`%[*font]] directive to control the font stack. the first thing we need to do is push a new font context, as the stack starts out empty. there's two ways we can do this: 350 408 fnd: [`%[*font] [#1]] 351 409 * {fnd dup} will create a copy of the current font context, allowing us to make some changes and then revert later with the {fnd pop} command. this isn't useful in our case, however, because right now the stack is empty; there's nothing to duplicate. 352 410 * {fnd new} will create a brand new empty context for us to work with and push it to the stack. this can also be used to temporarily revert to the system default fonts, and then switch back with {fnd pop}. 353 411 * {fnd set} changes one or more entries in the current font context. it can take a space-separated list of arguments in the form [`[$entry]=[$font-id]]. the supported entries are: 354 412 ** [`body]: the fallback font. if only this is set in a given font context, it will be used for everything 355 413 ** [`paragraph]: the font used for normal paragraphs 356 414 ** [`header]: the font used in headers ................................................................................ 452 510 * {d include} transcludes another file 453 511 * {d import} reads in the contents of another file as an embeddable section 454 512 * {d quote} transcludes another file, without expanding the text except for paragraphs 455 513 * {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. 456 514 * {d expand} causes the next object (usually a code block) to be fully expanded when it would otherwise not be 457 515 * {d font} controls the font stack, for outputs that support changing fonts. see [>fonts fonts] for more information. 458 516 * {d lang} changes the current language, which is used by extensions to e.g. control typographical conventions, and may be encoded into the output by certain renderers (e.g. HTML). note that quotes and blockquotes can be set to a separate language with a simpler syntax. the language should be notated using IETF language tags 459 -** {d lang is x-ranuir-Cent-CR8} sets the current language to Ranuir as spoken in the Central Worlds, written in Corran and encoded using UTF-8. this might be used at the top of a document to set its primary language. 517 +** {d lang is x-ranuir-Cent-CR8} sets the current language to Ranuir as spoken in the Central Worlds, written in Corran and encoded using C6B+U8L (which can also be interpreted as UTF-8, albeit with some lost semantics). this might be used at the top of a document to set its primary language. 460 518 ** {d lang push gsw-u-sd-chzh} temporarily switches to Zürich German, e.g. to quote a German passage in an otherwise Ranuir document 461 519 ** {d lang sec en-US} switches to American English for the duration of a section. does not affect the language stack. 462 520 ** {d lang pop} drops the current language off the language stack, returning to whatever was pushed or set before it. this would be used, for instance, at the end of a passage 463 521 * {d pragma} supplies semantic data about author intent, the kind of information the 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. 464 522 ** {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: 465 523 *** [`essay] 466 524 *** [`narrative] ................................................................................ 771 829 772 830 corran: http://ʞ.cc/fic/spirals/society 773 831 tengwar: https://en.wikipedia.org/wiki/Tengwar 774 832 775 833 ###refimpl-switches switches 776 834 [`cortav.lua] offers various switches to control its behavior. 777 835 + long + short + function + 778 -| [`--out [!file]] :|:[`-o]:| sets the output file (default stdout) | 779 -| [`--log [!file]] :|:[`-l]:| sets the log file (default stderr) | 780 -| [`--define [!var] [!val]] :|:[`-d]:| sets the context variable [$var] to [$val] | 781 -| [`--mode-set [!mode]] :|:[`-y]:| activates the [>refimpl-mode mode] with ID [!mode] 782 -| [`--mode-clear [!mode]] :|:[`-n]:| disables the mode with ID [!mode] | 783 -| [`--mode [!id] [!val]] :|:[`-m]:| configures mode [!id] with the value [!val] | 784 -| [`--mode-set-weak [!mode]] :|:[`-Y]:| activates the [>refimpl-mode mode] with ID [!mode] if the source file does not specify otherwise 785 -| [`--mode-clear-weak [!mode]] :|:[`-N]:| disables the mode with ID [$mode] if the source file does not specify otherwise 786 -| [`--mode-weak [!id] [!val]] :|:[`-M]:| configures mode [$id] with the value [$val] if the source file does not specify otherwise 787 -| [`--help] :|:[`-h]:| display online help | 788 -| [`--version] :|:[`-V]:| display the interpreter version | 836 +| [`\--out [!file]] :|:[`-o]:| sets the output file (default stdout) | 837 +| [`\--log [!file]] :|:[`-l]:| sets the log file (default stderr) | 838 +| [`\--define [!var] [!val]] :|:[`-d]:| sets the context variable [$var] to [$val] | 839 +| [`\--mode-set [!mode]] :|:[`-y]:| activates the [>refimpl-mode mode] with ID [!mode] 840 +| [`\--mode-clear [!mode]] :|:[`-n]:| disables the mode with ID [!mode] | 841 +| [`\--mode [!id] [!val]] :|:[`-m]:| configures mode [!id] with the value [!val] | 842 +| [`\--mode-set-weak [!mode]] :|:[`-Y]:| activates the [>refimpl-mode mode] with ID [!mode] if the source file does not specify otherwise 843 +| [`\--mode-clear-weak [!mode]] :|:[`-N]:| disables the mode with ID [$mode] if the source file does not specify otherwise 844 +| [`\--mode-weak [!id] [!val]] :|:[`-M]:| configures mode [$id] with the value [$val] if the source file does not specify otherwise 845 +| [`\--help] :|:[`-h]:| display online help | 846 +| [`\--version] :|:[`-V]:| display the interpreter version | 789 847 790 848 ###refimpl-mode modes 791 849 most of [`cortav.lua]'s implementation-specific behavior is controlled by use of [!modes]. these are namespaced options which may have a boolean, string, or numeric value. boolean modes are set with the [`-y] [`-n] flags; other modes use the [`-m] flags. 792 850 793 851 most modes are defined by the renderer backend. the following modes affect the behavior of the frontend: 794 852 795 853 + ID + type + effect ................................................................................ 869 927 if the [`toc] extension is active but [`%[*toc]] directive is provided, the table of contents will be given its own section at the start of the document (after the title page, if any). 870 928 871 929 ## further directions 872 930 873 931 ### additional backends 874 932 it is eventually intended to support to following backends, if reasonably practicable. 875 933 * [*html]: emit HTML and CSS code to typeset the document. [!in progress] 876 -* [*svg]: emit SVG, taking advantage of its precise layout features to produce a nicely formatted and paginated document. pagination can be accomplished through emitting multiple files or by assigning one layer to each page. [!long term] 877 -* [*groff]: the most important output backend, rivalling [*html]. will allow the document to be typeset in a wide variety of formats, including PDF and manpage. [!short term] 934 +* [*svg]: emit SVG, taking advantage of its precise layout features to produce a nicely formatted and paginated document. pagination can perhaps be accomplished through emitting multiple files (somewhat problematic) or by assigning one layer to each page. [!long term] 935 +* [*groff]: the most important output backend, rivalling [*html]. will allow the document to be typeset in a wide variety of formats, including PDF and manpage. [!in progress] 878 936 * [*gemtext]: essentially a downrezzing of cortav to make it readable to Gemini clients 879 937 * [*ast]: produces a human- and/or machine-readable dump of the document's syntax tree, to aid in debugging or for interoperation with systems that do not support `cortav` direcly. mode [`ast:repr] wil allow selecting formats for the dump. [`ast:rel] can be [`tree] (the default) to emit a hierarchical representation, or [`flat] to emit an array of nodes that convey hierarchy [^flatdoc by naming one another], rather than being placed inside one another. [`tree] is easier for humans to parse; [`flat] is easier for computers. origin information can be included for each node with the flag [`ast:debug-syms], but be aware this will greatly increase file size. 880 938 ** [`tabtree] [!(default)]: a hierarchical tree view, with the number of tabs preceding an item showing its depth in the tree 881 939 ** [`sexp] 882 940 ** [`binary]: emit a raw binary format that is easier for programs to read. maybe an lmdb or cdb file? 883 -** [`json] 941 +** [`json]: obligatory, alas 884 942 885 943 flatdoc: ~~~flat sexp example output [scheme]~~~ 886 944 (nodes 887 945 (section (id . "section1") 888 946 (anchor "introduction") 889 947 (kind . "ordinary") 890 948 (label . "section1-heading") ................................................................................ 951 1009 ### LCH support 952 1010 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. 953 1011 954 1012 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. 955 1013 956 1014 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. 957 1015 958 -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?? 1016 +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. groff lets us choose between [`rgb] and [`cmyk] for specifying color, with no explanation of what those mean. 1017 + 1018 +currently all internal colors are expressed and stored as HSL, and we're using code borrowed from my Minetest mod [`[>sorcrep sorcery]] & written by glowpelt for converting that into RGB for non-HTML outputs like groff. probably what should be done is to switch to LCH internally, accept both HSL and LCH input, and "downres" to the best representation each format can support. that's probably going to have to wait until someone who knows a bit more about color theory and math than me can do it (paging Lea Verou) 1019 + 1020 + sorcrep: https://c.hale.su/sorcery 959 1021 960 1022 ### intent files 961 1023 there's currently no standard way to describe the intent and desired formatting of a document besides placing pragmata 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. 962 1024 963 1025 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. 964 1026 965 1027 intent files should also be able to define [>rsrc resources], [>ctxvar context variables], and macros.
Modified cortav.lua from [bf3719fe9a] to [c52f4282f5].
1148 1148 {fn = insert_paragraph}; 1149 1149 } 1150 1150 1151 1151 function ct.parse_line(l, ctx, dest) 1152 1152 local newspan 1153 1153 local job = ctx.doc.stage.job 1154 1154 job:hook('line_read',ctx,l) 1155 + if l then 1156 + l = l:gsub("^ +","") -- trim leading spaces 1157 + end 1155 1158 if ctx.mode then 1156 1159 if ctx.mode.kind == 'code' then 1157 1160 if l and l:match '^~~~%s*$' then 1158 1161 job:hook('block_listing_end',ctx,ctx.mode.listing) 1159 1162 job:hook('mode_switch', c, nil) 1160 1163 ctx.mode = nil 1161 1164 else ................................................................................ 1264 1267 local lines = ss.str.breaklines(ctx.doc.enc, r.props.src) 1265 1268 local srcs = {} 1266 1269 for i,l in ipairs(lines) do 1267 1270 local args = ss.str.breakwords(ctx.doc.enc, l, 2, {escape=true}) 1268 1271 if #args < 3 then 1269 1272 r.origin:fail('invalid syntax for resource %s', t.ref) 1270 1273 end 1271 - local mimebreak = function(s) 1272 - local wds = ss.str.split(ctx.doc.enc, s, '/', 1, {escape=true}) 1273 - return wds 1274 - end 1275 - local mime = mimebreak(args[2]); 1276 - local mimeclasses = { 1277 - ['application/svg+xml'] = 'image'; 1278 - } 1274 + local mime = ss.mime(args[2]); 1279 1275 local class = mimeclasses[mime] 1280 1276 table.insert(srcs, { 1281 1277 mode = args[1]; 1282 1278 mime = mime; 1283 1279 uri = args[3]; 1284 1280 class = class or mime[1]; 1285 1281 }) 1286 1282 end 1287 1283 --ideally move this into its own mimetype lib 1288 - local kind = r.props.as or srcs[1].class 1289 - r.class = kind 1290 1284 r.srcs = srcs 1285 + -- note that resources do not themselves have kinds. when a 1286 + -- document requests to insert a resource, the renderer must 1287 + -- iterate through the sources and find the first source it 1288 + -- is capable of emitting. this allows constructions like 1289 + -- emitting a video for HTML outputs, a photo for printers, 1290 + -- and a screenplay for tty/plaintext outputs. 1291 1291 end 1292 1292 end 1293 1293 end 1294 1294 ctx.doc.stage = nil 1295 1295 ctx.doc.docjob:hook('meddle_ast') 1296 1296 return ctx.doc 1297 1297 end
Modified makefile from [9ea6c48a8b] to [fbd94cf6db].
94 94 95 95 $(build)/cortav.html: cortav.ct $(build)/$(executable) | $(build)/ 96 96 $(build)/$(executable) $< -o $@ -m render:format html -y html:fossil-uv 97 97 98 98 .PHONY: syncdoc 99 99 syncdoc: $(build)/cortav.html 100 100 fossil uv add $< --as cortav.html 101 - fossil uv sync 101 + fossil uv sync --all 102 102 103 103 # clean is written in overly cautious fashion to minimize damage, 104 104 # just in case it ever gets invoked in a bad way 105 105 .PHONY: clean 106 106 clean: 107 107 rm -f $(build)/*.{html,lc,sh,txt,desktop} \ 108 108 $(build)/$(executable){,.bin}
Modified render/groff.lua from [ab8e0fd21b] to [62c90e9915].
40 40 if me.linbuf == nil then 41 41 me.linbuf = ss.strac() 42 42 end 43 43 me.linbuf(text) 44 44 end; 45 45 txt = function(me, str, ...) 46 46 if str == nil then return end 47 + if me.linbuf == nil then 48 + -- prevent unwanted linebreaks 49 + str = str:gsub('^%s+','') 50 + end 47 51 me:raw(gsan(str)) 48 52 -- WARN this will cause problems if str is ever allowed to 49 53 -- include a line break. we can sanitize by converting 50 54 -- every line break into a new entry in the table, but i 51 55 -- don't think it should be possible for a \n to reach us 52 56 -- at this point, so i'm omitting the safety check as it 53 57 -- would involve an excessive hit to performance ................................................................................ 61 65 me:flush() 62 66 me:txt(...) 63 67 end; 64 68 req = function(me, r) 65 69 me:flush() 66 70 table.insert(me.lines, '.'..r) 67 71 end; 72 + sreq = function(me, r) 73 + me:flush() 74 + table.insert(me.lines, "'"..r) 75 + end; 68 76 esc = function(me, e) 69 77 me:raw('\\' .. e) 70 78 end; 79 + draw = function(me, args) 80 + for _,v in ipairs(args) do 81 + me:esc("D'" .. v .. "'") 82 + end 83 + end; 71 84 flush = function(me) 72 85 if me.linbuf ~= nil then 73 86 local line = me.linbuf:compile() 74 87 local first = line:sub(1,1) 75 88 -- make sure our lines aren't accidentally interpreted 76 89 -- as groff requests. groff is kinda hostile to script 77 90 -- generation, huh? ................................................................................ 163 176 }; 164 177 color = {'.color'}; 165 178 insert = {}; 166 179 footnote = { 167 180 '.de footnote-blank'; 168 181 '. sp 0.25m'; 169 182 '..'; 183 + 170 184 '.ev footnote-env'; 171 185 '. ps 8p'; 172 186 '. in 0.5c'; 173 - '. blm footnote-blank'; 174 187 '.ev'; 188 + 175 189 '.de footnote-print'; 176 190 -- '. sp |\\\\n[.p]u-\\\\n[footnote-pos]u'; 177 191 '. sp 0.5c'; 178 192 '. ev footnote-env'; 193 + '. blm footnote-blank'; 179 194 '. fn'; 195 + '. blm np'; 180 196 '. ev'; 181 197 '. rm fn'; 182 198 '. nr footnote-pos 0'; 183 - -- move the trap past the bottom of the page so it's not 199 + -- move the trap past the top of the page so it's not 184 200 -- invoked again until more footnotes have been assembled 185 - '. ch footnote-print |\\\\n[.p]u+10'; 201 + '. ch footnote-print |-1000'; 186 202 '. bp'; 187 203 '..'; 204 + 188 205 '.wh |\\n[.p]u footnote-print'; 189 206 }; 190 207 root = { 191 208 -- these are macros included in all documents 192 209 -- page offset is hideously broken and unusable; we 193 210 -- zero it out so we can use .in to control indents 194 211 -- instead. note that the upshot of this is we need 195 212 -- to manually specify the indent in every other 196 213 -- environment from now on, .evc doesn't seem to cut it 197 214 -- set up the page title environment & trap 198 215 "'in 2c"; 199 - "'ll 18c"; 216 + "'ll 19.5c"; 200 217 "'po 0"; 201 218 "'ps 13p"; 202 219 "'vs 15p"; 203 220 ".ev pgti"; 204 221 ". evc 0"; 205 222 ". fam H"; 206 223 ". ps 10pt"; ................................................................................ 212 229 '. lt 19c'; 213 230 ". tl '\\\\*[doctitle]'\\fB\\\\*[title]\\f[]'%'"; 214 231 '. po 0'; 215 232 ". br"; 216 233 '. ev'; 217 234 '. sp 1.2c'; 218 235 '..'; 219 - '.wh 0 ph'; 220 236 '.de np'; 221 - '. sp 0.2c'; 237 + '. sp 0.6m'; 222 238 '..'; 223 - '.blm np' 239 + '.blm np'; 240 + '.wh 0 ph'; 224 241 225 242 }; 226 243 } 227 244 rs.macsNeeded = { 228 245 order = {}; 229 246 map = {}; 230 247 count = 0; ................................................................................ 377 394 elseif spanRenderers[v.kind] then 378 395 spanRenderers[v.kind](rc, v, b, sec) 379 396 end 380 397 end 381 398 end 382 399 383 400 local blockRenderers = {} 401 + blockRenderers['horiz-rule'] = function(rc, b, sec) 402 + rc.prop.margin = { top = 0.3 } 403 + rc.prop.underline = 0.1 404 + end 384 405 function blockRenderers.label(rc, b, sec) 385 406 if ct.sec.is(b.captions) then 386 407 local sizes = {36,24,12,8,4,2} 387 - local margins = {0,5,2,1,0.5} 408 + local margins = {0,3} 388 409 local dedents = {2.5,1.3,0.8,0.4} 410 + local uls = {3,1.5,0.5,0.25} 389 411 rc.prop.dsz = sizes[b.captions.depth] or 10 390 - rc.prop.underline = b.captions.depth < 4 412 + rc.prop.underline = uls[b.captions.depth] 391 413 rc.prop.bold = b.captions.depth > 3 392 414 rc.prop.margin = { 393 - top = margins[b.captions.depth] or 0; 415 + top = margins[b.captions.depth] or 1; 394 416 bottom = 0.1; 395 417 } 418 + rc.prop.vassure = rc.prop.dsz+70; 396 419 rc.prop.indent = -(dedents[b.captions.depth] or 0) 397 - rc.prop.underline = true 398 420 rc.prop.chtitle = collectText(rc, b.spans, b.spec):compile() 399 421 if b.captions.depth == 1 then 400 422 rc.prop.breakBefore = true 401 423 end 402 424 rs.renderSpans(rc, b.spans, b, sec) 403 425 else 404 426 ss.bug 'tried to render label for an unknown object type':throw() ................................................................................ 419 441 local skippedFirstPagebreak = doc.secorder[1]:visible() 420 442 local deferrer = ss.declare { 421 443 ident = 'groff-deferrer'; 422 444 mk = function(buf) return {ops={}, tgt=buf} end; 423 445 fns = { 424 446 esc = function(me, str) table.insert(me.ops, {0, str}) end; 425 447 req = function(me, str) table.insert(me.ops, {1, str}) end; 448 + draw = function(me, lst) table.insert(me.ops,{2, lst}) end; 426 449 flush = function(me) 427 450 for i=#me.ops,1,-1 do 428 451 local d = me.ops[i] 429 452 if d[1] == 0 then 430 453 me.tgt:esc(d[2]) 431 454 elseif d[1] == 1 then 432 455 me.tgt:req(d[2]) 456 + elseif d[1] == 2 then 457 + me.tgt:draw(d[2]) 433 458 end 434 459 end 435 460 me.ops = {} 436 461 end; 437 462 }; 438 463 } 439 464 function rs.emitSpan(gtxt, s) ................................................................................ 458 483 else 459 484 gtxt:txt(s.txt) 460 485 end 461 486 defer:flush() 462 487 if s.div then 463 488 for div, body in pairs(s.div) do 464 489 if div == 'fn' then 465 - gtxt:req 'ev footnote-env' 490 + gtxt:sreq 'ev footnote-env' 466 491 end 467 - gtxt:req('boxa '..div) 492 + gtxt:sreq('boxa '..div) 468 493 gtxt:txt(body) 469 494 gtxt:raw '\n' 470 - gtxt:req 'boxa' 495 + gtxt:sreq 'boxa' 471 496 if div == 'fn' then 472 - gtxt:req 'ev' 473 - gtxt:req 'nr footnote-pos (\\n[footnote-pos]u+\\n[dn]u)' 474 - gtxt:req 'ch footnote-print -(\\n[footnote-pos]u+1c)' 497 + gtxt:sreq 'ev' 498 + gtxt:sreq 'nr footnote-pos (\\n[footnote-pos]u+\\n[dn]u)' 499 + gtxt:sreq 'ch footnote-print -(\\n[footnote-pos]u+1.5c)' 475 500 end 476 501 end 477 502 end 478 503 end 479 504 function rs.emitBlock(gtxt, b) 480 505 local didfinalbreak = false 481 506 local defer = deferrer(gtxt) ................................................................................ 485 510 end 486 511 if ln.breakBefore then 487 512 if skippedFirstPagebreak then 488 513 gtxt:req 'bp' 489 514 else 490 515 skippedFirstPagebreak = true 491 516 end 517 + elseif ln.vassure then 518 + gtxt:req(string.format('if (\\n[.t]u < %sp) .bp',ln.vassure)) 492 519 end 493 520 if ln.indent then 494 521 if ln.indent < 0 then 495 522 gtxt:req('in '..tostring(ln.indent)..'m') 496 523 defer:req 'in' 497 524 gtxt:req('ll +'..tostring(-ln.indent)..'m') 498 525 defer:req 'll' ................................................................................ 505 532 if ln.margin then 506 533 if ln.margin.top then 507 534 gtxt:req(string.format('sp %sm', ln.margin.top)) 508 535 end 509 536 end 510 537 511 538 if ln.underline then 512 - defer:esc("D'l \\n[.ll]u-\\n[.in]u 0'") 513 - defer:esc"v'-0.5'" 514 539 defer:req'br' 540 + defer:draw { 541 + "t "..tostring(ln.underline).."p"; 542 + "l \\n[.ll]u-\\n[.in]u 0"; 543 + } 544 + defer:esc("h'-" .. tostring(ln.underline) .. "p'") 545 + defer:esc"v'-0.5'" 515 546 end 516 547 517 548 if ln.dsz and ln.dsz > 0 then 518 549 gtxt:req('ps +' .. tostring(ln.dsz) .. 'p') 519 550 defer:req('ps -' .. tostring(ln.dsz) .. 'p') 520 551 elseif ln.sz or ln.dsz then 521 552 if ln.sz and ln.sz <= 0 then
Modified render/html.lua from [778a76ed09] to [39c7338664].
671 671 local function getBlockRenderers(procs, sr) 672 672 local tag, elt, catenate = procs.tag, procs.elt, procs.catenate 673 673 local null = function() return catenate{} end 674 674 675 675 local block_renderers = { 676 676 anchor = function(b,s) 677 677 return tag('a',{id = getSafeID(b)},null()) 678 + end; 679 + ['horiz-rule'] = function(b,s) 680 + return elt'hr' 678 681 end; 679 682 paragraph = function(b,s) 680 683 addStyle 'paragraph' 681 684 return tag('p', nil, sr.htmlSpan(b.spans, b, s), b) 682 685 end; 683 686 directive = function(b,s) 684 687 -- deal with renderer directives
Modified sirsem.lua from [550cdedbd6] to [eb2c53bff4].
4 4 -- ? utility library with functionality common to 5 5 -- cortav.lua and its extensions 6 6 -- from Ranuir "software utility" 7 7 -- > local ss = require 'sirsem.lua' 8 8 9 9 local ss 10 10 do -- pull ourselves up by our own bootstraps 11 - local package = _G.package -- prevent namespace from being broken by env shenanigans 11 + local package = _G.package 12 + -- prevent namespace from being broken by env shenanigans 12 13 local function namespace(name, tbl) 13 14 local pkg = tbl or {} 14 15 if package then 15 16 package.loaded[name] = pkg 16 17 end 17 18 return pkg 18 19 end ................................................................................ 600 601 601 602 if c.op then 602 603 cls.__add = c.op.sum 603 604 cls.__sub = c.op.sub 604 605 cls.__div = c.op.div 605 606 cls.__mul = c.op.mul 606 607 cls.__concat = c.op.cat 608 + cls.__eq = c.op.eq 609 + cls.__lt = c.op.lt 607 610 end 608 611 609 612 cls.mk = function(...) 610 613 local val = setmetatable(c.mk and c.mk(...) or {}, cls) 611 614 if c.init then 612 615 for k,v in pairs(c.init) do 613 616 val[k] = v ................................................................................ 685 688 686 689 ss.version = ss.declare { 687 690 name = 'version'; 688 691 mk = function(tbl) return tbl end; 689 692 fns = { 690 693 pre = function(self,other) end; 691 694 post = function(self,other) end; 692 - string = function(self) return tostring(self) end; 695 + string = function(self) return tostring(self) end; 693 696 }; 694 697 cast = { 695 698 string = function(vers) 696 699 if not(next(vers)) then return '0.0' end 697 700 local str = '' 698 701 for _,v in pairs(vers) do 699 702 if type(v) == 'string' then ................................................................................ 766 769 function ss.tuple.cdr(x, ...) return ... end 767 770 768 771 ss.stack = ss.declare { 769 772 ident = 'stack'; 770 773 mk = function() return { 771 774 top = 0; 772 775 store = {}; 773 - } end; 776 + } end; 774 777 index = function(me, i) 775 778 if i <= 0 then 776 779 return me.store[me.top + i] 777 780 else 778 781 return me.store[i] 779 782 end 780 783 end; 781 784 fns = { 782 785 push = function(me, val, ...) 783 - if val~=nil then 784 - me.top = me.top + 1 785 - me.store[me.top] = val 786 - me:push(...) 787 - end 788 - return val, ... 789 - end; 790 - pop = function(me,n) n = n or 1 791 - local r = {} 786 + if val~=nil then 787 + me.top = me.top + 1 788 + me.store[me.top] = val 789 + me:push(...) 790 + end 791 + return val, ... 792 + end; 793 + pop = function(me,n) n = n or 1 794 + local r = {} 792 795 if n < me.top then 793 796 for i = 0,n-1 do 794 797 r[i+1] = me.store[me.top - i] 795 798 me.store[me.top - i] = nil 796 799 end 797 800 me.top = me.top - n 798 - else 799 - r = me.store 801 + else 802 + r = me.store 800 803 me.store = {} 801 - end 804 + end 802 805 return table.unpack(r) 803 - end; 804 - set = function(me,val) 805 - if me.top == 0 then 806 - me.top = me.top + 1 --autopush 807 - end 808 - me.store[me.top] = val 809 - end; 810 - all = function(me) return table.unpack(me.store) end; 811 - each = function(forward) 812 - if forward then 813 - local idx = 0 814 - return function() 815 - idx = idx + 1 816 - if idx > top 806 + end; 807 + set = function(me,val) 808 + if me.top == 0 then 809 + me.top = me.top + 1 --autopush 810 + end 811 + me.store[me.top] = val 812 + end; 813 + all = function(me) return table.unpack(me.store) end; 814 + each = function(me,forward) 815 + if forward then 816 + local idx = 0 817 + return function() 818 + idx = idx + 1 819 + if idx > me.top 820 + then return nil 821 + else return me.store[idx], idx 822 + end 823 + end 824 + else 825 + local idx = me.top + 1 826 + return function() 827 + idx = idx - 1 828 + if idx == 0 817 829 then return nil 818 830 else return me.store[idx], idx 819 831 end 820 - end 821 - else 822 - local idx = top + 1 823 - return function() 824 - idx = idx - 1 825 - if idx == 0 826 - then return nil 827 - else return me.store[idx], idx 828 - end 829 - end 830 - end 831 - end; 832 + end 833 + end 834 + end; 832 835 }; 833 836 } 834 837 835 838 ss.automat = ss.declare { 836 839 ident = 'automat'; 837 840 mk = function() return { 838 841 state = ss.stack(); ................................................................................ 1107 1110 -- versions at least can launch programs in a sane and secure 1108 1111 -- way. 1109 1112 else 1110 1113 return s 1111 1114 end 1112 1115 end, ...)) 1113 1116 end 1117 + 1118 +ss.mime = ss.declare { 1119 + ident = 'mime-type'; 1120 + mk = function() return { 1121 + class = nil; 1122 + kind = nil; 1123 + opts = {}; 1124 + } end; 1125 + construct = function(me,str) 1126 + if not str then return end 1127 + local p,o = str:match '^([^;]+);?%s*(.-)$' 1128 + if not p then ss.mime.exn('invalid type syntax %s',str):throw() end 1129 + local c,k = p:match '^([^/]+)/?(.-)$' 1130 + me.class = (c ~= '') and c or nil 1131 + me.kind = (k ~= '') and k or nil 1132 + if o and o ~= '' then 1133 + for key, e, val in o:gmatch '%s*([^=;]+)(=?)([^;]*)' do 1134 + if me.opts[key] then 1135 + ss.mime.exn('mime type cannot contain multiple %s options',key):throw() 1136 + elseif me.opts.hex and key == 'base64' 1137 + or me.opts.base64 and key == 'hex' then 1138 + ss.mime.exn('mime type cannot more than one of (base64, hex)',key):throw() 1139 + end 1140 + if e == '' then val = true end 1141 + me.opts[key] = val 1142 + end 1143 + end 1144 + end; 1145 + op = { 1146 + eq = function(self, other) 1147 + -- exact match operator 1148 + if not ss.mime.is(other) then return ss.mime.exn("tried to compare MIME type %s against %s (%s)", tostring(self), type(other), tostring(other)):throw() end 1149 + if (self.kind == other.kind or (self.kind == '*' or other.kind == '*')) and 1150 + (self.class == other.class or (self.class == '*' or other.class == '*')) and 1151 + (#self.opts ==#other.opts) then 1152 + for k,v in pairs(self.opts) do 1153 + if not(other.opts[k] == '*' or (v == '*' and other.opts[k])) then 1154 + if other.opts[k] ~= v then return false end 1155 + end 1156 + end 1157 + for k,v in pairs(other.opts) do 1158 + if not(self.opts[k] == '*' or (v == '*' and self.opts[k])) then 1159 + if self.opts[k] ~= v then return false end 1160 + end 1161 + end 1162 + return true 1163 + else 1164 + return false 1165 + end 1166 + end; 1167 + lt = function(self,other) 1168 + -- lt is the "subset?" operator -- it returns true if self 1169 + -- matches at least as many fields as other has. use this 1170 + -- when you have a base type and want to check whether 1171 + -- another type is compatible with that type. say all you 1172 + -- care about is whether a file is "text/plain", and it 1173 + -- can be encoded however as long as that much fits. 1174 + -- you would then ask ss.mime'text/plain' < file.mime 1175 + return other:superset_of(self) 1176 + end; 1177 + }; 1178 + cast = { 1179 + string = function(me) 1180 + local r 1181 + if me.kind and me.class then 1182 + r = string.format('%s/%s',me.class,me.kind) 1183 + elseif me.class then 1184 + r = me.class 1185 + end 1186 + for k,v in pairs(me.opts) do 1187 + if v and v ~= true then 1188 + r = r .. string.format(';%s=%s',k,v) 1189 + elseif v == true then 1190 + r = r .. string.format(';%s',k) 1191 + end 1192 + end 1193 + return r 1194 + end; 1195 + }; 1196 + fns = { 1197 + superset_of = function(self, other) 1198 + -- a mime type is greater than another if all the fields 1199 + -- other has have a matching field in self. think of this 1200 + -- as the "superset?" operator -- all fields and options 1201 + -- on other must either match self or be unset 1202 + if not ss.mime.is(other) then return ss.mime.exn("tried to compare MIME type %s against %s (%s)", tostring(self), type(other), tostring(other)):throw() end 1203 + if (other.class and self.class ~= other.class and other.class ~='*') 1204 + or (other.kind and self.kind ~= other.kind and other.kind ~= '*') 1205 + then return false end 1206 + for k,v in pairs(other.opts) do 1207 + if self.opts[k] and self.opts[k] ~= v and v ~='*' then 1208 + return false 1209 + end 1210 + end 1211 + return true 1212 + end; 1213 + is = function(me, pc) 1214 + local mimeclasses = { 1215 + ['application/svg+xml'] = 'image'; 1216 + ['application/x-tar'] = 'archive'; 1217 + } 1218 + local c = me.class 1219 + for k,v in pairs(mimeclasses) do 1220 + if me > ss.mime(k) then 1221 + c = v break 1222 + end 1223 + end 1224 + print(c) 1225 + return c == pc 1226 + end; 1227 + }; 1228 +} 1229 +ss.mime.exn = ss.exnkind 'MIME error'
Modified tool/makeshim.lua from [f2235ca34c] to [cea771ab78].
7 7 -- giving cortav extra privileges 8 8 9 9 local includes = [[ 10 10 #include <lua.h> 11 11 #include <lauxlib.h> 12 12 #include <stdio.h> 13 13 #include <stddef.h> 14 +#include <unistd.h> 14 15 extern int luaL_openlibs(lua_State* l); 15 16 ]] 16 17 17 18 18 19 local main = [[ 19 20 int main(int argc, char** argv) { 20 21 lua_State* l = luaL_newstate(); ................................................................................ 31 32 // load and run our payload 32 33 int e = luaL_loadbufferx(l, ct_bytecode, sizeof(ct_bytecode), "cortav", "b"); 33 34 if (e != LUA_OK) { 34 35 printf("some kind of error idk fam\n"); 35 36 return -1; 36 37 } 37 38 38 - lua_call(l, 0, 0); 39 + if (lua_pcall(l, 0, 0, 0) != LUA_OK) { 40 + size_t len; 41 + const char* msg = luaL_tolstring(l, -1, &len); 42 + if (isatty(2)) { 43 + fprintf(stderr, "\33[31;1m(fatal)\33[m %.*s\n", (int)len, msg); 44 + } else { 45 + fprintf(stderr, "(fatal) %.*s\n", (int)len, msg); 46 + } 47 + }; 39 48 40 49 // normal termination is by the os.exit() call 41 50 return -1; 42 51 } 43 52 ]] 44 53 45 54 local function setfile(i, dflt, mode) ................................................................................ 53 62 return dflt 54 63 end 55 64 56 65 local src = setfile(1, io.stdin, "rb") 57 66 local dest = setfile(2, io.stdout, "w") 58 67 59 68 local cstr = {} 60 -local strtpl = 'static char ct_bytecode [%u] = {%s};' 61 -local lines = {includes} 69 +local strtpl = [[static char ct_bytecode [%u] = { 70 +%s 71 +};]] 62 72 63 73 local bytes = {} 64 74 65 75 local bn = 1 66 76 local len = 0 67 77 while true do 68 78 local byte = src:read(1) 69 79 if not byte then break end 70 80 local str = tostring(byte:byte(1))..',' 71 81 -- make sure our source file is parseable by 72 82 -- a compliant C compiler 73 - len = len + string.len(str) 74 - if len >= 4096 then 83 + local strl = string.len(str) 84 + if len + strl >= 4095 then 75 85 len = 0 76 86 bytes[bn]='\n' 77 87 bn = bn + 1 78 88 end 89 + len = len + strl 79 90 bytes[bn] = str 80 91 bn = bn + 1 81 92 end 82 93 83 -table.insert(lines, strtpl:format(#bytes, table.concat(bytes))) 84 -table.insert(lines, main) 94 +local lines = { 95 + includes; 96 + strtpl:format(#bytes, table.concat(bytes)); 97 + main; 98 +} 85 99 86 100 dest:write(table.concat(lines, '\n'))