diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2015-01-24 04:00:46 -0200 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2015-01-24 04:00:46 -0200 |
commit | 7ce3968e25c8c7a076f83f0b0d9d3b3b7d8afadc (patch) | |
tree | 786d050ebff6e1e741198acd3afe6535d8633921 /sx-question-print.el | |
parent | f6b00de6b91b2f52845d33a7ccf195409ad5c9f4 (diff) |
Handle the `code` html tag
Diffstat (limited to 'sx-question-print.el')
-rw-r--r-- | sx-question-print.el | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/sx-question-print.el b/sx-question-print.el index c10c43e..5be3133 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -370,12 +370,46 @@ E.g.: (forward-paragraph) (let ((end (point-marker))) ;; Compact links. + (sx-question-mode--process-html-tags beg end) + ;; Compact links. (sx-question-mode--process-links beg end) (goto-char end)) (fill-region beg (point))))) (replace-regexp-in-string "[[:blank:]]+\\'" "" (buffer-string)))) +;;; HTML tags +(defconst sx-question-mode--html-tag-regexp + (rx "<" (group-n 1 "%s") (* (not (any ">"))) ">")) + +(defun sx-question-mode--process-html-tags (beg end) + "Hide all html tags between BEG and END and possibly interpret them. +END should be a marker." + ;; This code understands nested html, but not if the same tag is + ;; nested in itself (e.g., <kbd><kbd></kbd></kbd>). + (goto-char beg) + (while (search-forward-regexp + (format sx-question-mode--html-tag-regexp "[[:alpha:]]+") + end 'noerror) + (unless (save-match-data (markdown-code-at-point-p)) + (let ((tag (match-string 1)) + (l (match-beginning 0))) + (replace-match "") + (when (search-forward-regexp + (format sx-question-mode--html-tag-regexp (concat "/" tag)) + ;; Searching for a match has no bounds. + nil 'noerror) + (let ((r (copy-marker (match-beginning 0)))) + ;; The code tag is special, because it quotes everything in + ;; the middle. + (if (string= tag "quote") + (progn (replace-match "`") + (save-excursion (goto-char l) (insert "`"))) + (replace-match "") + ;; Handle stuff between the two tags. + (save-match-data (sx-question-mode--process-html-tags l r))))))))) + + ;;; Handling links (defun sx-question-mode--process-links (beg end) "Turn all markdown links between BEG and ENG into compact format. |