Skip to content

Commit

Permalink
Update to CommonMark v0.31.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lexi-lambda committed Oct 7, 2024
1 parent f34feb8 commit f28bafb
Show file tree
Hide file tree
Showing 6 changed files with 1,582 additions and 1,582 deletions.
4 changes: 2 additions & 2 deletions commonmark-doc/scribblings/commonmark.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
values))
(apply hyperlink
#:style style
(~a "https://spec.commonmark.org/0.30/#"
(~a "https://spec.commonmark.org/0.31.2/#"
(~> (string-foldcase tag)
maybe-singularize
(string-replace #px"[^a-z]+" "-")))
Expand All @@ -70,7 +70,7 @@

@defmodule[commonmark]{

The @racketmodname[commonmark] library implements a @|CommonMark|-compliant Markdown parser. Currently, it passes all test cases in @hyperlink["https://spec.commonmark.org/0.30/"]{v0.30 of the specification}. By default, only the Markdown features specified by @CommonMark are supported, but non-standard support for @tech{footnotes} can be optionally enabled; see the @secref{extensions} section of this manual for more details.
The @racketmodname[commonmark] library implements a @|CommonMark|-compliant Markdown parser. Currently, it passes all test cases in @hyperlink["https://spec.commonmark.org/0.31.2/"]{v0.31.2 of the specification}. By default, only the Markdown features specified by @CommonMark are supported, but non-standard support for @tech{footnotes} can be optionally enabled; see the @secref{extensions} section of this manual for more details.

The @racketmodname[commonmark] module reprovides all of the bindings provided by @racketmodname[commonmark/parse] and @racketmodname[commonmark/render/html] (but @emph{not} the bindings provided by @racketmodname[commonmark/struct]).}

Expand Down
10 changes: 5 additions & 5 deletions commonmark-lib/commonmark/private/parse/block.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(:* "\\1[ \t]*" #:min 2)
:eol))

;; <https://spec.commonmark.org/0.30/#list-marker>
;; <https://spec.commonmark.org/0.31.2/#list-marker>
(define-for-syntax (:list-marker #:interrupt? interrupt?)
; If the list is ordered, it can only interrupt a paragraph if the
; start number is 1.
Expand Down Expand Up @@ -330,7 +330,7 @@
(set! partially-consumed-tab? #f)
(list* full-match indent group-matches)]))))

;; <https://spec.commonmark.org/0.30/#block-quote-marker>
;; <https://spec.commonmark.org/0.31.2/#block-quote-marker>
(define (try-read-blockquote-marker)
(try-with-optional-indent
(λ (pos indent)
Expand All @@ -355,7 +355,7 @@
#t]
[_ #f]))))

;; <https://spec.commonmark.org/0.30/#list-marker>
;; <https://spec.commonmark.org/0.31.2/#list-marker>
(define (try-read-list-marker #:interrupt? interrupt?)
(try-with-optional-indent
(λ (pos indent)
Expand Down Expand Up @@ -545,7 +545,7 @@
"h3" "h4" "h5" "h6" "head" "header" "hr" "html"
"iframe" "legend" "li" "link" "main" "menu"
"menuitem" "nav" "noframes" "ol" "optgroup"
"option" "p" "param" "section" "source"
"option" "p" "param" "search" "section"
"summary" "table" "tbody" "td" "tfoot" "th"
"thead" "title" "tr" "track" "ul"))
(:or "[ \t>]" :eol "/>"))))))
Expand Down Expand Up @@ -998,7 +998,7 @@ of the list item. |#
;; Link reference definitions

;; § 4.7 Link reference definitions
;; <https://spec.commonmark.org/0.30/#link-reference-definition>
;; <https://spec.commonmark.org/0.31.2/#link-reference-definition>
(define (try-read-link-reference-definition in)
(define (try-peek-eol start-pos)
(match (regexp-match-peek-positions (px "^" "[ \t\r\n]*" :eol) in start-pos)
Expand Down
20 changes: 10 additions & 10 deletions commonmark-lib/commonmark/private/parse/common.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
;; § 2.1 Characters and lines

(begin-for-syntax
; <https://spec.commonmark.org/0.30/#line-ending>
; <https://spec.commonmark.org/0.31.2/#line-ending>
(define :newline (:: "\n|\r\n?"))
; <https://spec.commonmark.org/0.30/#ascii-punctuation-character>
; <https://spec.commonmark.org/0.31.2/#ascii-punctuation-character>
(define :ascii-punctuation "[!-/:-@[-`{-~]")
; <https://spec.commonmark.org/0.30/#ascii-control-character>
; <https://spec.commonmark.org/0.31.2/#ascii-control-character>
(define :ascii-control: "\0-\x1F\x7F")

; Often referred to in the spec using the phrase “spaces, tabs, and up to one
Expand All @@ -47,12 +47,12 @@
(define :space* (:* "[" :space: "]"))
(define :space+ (:+ "[" :space: "]"))

; <https://spec.commonmark.org/0.30/#link-destination>
; <https://spec.commonmark.org/0.31.2/#link-destination>
(define :link-destination
(:or "<([^\r\n]*?)(?<!\\\\)>"
(:group "[^< " :ascii-control: "]")))

;; § 6.5 Raw HTML <https://spec.commonmark.org/0.30/#raw-html>
;; § 6.5 Raw HTML <https://spec.commonmark.org/0.31.2/#raw-html>
(define (:html-open-close #:allow-newlines? allow-newlines?)
(define-values [:sp: :sp* :sp+ :nl:]
(if allow-newlines?
Expand Down Expand Up @@ -86,8 +86,8 @@
(char<=? #\{ c #\~)))

(define (unicode-punctuation? c)
(or (ascii-punctuation? c)
(memq (char-general-category c) '(pc pd pe pf pi po ps))))
(or (char-punctuation? c)
(char-symbolic? c)))

;; -----------------------------------------------------------------------------

Expand All @@ -106,21 +106,21 @@
"\\]")
in start-pos)
[(list peeked-bytes (app bytes->string/utf-8 label-str))
; From <https://spec.commonmark.org/0.30/#link-label>:
; From <https://spec.commonmark.org/0.31.2/#link-label>:
; “Between these brackets there must be at least one character that is
; not a space, tab, or line ending.”
#:when (regexp-match? (px "[^" :space: "]") label-str)
(list (+ start-pos (bytes-length peeked-bytes))
(normalize-link-label label-str))]
[_ #f]))

;; <https://spec.commonmark.org/0.30/#matches>
;; <https://spec.commonmark.org/0.31.2/#matches>
(define (normalize-link-label str)
(~> (string-foldcase str)
(string-trim (px :space+))
(string-replace (px :space+) " ")))

;; <https://spec.commonmark.org/0.30/#link-destination>
;; <https://spec.commonmark.org/0.31.2/#link-destination>
(define (try-peek-link-destination in [start-pos 0])
(match (regexp-match-peek #px"^<([^\r\n]*?)(?<!\\\\)>" in start-pos)
; First, the simple case: a destination enclosed in <angle brackets>.
Expand Down
14 changes: 7 additions & 7 deletions commonmark-lib/commonmark/private/parse/inline.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
;; § 6.5 Raw HTML
(define :html-tag
(let ()
(define :comment (:: "<!--" "(?!>|->)" (:* (:or "[^-]" "-[^-]")) "-->"))
(define :instruction (:: "<\\?" (:* (:or "[^?]" "\\?[^>]")) "\\?>"))
(define :comment (:: "<!--" (:or ">" "->" (:: (:*? ".") "-->"))))
(define :instruction (:: "<\\?" (:*? ".") "\\?>"))
(define :declaration (:: "<!" "[a-zA-Z]" "[^>]*" ">"))
(define :cdata-section (:: "<!\\[CDATA\\[" (:* (:or "[^]]" "\\][^]]" "\\]\\][^>]")) "\\]\\]>"))
(define :cdata-section (:: "<!\\[CDATA\\[" (:*? ".") "\\]\\]>"))

(:or (:html-open-close #:allow-newlines? #t) :comment :instruction :declaration :cdata-section))))

Expand Down Expand Up @@ -312,15 +312,15 @@ positions in characters rather than bytes, which explains why we need to call

(define (try-read-link-target content-label-str)
(or
;; Full reference links <https://spec.commonmark.org/0.30/#reference-link>
;; Full reference links <https://spec.commonmark.org/0.31.2/#reference-link>
(match-and*
[(try-peek-link-label in) => (list label-pos label-str)]
[(hash-ref link-reference-defns label-str #f)
=> link-ref
(read-bytes label-pos in)
link-ref])

;; Inline links <https://spec.commonmark.org/0.30/#inline-link>
;; Inline links <https://spec.commonmark.org/0.31.2/#inline-link>
(let ()
(define (try-peek-end start-pos)
(match-and*
Expand Down Expand Up @@ -370,8 +370,8 @@ positions in characters rather than bytes, which explains why we need to call
(let ()
(define normalized-label (normalize-link-label content-label-str))
(or
;; Collapsed reference links <https://spec.commonmark.org/0.30/#collapsed-reference-link>,
;; and shortcut reference links <https://spec.commonmark.org/0.30/#shortcut-reference-link>
;; Collapsed reference links <https://spec.commonmark.org/0.31.2/#collapsed-reference-link>,
;; and shortcut reference links <https://spec.commonmark.org/0.31.2/#shortcut-reference-link>
(match-and*
[(hash-ref link-reference-defns normalized-label #f) => link-ref]
[(or (regexp-try-match #px"^\\[\\]" in)
Expand Down
Loading

0 comments on commit f28bafb

Please sign in to comment.