Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

small changes and modifications to markdown.lsp

  • Loading branch information...
commit 63ce2ba9ed22e5911b458e082b07c78f102960ed 1 parent 68ce740
@cormullion authored
Showing with 224 additions and 278 deletions.
  1. +223 −278 markdown.lsp
  2. +1 −0  nldb/nldb.lsp
View
501 markdown.lsp
@@ -9,14 +9,20 @@
;; see his original Perl script for explanations of the fearsome regexen and
;; byzantine logic, etc...
;; TODO:
-;; the following Markdown tests give different results:
-;; nested brackets (see Links, reference style.text)
-;; backticks in html tags (see test file Code Spans.text)
-;; parens in url : ![this is a stupid URL](http://example.com/(parens).jpg) see (Images.text)
-;; a nested ordered list error (see Ordered and unordered lists.text)
-;; some odd backslash escapes in Backslash escapes.text
-;; Add: email address scrambling
+;; the following Markdown tests fail:
+;; Inline HTML (Advanced) ... FAILED
+;; Links, reference style ... FAILED -- nested brackets
+;; Links, shortcut references ... FAILED
+;; Markdown Documentation - Syntax ... FAILED
+;; Ordered and unordered lists ... FAILED -- a nested ordered list error
+;; parens in url : ![this is a stupid URL](http://example.com/(parens).jpg) see (Images.text)
+;; Add: email address scrambling
;;
+;; version 2011-08-18 15:04:40
+;; various fixes, and added hack for running this from the command-line:
+;; echo "hi there" | newlisp markdown.lsp
+;; echo "hello world" | markdown.lsp
+;; cat file.text | newlisp markdown.lsp
;;
;; version 2010-11-14 17:34:52
;; some problems in ustring. Probably remove it one day, as it's non standard...
@@ -52,37 +58,37 @@
;; removed reliance on dostring for compatibility with 9.1
;; author: cormullion
-; need this for rainbox syntax colouring
; (load "nestor.lsp")
(context 'markdown)
(define (markdown:markdown txt)
(initialize)
- (unescape-special-chars (block-transforms (strip-link-definitions (protect (cleanup txt))))))
-
-; initialize
+ (unescape-special-chars
+ (block-transforms
+ (strip-link-definitions
+ (protect
+ (cleanup txt))))))
(define (initialize)
(set '*escape-chars* [text]\`*_{}[]()>#+-.![/text])
(set '*escape-pairs* '(
- ([text]\\\\[/text] [text]\\[/text])
- ([text]\\`[/text] [text]`[/text])
- ([text]\\\*[/text] [text]*[/text])
- ([text]\\_[/text] [text]_[/text])
- ([text]\\\{[/text] [text]{[/text])
- ([text]\\\}[/text] [text]}[/text])
- ([text]\\\[[/text] [text][[/text])
- ([text]\\\][/text] [text]][/text])
- ([text]\\\([/text] [text]([/text])
- ([text]\\\)[/text] [text])[/text])
- ([text]\\>[/text] [text]>[/text])
- ([text]\\\#[/text] [text]#[/text])
- ([text]\\\+[/text] [text]+[/text])
- ([text]\\\-[/text] [text]-[/text])
- ([text]\\\.[/text] [text].[/text])
- ([text]\\![/text] [text]![/text])
- ))
+ ({\\\\} {\})
+ ({\\`} {`})
+ ({\\\*} {*})
+ ({\\_} {_})
+ ([text]\\\{[/text] [text]{[/text])
+ ([text]\\\}[/text] [text]}[/text])
+ ({\\\[} {[})
+ ({\\\]} {]})
+ ({\\\(} {(})
+ ({\\\)} {)})
+ ({\\>} {>})
+ ({\\\#} {#})
+ ({\\\+} {+})
+ ({\\\-} {-})
+ ({\\\.} {.})
+ ({\\!} {!})))
(set '*hashed-html-blocks* '())
(build-escape-table)
(set '*list-level* 0))
@@ -104,8 +110,7 @@
(anchors
(images
(escape-special-chars
- (escape-special-chars-within-tag-attributes
- (code-spans txt))))))))))
+ (escape-special-chars (code-spans txt) 'inside-attributes)))))))))
(define (hash s)
(base64-enc (uuid)))
@@ -129,62 +134,36 @@
(str xhtml)
(len (length str))
(pos 0)
- (tokens '())
- )
+ (tokens '()))
(while (set 'tag-start (find tag-match str 8))
(if (< pos tag-start)
- (push (list 'text (slice str pos (- tag-start pos))) tokens -1))
+ (push (list 'text (slice str pos (- tag-start pos))) tokens -1))
(push (list 'tag $0) tokens -1)
(set 'str (slice str (+ tag-start (length $0))))
(set 'pos 0))
; leftovers
(if (< pos len)
- (push (list 'text (slice str pos (- len pos))) tokens -1))
- tokens)
-)
+ (push (list 'text (slice str pos (- len pos))) tokens -1))
+ tokens))
-(define (escape-special-chars-within-tag-attributes txt)
+(define (escape-special-chars txt (within-tag-attributes nil))
(let ((temp (tokenize-html txt))
- (new-text {})
- )
+ (new-text {}))
(dolist (pair temp)
- (if (= (first pair) 'tag)
- ; 'tag
- (begin
+ (if (= (first pair) 'tag)
+ ; 'tag
+ (begin
(set 'new-text (replace {\\} (last pair) (lookup {\\} *escape-table*) 0))
(replace [text](?<=.)</?code>(?=.)[/text] new-text (lookup {`} *escape-table*) 0)
(replace {\*} new-text (lookup {*} *escape-table*) 0)
- (replace {_} new-text (lookup {_} *escape-table*) 0)
- )
- ; 'text
- (set 'new-text (last pair))
- )
- (setf (temp $idx) (list (first pair) new-text)))
- (join (map last temp)) ; return as text
- )
-)
-
-(define (escape-special-chars txt )
- ; replaces characters in tags and text tokens
- (let ((temp (tokenize-html txt))
- (new-text {})
- )
- (dolist (pair temp)
- (if (= (first pair) 'tag)
- ; 'tag
- (begin
- (set 'new-text (replace {\\} (last pair) (lookup {\\} *escape-table*) 0))
- (replace [text](?<=.)</?code>(?=.)[/text] new-text (lookup {`} *escape-table*) 0)
- (replace {\*} new-text (lookup {*} *escape-table*) 0)
- (replace {_} new-text (lookup {_} *escape-table*) 0)
- )
- ; 'text
- (begin
- (set 'new-text (encode-backslash-escapes (last pair)))))
- (setf (temp $idx) (list (first pair) new-text)))
- (join (map last temp)) ; return as text
- )
-)
+ (replace {_} new-text (lookup {_} *escape-table*) 0))
+ ; 'text
+ (if within-tag-attributes
+ (set 'new-text (last pair))
+ (set 'new-text (encode-backslash-escapes (last pair)))))
+ (setf (temp $idx) (list (first pair) new-text)))
+ ; return as text
+ (join (map last temp))))
(define (encode-backslash-escapes t)
(dolist (pair *escape-pairs*)
@@ -201,34 +180,29 @@
(replace "{" s (lookup "{" *escape-table*) 0)
(replace {\[} s (lookup {[} *escape-table*) 0)
(replace {\]} s (lookup {]} *escape-table*) 0)
- (replace {\\} s (lookup {\\} *escape-table*) 0)
- s)
+ (replace {\\} s (lookup {\} *escape-table*) 0))
(define (code-spans s)
(replace
{(?<!\\)(`+)(.+?)(?<!`)\1(?!`)}
s
(string {<code>} (encode-code (trim $2)) {</code>})
- 2
- )
- s)
+ 2))
(define (encode-alt s)
(replace {&} s "&amp;" 0)
- (replace {"} s "&quot;" 0)
- s)
+ (replace {"} s "&quot;" 0))
(define (images txt)
(let ((alt-text {})
(url {} )
(title {})
- (ref-regex {(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])})
+ (ref-regex {(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])})
(inline-regex {(!\[(.*?)\]\([ \t]*<?(\S+?)>?[ \t]*((['"])(.*?)\5[ \t]*)?\))})
- (whole-match {})
+ (whole-match {})
(result {})
(id-ref {})
- (url {})
- )
+ (url {}))
; reference links ![alt text][id]
(replace
ref-regex
@@ -238,7 +212,7 @@
(if alt-text
(replace {"} alt-text {&quot;} 0))
(if (empty? id-ref)
- (set 'id-ref (lower-case alt-text)))
+ (set 'id-ref (lower-case alt-text)))
(if (lookup id-ref *link-database*)
(set 'url (first (lookup id-ref *link-database*)))
(set 'url nil))
@@ -304,51 +278,41 @@
(replace {!\[(.*?)\]\([ \t]*\)}
txt
(string {<img src="" alt="} $1 {" title="" />})
- 0
- )
-
- )
- txt)
+ 0)))
(define (make-anchor link-text id-ref )
; Link defs are in the form: ^[id]: url "optional title"
; stored in link db list as (id (url title))
; params are text to be linked and the id of the link in the db
; eg bar 1 for [bar][1]
- (let (
- (title {})
- (id id-ref)
- (url nil)
- )
- (if link-text
- (begin
- (replace {"} link-text {&quot;} 0)
- (replace {\n} link-text { } 0)
- (replace {[ ]?\n} link-text { } 0)
- ))
- (if (null? id ) (set 'id (lower-case link-text)))
- (if (not (nil? (lookup id *link-database*)))
- (begin
- (set 'url (first (lookup id *link-database*)))
- (replace {\*} url (lookup {*} *escape-table*) 0)
- (replace {_} url (lookup {_} *escape-table*) 0)
- (if (set 'title (last (lookup id *link-database*)))
- (begin
- (replace {"} title {&quot;} 0)
- (replace {\*} title (lookup {*} *escape-table*) 0)
- (replace {_} title (lookup {_} *escape-table*) 0))
- (set 'title {})))
- (set 'url nil))
- (if url
- (string {<a href="}
- (trim url)
- {"}
- (if (not (= title {}))
- (string { title="} (trim title) {"}) {})
- {>} link-text {</a>})
- (string {[} link-text {][} id-ref {]}))
- )
-)
+
+ (let ((title {})
+ (id id-ref)
+ (url nil))
+ (if link-text
+ (begin
+ (replace {"} link-text {&quot;} 0)
+ (replace {\n} link-text { } 0)
+ (replace {[ ]?\n} link-text { } 0)))
+ (if (null? id ) (set 'id (lower-case link-text)))
+ (if (not (nil? (lookup id *link-database*)))
+ (begin
+ (set 'url (first (lookup id *link-database*)))
+ (replace {\*} url (lookup {*} *escape-table*) 0)
+ (replace {_} url (lookup {_} *escape-table*) 0)
+ (if (set 'title (last (lookup id *link-database*)))
+ (begin
+ (replace {"} title {&quot;} 0)
+ (replace {\*} title (lookup {*} *escape-table*) 0)
+ (replace {_} title (lookup {_} *escape-table*) 0))
+ (set 'title {})))
+ (set 'url nil))
+ (if url
+ (string {<a href="} (trim url)
+ {"}
+ (if (not (= title {})) (string { title="} (trim title) {"}) {})
+ {>} link-text {</a>})
+ (string {[} link-text {][} id-ref {]}))))
(define (anchors txt)
(letn ((nested-brackets {(?>[^\[\]]+)*})
@@ -356,10 +320,13 @@
(inline-regex {(\[(.*?)\]\([ ]*<?(.*?\)?)>?[ ]*((['"])(.*?)\5[ \t]*)?\))})
(link-text {})
(url {})
- (title {})
- )
+ (title {}))
; reference-style links: [link text] [id]
(set '$1 {} '$2 {} '$3 {} '$4 {} '$5 {} '$6 {}) ; i still don't think I should have to do this...
+
+ ; what about this regex instead?
+ (set 'ref-link-regex {(\[(.*?)\][ ]?\[(.*?)\])})
+
(replace ref-link-regex txt (make-anchor $2 $3) 8) ; $2 is link text, $3 is id
; inline links: [link text](url "optional title")
(set '$1 {} '$2 {} '$3 {} '$4 {} '$5 {} '$6 {})
@@ -374,7 +341,7 @@
(if title
(begin
(replace {"} title {&quot;} 0)
- (replace {\*} title (lookup {*} *escape-table*) 0)
+ (replace {\*} title (lookup {*} *escape-table*) 0)
(replace {_} title (lookup {_} *escape-table*) 0))
(set 'title {}))
(replace {\*} url (lookup {*} *escape-table*) 0)
@@ -391,8 +358,7 @@
))
8
) ; replace
- )
- txt)
+ ) txt)
(define (auto-links txt)
(replace
@@ -402,7 +368,7 @@
0
)
; to-do: email ...
- txt)
+)
(define (amps-and-angles txt)
; Smart processing for ampersands and angle brackets
@@ -416,9 +382,7 @@
[text]<(?![a-z/?\$!])[/text]
txt
{&lt;}
- 10
- )
- txt)
+ 10))
(define (emphasis txt)
; italics/bold: strong first
@@ -433,13 +397,11 @@
txt
(string {<em>} $2 {</em>})
8
- )
- txt)
+ ))
(define (line-breaks txt)
; handles line break markers
- (replace " {2,}\n" txt " <br/>\n" 0)
- txt)
+ (replace " {2,}\n" txt " <br/>\n" 0))
(define (hex-str-to-unicode-char strng)
; given a five character string, assume it's "U" + 4 hex chars and convert
@@ -447,6 +409,7 @@
(char (int (string "0x" (1 strng)) 0 16)))
(define (ustring s)
+ ; any four digit string preceded by U
(replace "U[0-9a-f]{4,}" s (hex-str-to-unicode-char $0) 0))
(define (cleanup txt)
@@ -458,10 +421,10 @@
; convert inline Unicode:
(set 'txt (ustring txt))
(replace "\n[ \t]+\n" txt "\n\n" 0) ; lines with only spaces and tabs
- txt)
+ )
(define (protect txt)
- ; protect or "hash html blocks"
+ ; protect or "hash html blocks"
(letn ((nested-block-regex [text](^<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b(.*\n)*?</\2>[ \t]*(?=\n+|\Z))[/text])
(liberal-tag-regex [text](^<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b(.*\n)*?.*</\2>[ \t]*(?=\n+|\Z))[/text])
(hr-regex [text](?:(?<=\n\n)|\A\n?)([ ]{0,3}<(hr)\b([^<>])*?/?>[ \t]*(?=\n{2,}|\Z))[/text])
@@ -477,30 +440,25 @@
(for (i 0 chunk-count chunk-size)
; do a chunk
(set 'text-chunk (join (i (- (min chunk-count (- (+ i chunk-size) 1)) i) chunks) "\n\n"))
- (dolist (rgx (list nested-block-regex liberal-tag-regex hr-regex html-comment-regex))
- (replace
- rgx
+ (dolist (rgx (list nested-block-regex liberal-tag-regex hr-regex html-comment-regex))
+ (replace
+ rgx
text-chunk
- (begin
- (set 'key (hash $1))
- (push (list key $1 ) *hashed-html-blocks* -1)
- (string "\n\n" key "\n\n"))
- 2)
- )
+ (begin
+ (set 'key (hash $1))
+ (push (list key $1 ) *hashed-html-blocks* -1)
+ (string "\n\n" key "\n\n"))
+ 2))
; save this partial result
(push text-chunk results -1)
) ; for
; return string result
- (join results "\n\n")
- )
- )
+ (join results "\n\n")))
(define (unescape-special-chars t)
- ; Swap back in all the special characters we've hidden.
+ ; Swap back in all the special characters we've hidden.
(dolist (pair *escape-table*)
- (replace (last pair) t (first pair) 10)
- )
- t)
+ (replace (last pair) t (first pair) 10)) t)
(define (strip-link-definitions txt)
; strip link definitions from the text and store them
@@ -509,68 +467,61 @@
(let ((link-db '())
(url {})
(id {})
- (title {})
- )
- (replace
- [text]^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(?<=\s)["(](.+?)[")][ \t]*)?(?:\n+|\Z)[/text]
- txt
- (begin
- (set 'id (lower-case $1) 'url (amps-and-angles $2) 'title $3)
- (if title (replace {"} title {&quot;} 0))
- (push (list id (list url title)) link-db)
- (set '$3 {}) ; necessary?
- (string {}) ; remove from text
- )
- 10)
- (set '*link-database* link-db)
- txt
- )
-)
+ (title {}))
+ (replace
+ [text]^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(?<=\s)["(](.+?)[")][ \t]*)?(?:\n+|\Z)[/text]
+ txt
+ (begin
+ (set 'id (lower-case $1) 'url (amps-and-angles $2) 'title $3)
+ (if title (replace {"} title {&quot;} 0))
+ (push (list id (list url title)) link-db)
+ (set '$3 {}) ; necessary?
+ (string {}) ; remove from text
+ )
+ 10)
+ (set '*link-database* link-db)
+ txt))
(define (horizontal-rules txt)
- (replace
+ (replace
[text]^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$[/text]
txt
"\n<hr />"
14)
- (replace
- [text]^[ ]{0,2}([ ]? -[ ]?){3,}[ \t]*$[/text]
- txt
- "\n<hr />"
- 14)
- (replace
+ (replace
+ [text]^[ ]{0,2}([ ]? -[ ]?){3,}[ \t]*$[/text]
+ txt
+ "\n<hr />"
+ 14)
+ (replace
[text]^[ ]{0,2}([ ]? _[ ]?){3,}[ \t]*$[/text]
txt
"\n<hr />"
- 14)
- txt)
+ 14))
(define (headers txt)
; setext headers
- (let ((level 1)
- )
- (replace
- [text]^(.+)[ \t]*\n=+[ \t]*\n+[/text]
- txt
- (string "<h1>" (span-transforms $1) "</h1>\n\n")
- 2)
+ (let ((level 1))
+ (replace
+ [text]^(.+)[ \t]*\n=+[ \t]*\n+[/text]
+ txt
+ (string "<h1>" (span-transforms $1) "</h1>\n\n")
+ 2)
- (replace
- [text]^(.+)[ \t]*\n-+[ \t]*\n+[/text]
- txt
- (string "<h2>" (span-transforms $1) "</h2>\n\n")
- 2)
+ (replace
+ [text]^(.+)[ \t]*\n-+[ \t]*\n+[/text]
+ txt
+ (string "<h2>" (span-transforms $1) "</h2>\n\n")
+ 2)
; atx headers
- (replace
- [text]^(\#{1,6})\s*(.+?)[ ]*\#*(\n+)[/text]
- txt
- (begin
- (set 'level (length $1))
- (string "<h" level ">" (span-transforms $2) "</h" level ">\n\n")
- )
- 2)
- )
- txt)
+ (replace
+ [text]^(\#{1,6})\s*(.+?)[ ]*\#*(\n+)[/text]
+ txt
+ (begin
+ (set 'level (length $1))
+ (string "<h" level ">" (span-transforms $2) "</h" level ">\n\n")
+ )
+ 2)))
(define (lists txt)
(letn ((marker-ul {[*+-]})
@@ -579,8 +530,7 @@
(whole-list-regex (string [text](([ ]{0,3}([/text] marker-any [text])[ \t]+)(?s:.+?)(\z|\n{2,}(?=\S)(?![ \t]*[/text] marker-any [text][ \t]+)))[/text]))
(my-list {})
(list-type {})
- (my-result {})
- )
+ (my-result {}))
(replace
(if (> *list-level* 0)
(string {^} whole-list-regex)
@@ -596,63 +546,52 @@
(replace {\s+$} my-result {} 0)
(string {<} list-type {>} "\n" my-result "\n" {</} list-type {>} "\n"))
10 ; must be multiline
- )
- )
- txt
-)
+ )))
(define (process-list-items list-text marker-any)
(let ((list-regex (string [text](\n)?(^[ \t]*)([/text] marker-any [text])[ \t]+((?s:.+?)(\n{1,2}))(?=\n*(\z|\2([/text] marker-any [text])[ \t]+))[/text]))
(item {})
(leading-line {})
(leading-space {})
- (result {})
- )
- (inc *list-level*)
- (replace [text]\n{2,}\z[/text] list-text "\n" 0)
- (set '$1 {} '$2 {} '$3 {} '$4 {} '$5 {})
- (replace
- list-regex
- list-text
- (begin
- (set 'item $4)
- (set 'leading-line $1)
- (set 'leading-space $2)
- (if (or (not (empty? leading-line)) (ends-with item "\n{2,}" 0))
- (set 'item (block-transforms (outdent item)))
- ; recurse for sub lists
- (begin
- (set 'item (lists (outdent item)))
- (set 'item (span-transforms (trim item "\n")))
- ))
- (string {<li>} item {</li>} "\n")
- )
- 10)
- (dec *list-level*)
- list-text
- )
-)
+ (result {}))
+ (inc *list-level*)
+ (replace [text]\n{2,}\z[/text] list-text "\n" 0)
+ (set '$1 {} '$2 {} '$3 {} '$4 {} '$5 {})
+ (replace
+ list-regex
+ list-text
+ (begin
+ (set 'item $4)
+ (set 'leading-line $1)
+ (set 'leading-space $2)
+ (if (or (not (empty? leading-line)) (ends-with item "\n{2,}" 0))
+ (set 'item (block-transforms (outdent item)))
+ ; recurse for sub lists
+ (begin
+ (set 'item (lists (outdent item)))
+ (set 'item (span-transforms (trim item "\n")))
+ ))
+ (string {<li>} item {</li>} "\n"))
+ 10)
+ (dec *list-level*)
+ list-text))
(define (code-blocks txt)
(let ((code-block {})
- (token-list '())
- )
+ (token-list '()))
(replace
[text](?:\n\n|\A)((?:(?:[ ]{4}|\t).*\n+)+)((?=^[ ]{0,3}\S)|\Z)[/text]
txt
(begin
(set 'code-block $1)
-
; format if Nestor module is loaded and it's not marked as plain
(if (and (not (starts-with code-block " ;plain\n")) (context? Nestor))
; format newlisp
(begin
; remove flag if present
- (replace "[ ]{4};newlisp\n" code-block {} 0)
+ (replace "[ ]{4};newlisp\n" code-block {} 0)
(set 'code-block (protect (Nestor:nlx-to-html (Nestor:my-read (trim (detab (outdent code-block)) "\n")))))
- code-block
- )
-
+ code-block)
; don't format
(begin
; trim leading and trailing newlines
@@ -660,44 +599,35 @@
(set 'code-block (trim (detab (encode-code (outdent code-block))) "\n"))
(set '$1 {})
(set 'code-block (string "\n\n<pre><code>" code-block "\n</code></pre>\n\n")))))
- 10
- )
- )
- txt)
+ 10)))
(define (block-quotes txt)
- (let ((block-quote {})
- )
- (replace
- [text]((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)[/text]
- txt
- (begin
- (set 'block-quote $1)
- (replace {^[ ]*>[ ]?} block-quote {} 2)
- (replace {^[ ]+$} block-quote {} 2)
- (set 'block-quote (block-transforms block-quote)) ; recurse
- ; remove leading spaces
- (replace
- {(\s*<pre>.+?</pre>)}
- block-quote
- (trim $1)
- 2)
- (string "<blockquote>\n" block-quote "\n</blockquote>\n\n"))
- 2
- )
- )
- txt)
+ (let ((block-quote {}))
+ (replace
+ [text]((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)[/text]
+ txt
+ (begin
+ (set 'block-quote $1)
+ (replace {^[ ]*>[ ]?} block-quote {} 2)
+ (replace {^[ ]+$} block-quote {} 2)
+ (set 'block-quote (block-transforms block-quote)) ; recurse
+ ; remove leading spaces
+ (replace
+ {(\s*<pre>.+?</pre>)}
+ block-quote
+ (trim $1)
+ 2)
+ (string "<blockquote>\n" block-quote "\n</blockquote>\n\n"))
+ 2)))
(define (outdent s)
- (replace [text]^(\t|[ ]{1,4})[/text] s {} 2)
- s)
+ (replace [text]^(\t|[ ]{1,4})[/text] s {} 2))
(define (detab s)
(replace [text](.*?)\t[/text]
s
(string $1 (dup { } (- 4 (% (length $1) 4))))
- 2)
- )
+ 2))
(define (form-paragraphs txt)
(let ((grafs '())
@@ -709,10 +639,25 @@
; html blocks
(setf (grafs $idx) original)
; wrap <p> tags round everything else
- (setf (grafs $idx) (string {<p>} (replace {^[ ]*} (span-transforms p) {} (+ 4 8 16)) {</p>}))
- ))
- (join grafs "\n\n")
- )
-)
-
-; the end
+ (setf (grafs $idx) (string {<p>} (replace {^[ ]*} (span-transforms p) {} (+ 4 8 16)) {</p>}))))
+ (join grafs "\n\n")))
+
+; three command line arguments: let's hope last one is a file
+(when (= 3 (length (main-args)))
+ (println (markdown (read-file (main-args 2))))
+ (exit))
+
+; hack for command-line and module loading
+(set 'level (sys-info 3))
+
+; if level is 2, then we're probably invoking markdown.lsp directly
+; if level is > 3, then we're probably loading it into another script...
+
+(when (= level 2)
+ ; running on command line, read STDIN and execute:
+ (while (read-line)
+ (push (current-line) *stdin* -1))
+ (println (markdown (join *stdin* "\n")))
+ (exit))
+
+; eof
View
1  nldb/nldb.lsp
@@ -8,6 +8,7 @@
;; to install or use something better, such as sqlite.
;; Data is stored in a list of lists. The first row is a list of column names, stored as symbols.
;; List elements can be numbers, strings, or lists.
+;; </p>
(context 'nldb)
Please sign in to comment.
Something went wrong with that request. Please try again.