simple ansi document. A Document-Format originally designed to be formatted using ansi https://marie.software/projects/sad.html
Find a file
2025-09-29 02:07:49 +02:00
inc Refactor project structure 2023-05-11 12:05:08 +02:00
src make ParseSwitchArgs public 2025-09-29 02:07:49 +02:00
.gitattributes fix gitattributes 2023-05-11 18:33:44 +02:00
.gitignore start rewrite 2025-09-28 22:10:08 +02:00
LICENSE Update LICENSE 2023-05-11 11:36:40 +02:00
Makefile adjust sadv to use new parser 2025-09-28 23:10:41 +02:00
README.md update README 2025-09-28 23:22:40 +02:00

sad

about

sad is a simple document format originally designed to be rendered in terminals using regular ansi control sequences. formatting is handled through "switches" in plain text.

repo structure

  • src/
    • sad.pas — main sad parser unit
    • sadv.pas — command line sad viewer/renderer
    • test.pas — program for development testing

the rewrite

sad has been through a major rewrite and received major changes to the syntax and features.

  • {$begin-section} <name> -> {$section} <name> (backwards compatible)
  • {$end-section} -> {$end} (backwards compatible)
  • {$color <color>} removed
  • {$reset} now resets the last applied style
  • {$reset-all} resets all styles
  • {$sub-head}
    • deprecated
      • headers now derive their importance from the depth of the section which they are found in.
    • only one per section, can not be in a section if a regular {$head} switch was already encountered.
  • {$head}
    • headers now derive their importance from the depth of the section which they are found in.
    • only one {$head} or {$sub-head} switch may appear in a section.
  • {$title} switch can only be used in the document header

sadsuite

  • sadv (included, broken) — CLI sad viwer
  • fpc-sitgen — SAD based satic site generator

what the parsed data looks like

a parsed sa document is contained inside an instance of the TDocument record. this record contains a map of the metadata, the title and a pointer to the root section of the document.

switches recognized by the parser do not appear inside the parsed data, non-recognized switches will still appear. if that behaviour is not wanted and an error should be emitted if an unrecognized switch appears, define OnlyStandardSwitches at compilation time.

sections

the root section is of the record type TSection like every other section and contains is subsections in the field children. the text inside of a root section is stored in blocks (array of TTextBlock). a new textblock is opened everytime a style changes.

text blocks

a textblock (TTextBlock) represents a block of text associated with its active set of styles (array of TStyle). The actual text is stored in an array of strings which was initially split at every space and trimmed of whitespace, except for linebreaks.

styles

active styles are represented using the TStyle record which stores the kind of the style (TStyleKind) which may be either one of:

  • Head
  • SubHead
  • Custom

and the arguments, if any, for that style in a string array.