Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
compiled/
.DS_Store
*~
\#*
17 changes: 17 additions & 0 deletions markdown/base.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#lang racket

(require "parse.rkt"
"display-xexpr.rkt"
"toc.rkt")

(provide (all-from-out "parse.rkt")
(all-from-out "display-xexpr.rkt")
(all-from-out "toc.rkt")
markdown->html)

(define (markdown->html md)
(with-output-to-string
(lambda ()
(display "<!DOCTYPE html>")
(display-xexpr `(html (head () (meta ([charset "utf-8"])))
(body () ,@md))))))
6 changes: 6 additions & 0 deletions markdown/lang.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#lang racket

(require "main.rkt")

(provide (all-from-out "main.rkt")
(rename-out [module-begin/markdown #%module-begin]))
11 changes: 11 additions & 0 deletions markdown/lang/reader.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#lang s-exp syntax/module-reader
markdown/lang

#:read read-markdown
#:read-syntax read-markdown-syntax
#:whole-body-readers? #t

(require "../parse.rkt")

(define (read-markdown-syntax source in)
(datum->syntax #f (read-markdown in)))
19 changes: 10 additions & 9 deletions markdown/main.rkt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#lang racket

(require "parse.rkt"
"display-xexpr.rkt"
"toc.rkt")
(require "base.rkt"
(for-syntax racket
"base.rkt"))

(provide (all-from-out "parse.rkt")
(all-from-out "display-xexpr.rkt")
(all-from-out "toc.rkt"))
(provide (all-from-out "base.rkt")
module-begin/markdown)

(define-syntax-rule (module-begin/markdown body ...)
(#%plain-module-begin
(display (markdown->html '(body ...)))))

;; For use as command-line pipe.
(module+ main
(display "<!DOCTYPE html>")
(display-xexpr `(html (head () (meta ([charset "utf-8"])))
(body () ,@(read-markdown)))))
(display (markdown->html (read-markdown))))
6 changes: 3 additions & 3 deletions markdown/parse.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

(provide
(contract-out
[read-markdown (->* () (symbol?) xexpr-element-list?)]
[read-markdown (->* () (input-port? symbol?) xexpr-element-list?)]
[parse-markdown (->* ((or/c string? path?)) (symbol?) xexpr-element-list?)]
[current-strict-markdown? (parameter/c boolean?)]))

Expand Down Expand Up @@ -125,8 +125,8 @@
normalize-xexprs))

;; For backward compatibility
(define (read-markdown [footnote-prefix-symbol (gensym)])
(parse-markdown (port->string (current-input-port)) footnote-prefix-symbol))
(define (read-markdown [in-port (current-input-port)] [footnote-prefix-symbol (gensym)])

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the pull request!

I'm reviewing this quickly, not much free time now, so maybe I'm misunderstanding, but:

Wouldn't the new optional argument in-port need to come after the existing optional argument footnote-prefix-symbol? For backward compatibility?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are absolutely correct that adding it to the front breaks backwards compatibility. Although for whatever it's worth, changing it to this causes it to follow the read read-syntax etc. convention. Also, afaik, the functions need to have that api to work in the lang/reader.rkt file. However, if you don't want to break backwards compatibility we could always make other functions we use internally that use this api.

It seems like neither frog nor this library rely on that argument, but I'm not sure of what other code does.

Either way is fine with me though. It's a matter of keeping to conventions and reducing complexity, or keeping backwards compatibility.

(parse-markdown (port->string in-port) footnote-prefix-symbol))

;; Parameter to limit us to strict markdown (no customizations).
(define current-strict-markdown? (make-parameter #f))
Expand Down