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

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

[nongnu] elpa/adoc-mode 105519ce37 033/199: changed image fontification


From: ELPA Syncer
Subject: [nongnu] elpa/adoc-mode 105519ce37 033/199: changed image fontification without tests, added tests for attribute lists
Date: Sun, 3 Sep 2023 06:59:25 -0400 (EDT)

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

    changed image fontification without tests, added tests for attribute lists
---
 adoc-mode-test.el | 40 +++++++++++++++++++++++++++-------------
 adoc-mode.el      | 55 ++++++++++++++++++++++++++++++++-----------------------
 2 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/adoc-mode-test.el b/adoc-mode-test.el
index 3e3fe96808..b3f045881a 100644
--- a/adoc-mode-test.el
+++ b/adoc-mode-test.el
@@ -135,18 +135,32 @@
     ;; tested in delimited-blocks-simple
     ))
 
-(ert-deftest adoctest-test- ()
-  (adoctest-faces "comments"
-    ;; as block macro 
-    "// lorem ipsum\n" markup-comment-face
-    "\n" nil
-    ;; as inline macro
-    "lorem ipsum\n" 'no-face
-    "// dolor sit\n" markup-comment-face
-    "amen\n" 'no-face
-    "\n" nil
-    ;; as delimited block
-    ;; tested in delimited-blocks-simple
+(ert-deftest adoctest-test-attribute-list ()
+  (adoctest-faces "attribute-list"
+    ;; positional attribute 
+    "[" markup-meta-face "hello" markup-value-face "]" markup-meta-face "\n" 
nil                 
+    ;; positional attribute containing spaces
+    "[" markup-meta-face "hello world" markup-value-face "]" markup-meta-face 
"\n" nil                   
+    ;; positional attribute as string
+    "[\"" markup-meta-face  "hello world" markup-value-face "\"]" 
markup-meta-face "\n" nil              
+
+    ;; multiple positional attributes
+    "[" markup-meta-face "hello" markup-value-face "," markup-meta-face 
"world" markup-value-face "]" markup-meta-face "\n" nil                  
+
+    ;; keyword attribute
+    "[" markup-meta-face "salute" markup-attribute-face "=" markup-meta-face 
"hello" markup-value-face "]" markup-meta-face "\n" nil             
+    ;; keyword attribute where value is a string
+    "[" markup-meta-face "salute" markup-attribute-face "=\"" markup-meta-face 
"hello world" markup-value-face "\"]" markup-meta-face "\n" nil                 
  
+
+    ;; multiple positional attributes, multiple keyword attributes
+    "[" markup-meta-face "lorem" markup-value-face "," markup-meta-face 
"ipsum" markup-value-face "," markup-meta-face
+        "dolor" markup-attribute-face "=" markup-meta-face "sit" 
markup-value-face "," markup-meta-face
+        "dolor" markup-attribute-face "=" markup-meta-face "sit" 
markup-value-face "]" markup-meta-face "\n" nil                 
+
+    ;; is , within strings really part of the string and not mistaken as 
element separator
+    "[\"" markup-meta-face "lorem,ipsum=dolor" markup-value-face "\"]" 
markup-meta-face "\n" nil                 
+    ;; does escaping " in strings work
+    "[\"" markup-meta-face "lorem \\\"ipsum\\\" dolor" markup-value-face "\"]" 
markup-meta-face "\n" nil                 
     ))
 
 (ert-deftest adoctest-test-quotes-simple ()
@@ -358,5 +372,5 @@
   (save-buffer "adoc-mode.el")
   (save-buffer "adoc-mode-test.el")
   (ert-run-tests-interactively "^adoctest-pre-test-byte-compile")
-  (ert-run-tests-interactively "^adoctest-test-"))
+  (ert-run-tests-interactively "^adoctest-test"))
 
diff --git a/adoc-mode.el b/adoc-mode.el
index e89fb5a0c8..42a8fe5887 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -617,7 +617,7 @@ Subgroups:
    "\\(?:"
      ;; regexp for string: See 'Mastering Regular Expressions', chapter 'The
      ;; Real "Unrolling-the-Loop" Pattern'.
-     "\"\\([^\"]*\\(?:\\.[^\"]*\\)*\\)\"[ \t\n]*" "\\|"        ; 2 
+     "\"\\([^\"\\]*\\(?:\\\\.[^\"\\]*\\)*\\)\"[ \t\n]*" "\\|"  ; 2 
      "\\([^,]+\\)"                                     ; 3 
    "\\)"))
 
@@ -710,6 +710,19 @@ subgroups:
    (t
     (error "Invalid type"))))
 
+;; Macros using default syntax.
+;; 
(?<!\w)[\\]?(?P<name>http|https|ftp|file|irc|mailto|callto|image|link|anchor|xref|indexterm):(?P<target>\S*?)\[(?P<attrlist>.*?)\]
+;; Default (catchall) inline macro is not implemented
+;; #    [\\]?(?P<name>\w(\w|-)*?):(?P<target>\S*?)\[(?P<passtext>.*?)(?<!\\)\]
+(defun adoc-re-inline-macro (cmd-name)
+  "Returns regex matching an inline macro.
+Subgroups:
+1 cmd name
+2 target
+3 attribute list, exclusive brackets []"
+  ;; !!! \< is not exactly what AsciiDoc does, see regex above
+  (concat "\\<\\(" cmd-name "\\):\\([^ \t\n].*\\)[\\(.*?\\)]" ))
+
 ;; todo: use same regexps as for font lock
 (defun adoc-re-paragraph-separate ()
   (concat
@@ -988,6 +1001,19 @@ When LITERAL-P is non-nil, the contained text is literal 
text."
       '(3 nil)) ; grumbl, I dont know how to get rid of it
    `(4 '(face ,(or del-face markup-meta-hide-face) adoc-reserved t) t))); 
close del
 
+(defun adoc-kw-inline-image ()
+  (list
+   ;; matcher function
+   `(lambda (end) (adoc-kwf-std end ,(adoc-re-inline-macro "image") '(1 2) 
'(0)))
+   ;; highlighers
+   '(0 '(face markup-meta-face adoc-reserved t) t)
+   '(1 markup-complex-replacement-face t)
+   '(2 markup-internal-reference-face t)
+   '(3 '(face markup-delimiter-face
+            adoc-reserved nil      
+            adoc-attribute-list (((0 "alt") markup-secondary-text-face)
+                                 ("title" markup-secondary-text-face))))))
+
 ;; 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
@@ -1176,6 +1202,7 @@ When LITERAL-P is non-nil, the contained text is literal 
text."
          '(1 markup-complex-replacement-face t)          ; macro name
          '(2 markup-internal-reference-face t)   ; file name
          '(3 '(face markup-delimiter-face
+              adoc-reserved nil            
               adoc-attribute-list (((0 "alt") markup-secondary-text-face)
                                ("title" markup-secondary-text-face)))
              t))                         ; attribute list
@@ -1297,8 +1324,8 @@ When LITERAL-P is non-nil, the contained text is literal 
text."
    ;; --- general attribute list
    ;; ^\[(?P<attrlist>.*)\]$
    (list "^\\(\\[\\(.*\\)\\]\\)[ \t]*$"
-         '(1 '(face adoc-delimiter adoc-reserved block-del))
-        '(2 '(face markup-delimiter-face 'adoc-attribute-list t)))
+         '(1 '(face markup-meta-face adoc-reserved block-del))
+        '(2 '(face markup-delimiter-face adoc-attribute-list t)))
 
 
    ;; block title
@@ -1432,26 +1459,8 @@ When LITERAL-P is non-nil, the contained text is literal 
text."
    (list "\\b\\(xref:\\)\\([^ \t\n]*?\\)\\(\\[\\)\\(.*?\\)\\(,.*?\\)?\\(\\]\\)"
          '(1 adoc-hide-delimiter) '(2 adoc-delimiter) '(3 adoc-hide-delimiter) 
'(4 adoc-reference) '(5 adoc-delimiter nil t) '(6 adoc-hide-delimiter)) 
 
-   ;; todo: fontify alt and title attribute value
-   ;; todo: one regexp for both inline/block image macro
-   ;;          1           2       3               4     5           6         
    7              8          9
-   (list "\\b\\(image:\\)\\(:?\\)\\([^ 
\t\n]*?\\)\\(\\[\\(\"?\\)\\)\\([^=\n]*?\\)\\(\\5[ \t]*,\\)\\(.*?\\)?\\(\\]\\)"
-         '(1 adoc-hide-delimiter)       ; macro name
-         '(2 adoc-warning)              ; if there are two colons, we have a 
bogous block macro
-         '(3 adoc-complex-replacement)  ; file name
-         '(4 adoc-hide-delimiter)       ; ["
-         '(6 adoc-secondary-text)       ;    first positional argument is 
caption
-         '(7 adoc-hide-delimiter)       ;    ",
-         '(8 adoc-delimiter nil t)      ;    rest of attribute list
-         '(9 adoc-hide-delimiter))      ; ]
-   (list "\\b\\(image:\\)\\(:?\\)\\([^ \t\n]*?\\)\\(\\[\\)\\(.*?\\)\\(\\]\\)"
-         '(1 adoc-hide-delimiter)       ; macro name
-         '(2 adoc-warning)              ; if there are two colons, we have a 
bogous block macro
-         '(3 adoc-complex-replacement)  ; file name
-         '(4 adoc-hide-delimiter)       ; [
-         '(5 adoc-delimiter)            ;   attribute list content
-         '(6 adoc-hide-delimiter))      ; ]
-
+   (adoc-kw-inline-image)
+   
    (list "\\(anchor:\\)\\([^ \t\n]*?\\)\\(\\[\\)\\(.*?\\)\\(,.*?\\)?\\(\]\\)"
          '(1 adoc-hide-delimiter) '(2 adoc-anchor) '(3 adoc-hide-delimiter) 
'(4 adoc-secondary-text) '(5 adoc-delimiter nil t) '(6 adoc-hide-delimiter)) 
    ;; standalone email, SIMPLE reglex! copied from 
http://www.regular-expressions.info/email.html



reply via email to

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