Skip to content

Commit

Permalink
Add test case for source blocks without language attribute
Browse files Browse the repository at this point in the history
Restructure adoc-fontify-code-blocks and adoc-fontify-code-block-natively
such that things that are needed for blocks with and without language attribute
are done in adoc-fontify-code-blocks.
  • Loading branch information
Tobias Zawada authored and Tobias Zawada committed Feb 18, 2024
1 parent ba334ab commit c307889
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
31 changes: 13 additions & 18 deletions adoc-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2066,12 +2066,6 @@ START-SRC and END-SRC delimit the actual source code."
(put-text-property
(+ start-src (1- pos)) (1- (+ start-src next)) 'face
val adoc-buffer))))
(add-text-properties start-block start-src '(face adoc-meta-face))
(add-text-properties end-src end-block '(face adoc-meta-face))
(add-text-properties
start-block end-block
'(font-lock-fontified t fontified t font-lock-multiline t
adoc-code-block t adoc-reserved t))
(set-buffer-modified-p modified)))))

(defconst adoc-code-block-begin-regexp
Expand Down Expand Up @@ -2169,20 +2163,21 @@ Use this function as matching function MATCHER in `font-lock-keywords'."
(end-src+nl (if (eq (char-after end-src) ?\n) (1+ end-src) end-src))
(size (1+ (- end-src start-src))))
(if (and
(stringp lang)
(if (numberp adoc-fontify-code-blocks-natively)
(<= size adoc-fontify-code-blocks-natively)
adoc-fontify-code-blocks-natively)
(stringp lang))
(adoc-fontify-code-block-natively lang start-block end-block start-src end-src)
(add-text-properties
start-src
end-src
'(font-lock-face adoc-verbatim-face)))
;; Set background for block as well as opening and closing lines.
(font-lock-append-text-property
start-src end-src+nl 'face 'adoc-native-code-face)
(add-text-properties
start-src end-src+nl '(font-lock-fontified t font-lock-multiline t adoc-code-block t))
adoc-fontify-code-blocks-natively))
(progn
(adoc-fontify-code-block-natively lang start-block end-block start-src end-src)
(font-lock-append-text-property start-src end-src 'face 'adoc-native-code-face)
(add-text-properties end-src end-src+nl '(face adoc-native-code-face)))
;; code block without language attribute or too large
(add-text-properties start-src end-src '(face (adoc-verbatim-face adoc-code-face)))
(add-text-properties end-src end-src+nl '(face adoc-code-face)))
(add-text-properties start-block start-src '(face adoc-meta-face))
(put-text-property end-src+nl end-block 'face adoc-meta-face)
(add-text-properties start-src end-src+nl '(adoc-code-block t))
(add-text-properties start-block end-block '(font-lock-fontified t font-lock-multiline t adoc-reserved t))
)))
t)))

Expand Down
14 changes: 10 additions & 4 deletions test/adoc-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -349,26 +349,32 @@ Don't use it for anything real.")
"\n" nil
"[source,adoctest-lang]\n----\n" 'adoc-meta-face
source-code
"\n" '(adoc-meta-face adoc-native-code-face)
"\n" 'adoc-native-code-face
"----" 'adoc-meta-face
"\n" nil
;; Code blocks without language attribute
"[source]\n----\n" 'adoc-meta-face
(apply #'concat (cl-loop for str in source-code by #'cddr collect str)) '(adoc-verbatim-face adoc-code-face)
"\n" 'adoc-code-face
"----" 'adoc-meta-face
"\n" nil
;; Code block as OPEN BLOCK
"\n" nil
"[source,adoctest-lang]\n--\n" 'adoc-meta-face
source-code
"\n" '(adoc-meta-face adoc-native-code-face)
"\n" 'adoc-native-code-face
"--" 'adoc-meta-face
"\n" nil
;; Code block as Literal block
"[source,adoctest-lang]\n....\n" 'adoc-meta-face
source-code
"\n" '(adoc-meta-face adoc-native-code-face)
"\n" 'adoc-native-code-face
"...." 'adoc-meta-face
"\n" nil
;; Test ignored spaces
"[source,\t adoctest-lang]\t \n....\n" 'adoc-meta-face
source-code
"\n" '(adoc-meta-face adoc-native-code-face)
"\n" 'adoc-native-code-face
"...." 'adoc-meta-face
"\n" nil
))))
Expand Down

0 comments on commit c307889

Please sign in to comment.