Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for embedded markdown formatting #1

Open
jeberger opened this issue Feb 1, 2019 · 3 comments
Open

Add support for embedded markdown formatting #1

jeberger opened this issue Feb 1, 2019 · 3 comments

Comments

@jeberger
Copy link

jeberger commented Feb 1, 2019

It would be nice if embedded markdown formatting were recognized. Today I have the following in my configuration to add support for bold, italic and code:

(defun jmb/doxygen-add-markdown (rules)
  (-concat
   rules
   `(
     ;; Markdown

     ;; `code`    not code   `code`again`    not`code`embedded   `code``again`
     ;; `code`,   not code   `code again``   not code            `code`
     (,(rx space
           (group ?` (not (any space "\r\n`"))
                  (* (or (not (any ?`))
                         (: (+ ?`) (not (any space punctuation "\r\n")))))
                  (+ ?`))
           (or (any space punctuation "\r\n") eol))
      1 (quote underline) prepend nil)
     ;; *italic*  not italic *italic*again*  not*italic*embedded *italic**again*
     ;; *italic*, not italic *italic again** not italic          *italic*
     ;; _italic_  not italic _italic_again_  not_italic_embedded _italic__again_
     ;; _italic_, not italic _italic again__ not italic          _italic_
     (,(rx space
           (group
            (or (: ?* (not (any space "\r\n*"))
                   (* (or (not (any ?*))
                          (: (+ ?*) (not (any space punctuation "\r\n")))))
                   ?*)
                (: ?_ (not (any space "\r\n_"))
                   (* (or (not (any ?_))
                          (: (+ ?_) (not (any space punctuation "\r\n")))))
                   ?_)))
           (or (any space punctuation "\r\n") eol))
      1 (quote italic) prepend nil)
     ;; **bold**  not bold   **bold*again**  not**bold**embedded **bold***again**
     ;; **bold**, not bold   **bold again*** not bold            **bold**
     ;; __bold__  not bold   __bold_again__  not__bold__embedded __bold___again__
     ;; __bold__, not bold   __bold again___ not bold            __bold__
     (,(rx space
           (group
            (or (: "**" (not (any space "\r\n*"))
                   (* (or (: (? ?*) (not (any ?*)))
                          (: (+ "*") (not (any space punctuation "\r\n")))))
                   "**")
                (: "__" (not (any space "\r\n_"))
                   (* (or (: (? ?_) (not (any ?_)))
                          (: (+ "_") (not (any space punctuation "\r\n")))))
                   "__")))
           (or (any space punctuation "\r\n") eol))
      1 (quote bold) prepend nil)
     )))

(advice-add
 #'highlight-doxygen-compose-font-lock-keywords
 :filter-return
 #'jmb/doxygen-add-markdown)

Note that highlight-doxygen already has basic support for "code" format using backticks, but the current support is broken: the following text is not properly formatted:

 `code`    not code   `code`again`    not`code`embedded   `code``again`
 `code`,   not code   `code again``   not code            `code`
@Lindydancer
Copy link
Owner

Lindydancer commented Feb 4, 2019 via email

@jeberger
Copy link
Author

jeberger commented Feb 8, 2019

Actually it's wrong (this was just a quick port of what I used to have for doxymacs-mode). The extra rules should be added to highlight-doxygen-anchored-keywords-template instead of highlight-doxygen-compose-font-lock-keywords, and the highlight rule in each item in the list should be wrapped in a sub-list like this:

;; `code`    not code   `code`again`    not`code`embedded   `code``again`
;; `code`,   not code   `code again``   not code            `code`
(,(rx space
      (group ?` (not (any space "\r\n`"))
             (* (or (not (any ?`))
                    (: (+ ?`) (not (any space punctuation "\r\n")))))
             (+ ?`))
      (or (any space punctuation "\r\n") eol))
 (1 (quote underline) prepend nil)) ; <- original code had these items directly in the rule without the sublist

I'll try and make a proper PR this weekend.

@Lindydancer
Copy link
Owner

Lindydancer commented Feb 8, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants