-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 347279d
Showing
20 changed files
with
1,665 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
;;;; System definition for document.export.html. | |||
|
|||
(defpackage document.export.html-asd | |||
(:use :cl :asdf)) | |||
|
|||
(in-package :document.export.html-asd) | |||
|
|||
(defsystem document-export-html | |||
:components ((:file "export/html")) | |||
:depends-on ("document" "html" "file-types")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
;;;; System definition for document.export.org-mode. | |||
|
|||
(defpackage document.export.org-mode-asd | |||
(:use :cl :asdf)) | |||
|
|||
(in-package :document.export.org-mode-asd) | |||
|
|||
(defsystem document-export-org-mode | |||
:components ((:file "export/plain") | |||
(:file "export/org-mode" | |||
:depends-on ("export/plain"))) | |||
:depends-on ("document")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
;;;; System definition for document.export.plain. | |||
|
|||
(defpackage document.export.plain-asd | |||
(:use :cl :asdf)) | |||
|
|||
(in-package :document.export.plain-asd) | |||
|
|||
(defsystem document-export-plain | |||
:components ((:file "export/plain")) | |||
:depends-on ("document")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
;;;; System definition for document.import.plain. | |||
|
|||
(defpackage document.import.plain-asd | |||
(:use :cl :asdf)) | |||
|
|||
(in-package :document.import.plain-asd) | |||
|
|||
(defsystem document-import-plain | |||
:components ((:file "import/plain")) | |||
:depends-on ("document" "smug" "defmacro!")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
;;;; Defines named readtable for text markup syntax. | |||
|
|||
(in-package :document.macros) | |||
|
|||
(defun make-markup-reader (constructor) | |||
"Returns function that reads string literal and applies CONSTRUCTOR." | |||
(lambda (stream subchar arg) | |||
`(funcall ,constructor ,(read stream t)))) | |||
|
|||
(defreadtable syntax | |||
(:merge :standard) | |||
(:dispatch-macro-char #\# #\b (make-markup-reader #'make-bold)) | |||
(:dispatch-macro-char #\# #\i (make-markup-reader #'make-italic)) | |||
(:dispatch-macro-char #\# #\c (make-markup-reader #'make-code)) | |||
(:dispatch-macro-char #\# #\u (make-markup-reader #'make-url)) | |||
(:case :invert)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
;;;; Macros for document construction. | |||
|
|||
(defpackage document.macros | |||
(:use :cl | |||
:document | |||
:named-readtables) | |||
(:export :paragraph | |||
:listing | |||
:table | |||
:media | |||
:pre | |||
:section | |||
:document | |||
:syntax)) | |||
|
|||
(in-package :document.macros) | |||
|
|||
(defmacro paragraph (&rest text) | |||
"Make a paragraph." | |||
`(make-paragraph (list ,@text))) | |||
|
|||
(defmacro listing (&rest items) | |||
"Make a listing." | |||
`(make-listing (list ,@(loop for item in items | |||
collect `(list ,@item))))) | |||
|
|||
(defmacro table ((&rest description) &rest rows) | |||
"Make a table." | |||
`(make-table | |||
(list ,@description) | |||
(list ,@(loop for row in rows | |||
collect `(list ,@(loop for column in row | |||
collect `(list ,@column))))))) | |||
|
|||
(defmacro media ((&rest description) url) | |||
"Make a media object." | |||
`(make-media (list ,@description) ,url)) | |||
|
|||
(defmacro pre ((&rest description) code) | |||
"Make code object." | |||
`(make-pre (list ,@description) ,code)) | |||
|
|||
(defmacro section ((&rest header) &rest document) | |||
"Make section." | |||
`(make-section (list ,@header) | |||
(list ,@document))) | |||
|
|||
(defmacro document (&rest content) | |||
`(list ,@content)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
;;;; System definition for document. | |||
|
|||
(defpackage document-asd | |||
(:use :cl :asdf)) | |||
|
|||
(in-package :document-asd) | |||
|
|||
(defsystem document | |||
:components ((:file "document") | |||
(:file "document-macros" :depends-on ("document")) | |||
(:file "document-macros-syntax" | |||
:depends-on ("document" "document-macros"))) | |||
:depends-on ("named-readtables")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,118 @@ | |||
;;;; Simple documents. | |||
|
|||
(defpackage document | |||
(:use :cl) | |||
(:export :+paragraph+ | |||
:+listing+ | |||
:+table+ | |||
:+media+ | |||
:+pre+ | |||
:+section+ | |||
:+bold+ | |||
:+italic+ | |||
:+code+ | |||
:+url+ | |||
:make-paragraph | |||
:make-listing | |||
:make-table | |||
:make-media | |||
:make-pre | |||
:make-section | |||
:make-bold | |||
:make-italic | |||
:make-code | |||
:make-url | |||
:content-type | |||
:content-values | |||
:walk-document)) | |||
|
|||
(in-package :document) | |||
|
|||
(defconstant +paragraph+ :p | |||
"Paragraph symbol.") | |||
|
|||
(defconstant +listing+ :l | |||
"List symbol.") | |||
|
|||
(defconstant +table+ :t | |||
"Table symbol.") | |||
|
|||
(defconstant +media+ :m | |||
"Media symbol.") | |||
|
|||
(defconstant +pre+ :r | |||
"Pre symbol.") | |||
|
|||
(defconstant +section+ :s | |||
"Section symbol.") | |||
|
|||
(defconstant +bold+ :b | |||
"Bold symbol.") | |||
|
|||
(defconstant +italic+ :i | |||
"Italic symbol.") | |||
|
|||
(defconstant +code+ :c | |||
"Code symbol.") | |||
|
|||
(defconstant +url+ :u | |||
"URL symbol.") | |||
|
|||
(defun make-paragraph (text) | |||
"Make a paragraph." | |||
(list +paragraph+ text)) | |||
|
|||
(defun make-listing (items) | |||
"Make a listing." | |||
(list +listing+ items)) | |||
|
|||
(defun make-table (description rows) | |||
"Make a table." | |||
(list +table+ description rows)) | |||
|
|||
(defun make-media (description url) | |||
"Make a media object." | |||
(list +media+ description url)) | |||
|
|||
(defun make-pre (description code) | |||
"Make code object." | |||
(list +pre+ description code)) | |||
|
|||
(defun make-section (header document) | |||
"Make section." | |||
(list +section+ header document)) | |||
|
|||
(defun make-bold (string) | |||
"Make bold text." | |||
(list +bold+ string)) | |||
|
|||
(defun make-italic (string) | |||
"Make italic text." | |||
(list +italic+ string)) | |||
|
|||
(defun make-code (string) | |||
"Make fixed-width text." | |||
(list +code+ string)) | |||
|
|||
(defun make-url (string) | |||
"Make URL link." | |||
(list +url+ string)) | |||
|
|||
(defun content-type (content) | |||
"Returns CONTENT's type." | |||
(first content)) | |||
|
|||
(defun content-values (content) | |||
"Returns CONTENT's values." | |||
(apply #'values (rest content))) | |||
|
|||
(defun section-content (section) | |||
"Returns SECTION's content." | |||
(third section)) | |||
|
|||
(defun walk-document (document function) | |||
"Walk over DOCUMENT and call (FUNCTION content) on content." | |||
(dolist (content document) | |||
(funcall function content) | |||
(when (eq (content-type content) +section+) | |||
(walk-document (section-content content) function)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
+ {DOCUMENT.EXPORT.PLAIN} does not indent properly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,71 @@ | |||
< Document: A meta format for simple documents | |||
|
|||
The purpose of this format is to ease the creation, storage and | |||
publishing of documents. Documents contain a hierarchy of sections | |||
which in return contain formatted text and media in form of | |||
paragraphs, lists, tables, code and links. The goals are achieved by | |||
specifying a human consumable but basic plain text format for in- and | |||
output and implementing an internal tree-based format in common lisp. | |||
|
|||
< Contents of a document | |||
|
|||
Paragraphs are text bodies which contain formatting like *bold*, | |||
_italic_ and {code} but also links like this one: | |||
[http://triakis.ath.cx/]. | |||
|
|||
+ a list | |||
+ _an_ item | |||
+ *yet* another {one} | |||
|
|||
#media A short description of the picture.# | |||
picture.png | |||
|
|||
#table A short description of the table.# | |||
| name | age | rating | |||
| Jim | 33 | A | |||
| Joe | 27 | B | |||
| ... | ... | ... | |||
|
|||
#code A short description of the code.# | |||
(defun pow (x n) | |||
"Returns power N of X." | |||
(if (= n 1) | |||
x | |||
(* x (pow x (- n 1))))) | |||
# | |||
|
|||
Special interpretation of characters like \<, \>, \+, \|, \_, \{, \[, \# | |||
and \\ can be prevented by quoting them with \\. | |||
|
|||
> | |||
|
|||
< Lisp representation | |||
|
|||
Documents in their lisp representation consist of a list hierarchy | |||
made up of strings and symbols. | |||
|
|||
#table Formal definition of a document.# | |||
| Element | Definition | |||
| document | (\[paragraph\|list\|table\|media\|pre\|section...\]) | |||
| paragraph | (:p \<text\>) | |||
| list | (:l (\<text...\>)) | |||
| table | (:t \<text\> ((\<textbody...\>))...) | |||
| media | (:m \<text\> string) | |||
| pre | (:r \<text\> string) | |||
| section | (:s \<text\> \[document...\]) | |||
| text | (\[string\|bold\|italic\|code\|url...\]) | |||
| string | a vector of characters | |||
| bold | (:b string) | |||
| italic | (:i string) | |||
| code | (:c string) | |||
|
|||
#code A sample document as an s-expression.# | |||
((:s ("string") | |||
(:p ("A " (:c "paragraph"))) | |||
(:l (((:b "bold")) | |||
((:i "italic")))))) | |||
# | |||
|
|||
> | |||
|
|||
> |
Oops, something went wrong.