emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/adoc-mode 950223b614 070/199: reworked highlighting of url


From: ELPA Syncer
Subject: [nongnu] elpa/adoc-mode 950223b614 070/199: reworked highlighting of urls
Date: Sun, 3 Sep 2023 06:59:35 -0400 (EDT)

branch: elpa/adoc-mode
commit 950223b614c90d0eb8ea9bb6aad4dce135f6e74a
Author: Florian Kaufmann <sensorflo@gmail.com>
Commit: Florian Kaufmann <sensorflo@gmail.com>

    reworked highlighting of urls
---
 adoc-mode-test.el | 27 +++++++++++++++++
 adoc-mode.el      | 86 +++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 95 insertions(+), 18 deletions(-)

diff --git a/adoc-mode-test.el b/adoc-mode-test.el
index 82c588e910..d91ed4915f 100644
--- a/adoc-mode-test.el
+++ b/adoc-mode-test.el
@@ -450,6 +450,33 @@
   ;; .... todo
   )
 
+(ert-deftest adoctest-test-url ()
+  (adoctest-faces "url"
+    ;; url inline macro with attriblist 
+    "foo " nil
+    "http://www.lorem.com/ipsum.html"; markup-internal-reference-face
+    "[" markup-meta-face "sit amet" markup-reference-face "]" markup-meta-face
+    " bar \n" nil
+    ;; url inline macro withOUT attriblist 
+    "http://www.lorem.com/ipsum.html"; markup-reference-face
+    "[]" markup-meta-face
+    " bar \n" nil
+    ;; plain url
+    "http://www.lorem.com/ipsum.html"; markup-reference-face
+    " foo " nil "joe.bloggs@foobar.com" markup-reference-face ))
+
+(ert-deftest adoctest-test-url-enclosing-quote ()
+  (adoctest-faces "url-enclosing-quote"
+    ;; spaces between __ and url seem really to be needed also in asciidoc 
+    "foo " nil "__" markup-meta-hide-face " " nil
+    "http://www.lorem.com/ipsum.html"; '(markup-emphasis-face 
markup-reference-face)
+    " " nil "__" markup-meta-hide-face
+
+    "\nfoo " nil
+    "**" markup-meta-hide-face " " nil
+    "joe.bloggs@foobar.com" '(markup-strong-face markup-reference-face)
+    " " nil "**" markup-meta-hide-face ))
+
 ;; inline substitutions only within the block they belong to. I.e. don't cross
 ;; block boundaries.
 (ert-deftest adoctest-test-inline-subst-boundaries ()
diff --git a/adoc-mode.el b/adoc-mode.el
index 40f4139786..a96c0268c8 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -1211,6 +1211,70 @@ considered to be meta characters."
    `(5 '(face markup-meta-face adoc-attribute-list ,(or attribute-list t)) t)
    '(6 '(face markup-meta-face adoc-reserved t) t))) ; ]
 
+;; largely copied from adoc-kw-inline-macro
+;; todo: output text should be affected by quotes & co, e.g. bold, emph, ...
+;; todo: for simplicity maybe split up in one for url[] and url[caption]
+(defun adoc-kw-inline-macro-urls-attriblist ()
+  (let ((cmd-name (regexp-opt '("http" "https" "ftp" "file" "irc" "mailto" 
"callto" "link")))
+       (attribute-list '(("caption") (("caption" . markup-reference-face)))))
+    (list
+     `(lambda (end) (adoc-kwf-std end ,(adoc-re-inline-macro cmd-name) '(0) 
'(0)))
+     `(1 '(face markup-internal-reference-face adoc-reserved t) t) ; cmd-name
+     `(2 '(face markup-internal-reference-face adoc-reserved t) t) ; :
+     `(3 '(face markup-internal-reference-face adoc-reserved t) t) ; target
+     '(4 '(face markup-meta-face adoc-reserved t) t)              ; [
+     `(5 '(face markup-reference-face adoc-attribute-list ,attribute-list) 
append)
+     '(6 '(face markup-meta-face adoc-reserved t) t))))            ; ]
+
+(defun adoc-kw-inline-macro-urls-no-attriblist ()
+  (let ((cmd-name (regexp-opt '("http" "https" "ftp" "file" "irc" "mailto" 
"callto" "link"))))
+    (list
+     `(lambda (end) (adoc-kwf-std end ,(adoc-re-inline-macro cmd-name nil t) 
'(0) '(0)))
+     '(1 '(face markup-reference-face adoc-reserved t) append) ; cmd-name
+     '(2 '(face markup-reference-face adoc-reserved t) append)              ; :
+     '(3 '(face markup-reference-face adoc-reserved t) append)              ; 
target
+     '(4 '(face markup-meta-face adoc-reserved t) t) ; [
+                                                    ; 5 = attriblist is empty
+     '(6 '(face markup-meta-face adoc-reserved t) t)))) ; ]
+
+;; standalone url
+;; From asciidoc.conf:
+;; # These URL types don't require any special attribute list formatting.
+;; 
(?su)(?<!\S)[\\]?(?P<name>http|https|ftp|file|irc):(?P<target>//[^\s<>]*[\w/])=
+;; # Allow a leading parenthesis and square bracket.
+;; 
(?su)(?<\=[([])[\\]?(?P<name>http|https|ftp|file|irc):(?P<target>//[^\s<>]*[\w/])=
+;; # Allow <> brackets.
+;; 
(?su)[\\]?&lt;(?P<name>http|https|ftp|file|irc):(?P<target>//[^\s<>]*[\w/])&gt;=
+;; 
+;; asciidoc.conf bug? why is it so restrictive for urls without attribute
+;; list, that version can only have a limited set of characters before. Why
+;; not just have the rule that it must start with \b.
+;;
+;; standalone email
+;; From asciidoc.conf:
+;; 
(?su)(?<![">:\w._/-])[\\]?(?P<target>\w[\w._-]*@[\w._-]*\w)(?!["<\w_-])=mailto
+;;
+;; todo: properly handle leading backslash escapes
+;;
+;; non-bugs: __flo@gmail.com__ is also in AsciiDoc *not* an emphasised email, 
it's
+;;   just an emphasised text. Thats because the quote transforms happen before
+;;   the url transform, thus the middle stage is something like
+;;   ...>flo@gmail.com<... According to asciidoc.conf regexps a leading > or a
+;;   trailing < are not allowed. In adoc-mode, the fontification is as in
+;;   AsciiDoc, but that's coincidence. The reason in adoc-mode is that the
+;;   regexps quantifier are greedy instead lazy, thus the trailing __ behind 
the
+;;   email are taken part as the email adress, and then adoc-kwf-std cant match
+;;   because part of the match (the __) contains text properties with
+;;   adoc-reserved non-nil, also because quote highlighting already happened.
+(defun adoc-kw-standalone-urls ()
+  (let* ((url "\\b\\(?:https?\\|ftp\\|file\\|irc\\)://[^ 
\t\n<>]*[a-zA-Z0-9_/]")
+        (url<> (concat "<\\(?:" url "\\)>")) 
+        (email "[a-zA-Z0-9_][-a-zA-Z0-9_._]*@[-a-zA-Z0-9_._]*[a-zA-Z0-9_]")
+        (both (concat "\\(?:" url "\\)\\|\\(?:" url<> "\\)\\|\\(?:" email 
"\\)")))
+    (list
+     `(lambda (end) (adoc-kwf-std end ,both '(0) '(0)))
+     '(0 '(face markup-reference-face adoc-reserved t) append t))))
+
 ;; bug: escapes are not handled yet
 ;; todo: give the inserted character a specific face. But I fear that is not
 ;; possible. The string inserted with the ovlerlay property after-string gets
@@ -1635,6 +1699,8 @@ considered to be meta characters."
    ;; 
 
    ;; Macros using default syntax, but having special highlighting in adoc-mode
+   (adoc-kw-inline-macro-urls-no-attriblist)
+   (adoc-kw-inline-macro-urls-attriblist)
    (adoc-kw-inline-macro "anchor" nil markup-anchor-face t '("xreflabel"))
    (adoc-kw-inline-macro "image" markup-complex-replacement-face 
markup-internal-reference-face t
      '("alt"))
@@ -1644,24 +1710,8 @@ considered to be meta characters."
    ;; Macros using default syntax and having default highlighting in adoc-mod
    (adoc-kw-inline-macro)  
    
-   ;; # These URL types don't require any special attribute list formatting.
-   ;; 
(?su)(?<!\S)[\\]?(?P<name>http|https|ftp|file|irc):(?P<target>//[^\s<>]*[\w/])=
-   ;; # Allow a leading parenthesis and square bracket.
-   ;; 
(?su)(?<\=[([])[\\]?(?P<name>http|https|ftp|file|irc):(?P<target>//[^\s<>]*[\w/])=
-   ;; # Allow <> brackets.
-   ;; 
(?su)[\\]?&lt;(?P<name>http|https|ftp|file|irc):(?P<target>//[^\s<>]*[\w/])&gt;=
-   ;; todo: overtake above regexes
-   ;; asciidoc.conf bug? why is it so restrictive for urls without attribute
-   ;; list, that version can only have a limited set of characters before. Why
-   ;; not just have the rule that it must start with \b.
-   (list "\\b\\(\\(?:https?\\|ftp\\|file\\|irc\\|mailto\\|callto\\|link\\)[^ 
\t\n]*?\\)\\(\\[\\)\\(.*?\\)\\(,.*?\\)?\\(\\]\\)"
-         '(1 adoc-delimiter) '(2 adoc-hide-delimiter) '(3 adoc-reference) '(4 
adoc-delimiter nil t) '(5 adoc-hide-delimiter))
-   (cons "\\b\\(?:https?\\|ftp\\|file\\|irc\\)://[^ \t<>\n]*[a-zA-Z0-9_//]" 
'adoc-reference)
-
-   ;; standalone email, SIMPLE reglex! copied from 
http://www.regular-expressions.info/email.html
-   ;; asciidoc.conf: 
(?su)(?<![">:\w._/-])[\\]?(?P<target>\w[\w._-]*@[\w._-]*\w)(?!["<\w_-])=mailto
-   ;; todo: use asciidoc's regex
-   (cons "\\(\\w\\|[.%+-]\\)+@\\(\\w\\|[.-]\\)+\\.[a-zA-Z]\\{2,4\\}" 
'adoc-reference) 
+   ;; URLs & Email addresses
+   (adoc-kw-standalone-urls)
 
    (list "\\(\\bfootnote:\\)\\(\\[\\)\\(.*?\\(?:\n.*?\\)?\\)\\(\\]\\)"
          '(1 adoc-delimiter)            ; name



reply via email to

[Prev in Thread] Current Thread [Next in Thread]