[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)[\\]?<(?P<name>http|https|ftp|file|irc):(?P<target>//[^\s<>]*[\w/])>=
+;;
+;; 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)[\\]?<(?P<name>http|https|ftp|file|irc):(?P<target>//[^\s<>]*[\w/])>=
- ;; 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
- [nongnu] elpa/adoc-mode 411eb48ce9 120/199: Sensorflo/pr35 (#3), (continued)
- [nongnu] elpa/adoc-mode 411eb48ce9 120/199: Sensorflo/pr35 (#3), ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 69569ee920 105/199: improved fontifying for footnoteref, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 6dc82593f0 162/199: Document the mode's history, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 4415af4a53 036/199: fixed typo in identifier, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode fdc42c818a 044/199: removed TAGS file, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 47fc7143a3 048/199: test, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 30176c0f3c 054/199: added skelleton for generig promote / denote, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 303019657d 060/199: many things with xref and anchor, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 6cb42436d2 067/199: test: running the test is now more smoothly, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 838684c227 068/199: comment improvements, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 950223b614 070/199: reworked highlighting of urls,
ELPA Syncer <=
- [nongnu] elpa/adoc-mode d80b29ebc9 072/199: test: bugfix: point was wronly positioned in adoctest-trans, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 63abada690 074/199: test: adoctest-trans learned setting mark using <>, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 0a35871ac3 083/199: edited (doc-)comments to make it fit package format guidelines, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 2bbd6a36ac 088/199: bumped version to 0.6.2, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode b6d54d9007 097/199: bumped version to 0.6.4, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode b508984663 106/199: id attribute of footnoteref now uses markup-internal-reference-face if it's used as reference opposed to anchor, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode ab42f4909a 107/199: (un)constrained quotes can now spawn more than two lines, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 61974788b4 109/199: small reformatting, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 2bcfcea743 112/199: improved comments, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 9916b51199 113/199: small refactoring in field of the adoc-attribute-list text property, ELPA Syncer, 2023/09/03