Improved version. Where applicable, it now uses the same regular expressions as the board software. Highlighting for code blocks has also been updated to handle multi-line better. Although I am unsure how much schemebbs-font-lock-extend-function
actually helps. Maybe there's a better way.
(defconst schemebbs-font-lock-rules
'(;; code
("^\\(```\\(.*\n\\)*?```\\)$" 1 font-lock-reference-face)
;; bold
("\\(\\*\\*[^ ].*?[^ ]\\*\\*\\|\\*\\*[^ ]\\*\\*\\)" 1 font-lock-keyword-face)
;; italic
("\\(__[^ ].*?[^ ]__\\|__[^ ]__\\)" 1 font-lock-comment-face)
;; monospaced
("\\(==[^ ].*?[^ ]==\\|==[^ ]==\\)" 1 font-lock-constant-face)
;; spoiler
("\\(~~[^ ].*?[^ ]~~\\|~~[^ ]~~\\)" 1 font-lock-type-face)
;; quotes
("^\\(>.+\\)" 1 font-lock-doc-face))
"Highlighting for SchemeBBS posts.")
(defun schemebbs-font-lock-extend-function ()
"Try to extend the update to the nearest code blocks."
(save-excursion
(goto-char font-lock-beg)
(when (re-search-backward "^```$" nil t)
(setq font-lock-beg (point)))
(goto-char font-lock-end)
(when (re-search-forward "^```$" nil t)
(setq font-lock-end (point)))))
(define-derived-mode schemebbs-mode text-mode "SchemeBBS"
"Basic highlighting for composing SchemeBBS posts."
(set (make-local-variable 'font-lock-defaults) '(schemebbs-font-lock-rules))
(set (make-local-variable 'font-lock-multilne) t)
(add-hook 'font-lock-extend-region-functions
'schemebbs-font-lock-extend-function))