Skip to content

Commit 5fcf166

Browse files
committed
Merge branch 'main' of github.com:lem-project/lem
2 parents 7c958c2 + 17f1751 commit 5fcf166

File tree

5 files changed

+175
-51
lines changed

5 files changed

+175
-51
lines changed

extensions/asciidoc-mode/asciidoc-mode.lisp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ link : https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/
6464
:mode-hook *asciidoc-mode-hook*)
6565
(setf (variable-value 'enable-syntax-highlight) t))
6666

67-
(define-file-type ("adoc") 'asciidoc-mode)
67+
(define-file-type ("adoc") asciidoc-mode)

extensions/markdown-mode/example.md

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
# Hello
22

3+
## Test
4+
5+
### Subheader
6+
7+
#### Deeper header
8+
9+
##### Even deeper
10+
11+
###### Deepest header
12+
13+
This is a paragraph with **bold text**, *italic text*, and __underlined text__.
14+
15+
Here is some `inline code` and a [link](https://example.com).
16+
17+
> This is a blockquote.
18+
> More blockquote text.
19+
> > Nested blockquote text.
20+
21+
Lists:
22+
23+
- foo
24+
- bar
25+
- baz
26+
27+
* hoge
28+
* piyo
29+
30+
+ hoge
31+
+ piyo
32+
33+
1. one
34+
2. two
35+
3. three
36+
37+
Task list example:
38+
39+
- [ ] Incomplete task
40+
- [x] Completed task
41+
- [ ] Another task to do
42+
43+
Table:
44+
45+
| Header 1 | Header 2 | Header 3 |
46+
|----------|----------|----------|
47+
| Row 1, Col 1 | Row 1, Col 2 | Row 1, Col 3 |
48+
| Row 2, Col 1 | Row 2, Col 2 | Row 2, Col 3 |
49+
50+
Code:
51+
352
```lisp
453
(defpackage :foo
554
(:use :cl))
@@ -17,20 +66,22 @@ int main(void) {
1766
}
1867
```
1968
20-
## Test
69+
```python
70+
def greet(name):
71+
print(f"Hello, {name}!")
2172
22-
this is test
73+
greet("World")
74+
```
2375

24-
- foo
25-
- bar
26-
- baz
76+
Inline formatting combinations:
77+
- **Bold and *italic* text**
78+
- *Italic and `inline code`*
79+
- [A link with **bold** text](https://example.com)
2780

28-
* hoge
29-
* piyo
81+
---
3082

31-
+ hoge
32-
+ piyo
83+
Metadata:
3384

34-
1. one
35-
2. two
36-
3. three
85+
Title: Expanded Comprehensive Markdown Test File
86+
Author: AI Assistant
87+
Date: 2024-08-05

extensions/markdown-mode/syntax-parser.lisp

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,89 @@
5151
:syntax-table syntax-table
5252
:recursive-check nil))
5353
(t
54-
(put-text-property start point :attribute 'syntax-string-attribute))))))
54+
(put-text-property start point :attribute 'document-code-block-attribute))))))
5555

5656
(defun scan-region (start end)
5757
(clear-region-major-mode start end)
5858
(with-point ((point start))
5959
(loop :while (point< point end)
60-
:do (cond ((looking-at point "^#")
61-
(put-line-attribute point 'syntax-constant-attribute))
62-
((looking-at point "^>")
63-
(put-line-attribute point 'syntax-string-attribute))
64-
((looking-at point "^\\s*[-*+]")
65-
(back-to-indentation point)
66-
(with-point ((start point)
67-
(end point))
68-
(character-offset end 1)
69-
(put-text-property start end :attribute 'syntax-keyword-attribute)))
70-
((looking-at point "^\\s*(?:\\d)+\\.\\s")
71-
(back-to-indentation point)
72-
(with-point ((start point)
73-
(end point))
74-
(skip-chars-forward end #'digit-char-p)
75-
(character-offset end 1)
76-
(put-text-property start end :attribute 'syntax-keyword-attribute)))
77-
((start-code-block-line-p point)
78-
(scan-code-block point end)))
79-
:while (line-offset point 1))))
60+
:do (let ((line (line-string point)))
61+
(cond
62+
((str:starts-with-p "#" line)
63+
(let ((level (position #\Space line)))
64+
(when level
65+
(put-line-attribute point (case level
66+
(1 'document-header1-attribute)
67+
(2 'document-header2-attribute)
68+
(3 'document-header3-attribute)
69+
(4 'document-header4-attribute)
70+
(5 'document-header5-attribute)
71+
(6 'document-header6-attribute))))))
72+
((str:starts-with-p ">" line)
73+
(put-line-attribute point 'document-blockquote-attribute))
74+
;; Unordered list items
75+
((ppcre:scan "^\\s*[-*+]\\s" line)
76+
(ppcre:do-matches (start end "^(\\s*[-*+])\\s" line)
77+
(put-text-property
78+
(character-offset (copy-point point) start)
79+
(character-offset (copy-point point) end)
80+
:attribute 'document-list-attribute)))
81+
;; Ordered list items
82+
((ppcre:scan "^\\s*\\d+\\.\\s" line)
83+
(ppcre:do-matches (start end "^(\\s*\\d+\\.)\\s" line)
84+
(put-text-property
85+
(character-offset (copy-point point) start)
86+
(character-offset (copy-point point) end)
87+
:attribute 'document-list-attribute)))
88+
((start-code-block-line-p point)
89+
(scan-code-block point end))
90+
((or (str:starts-with-p "- [ ]" line)
91+
(str:starts-with-p "- [x]" line)
92+
(str:starts-with-p "- [X]" line))
93+
(put-line-attribute point 'document-task-list-attribute))
94+
((str:starts-with-p "---" line)
95+
(put-line-attribute point 'document-metadata-attribute))
96+
((str:starts-with-p "|" line)
97+
(put-line-attribute point 'document-table-attribute)))
98+
99+
;; Inline matches
100+
;; Bold
101+
(ppcre:do-matches (start end "\\*\\*(.*?)\\*\\*" line)
102+
(put-text-property
103+
(character-offset (copy-point point) start)
104+
(character-offset (copy-point point) end)
105+
:attribute 'document-bold-attribute))
106+
;; Italic
107+
(ppcre:do-matches (start end "\\*(.*?)\\*" line)
108+
(let ((bold-start (character-offset (copy-point point) start))
109+
(bold-end (character-offset (copy-point point) end)))
110+
(unless (text-property-at bold-start :attribute)
111+
(put-text-property
112+
bold-start
113+
bold-end
114+
:attribute 'document-italic-attribute))))
115+
;; Underline
116+
(ppcre:do-matches (start end "__(.*?)__" line)
117+
(put-text-property
118+
(character-offset (copy-point point) start)
119+
(character-offset (copy-point point) end)
120+
:attribute 'document-underline-attribute))
121+
;; Code
122+
(ppcre:do-matches (start end "`([^`]+)`" line)
123+
(put-text-property
124+
(character-offset (copy-point point) start)
125+
(character-offset (copy-point point) end)
126+
:attribute 'document-inline-code-attribute))
127+
;; Links
128+
(ppcre:do-matches (start end "\\[([^\\]]+)\\]\\(([^)]+)\\)" line)
129+
(put-text-property
130+
(character-offset (copy-point point) start)
131+
(character-offset (copy-point point) end)
132+
:attribute 'document-link-attribute)))
133+
; Exit if we can't move forward
134+
:do (unless (line-offset point 1)
135+
(return)))))
136+
80137

81138
(defun search-backward-code-block-start (point)
82139
(with-point ((point point))

qlfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
("lem-base16-themes" .
1414
(:class qlot/source/git:source-git
1515
:initargs (:remote-url "https://github.com/lem-project/lem-base16-themes.git")
16-
:version "git-20ab66c6b9f24e3634fb2a1d4ced1d51cefd3622"))
16+
:version "git-e09618e2f3a4ba9977167d3ea90123ecabd884ab"))
1717
("async-process" .
1818
(:class qlot/source/git:source-git
1919
:initargs (:remote-url "https://github.com/lem-project/async-process.git")

src/common/color.lisp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -771,22 +771,38 @@
771771
144 238 144 LightGreen
772772
")
773773

774-
(let ((color-names
775-
(flet ((parse (text)
776-
(with-input-from-string (stream text)
777-
(loop :for line := (read-line stream nil)
778-
:while line
779-
:for elt := (ppcre:register-groups-bind (r g b name)
780-
("^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+([a-zA-Z0-9 ]+)" line)
781-
(cons (string-downcase name)
782-
(list (and r (parse-integer r))
783-
(and g (parse-integer g))
784-
(and b (parse-integer b)))))
785-
:if elt
786-
:collect elt))))
787-
(alexandria:alist-hash-table (parse *rgb.txt*) :test 'equal))))
788-
(defun get-rgb-from-color-name (color-name)
789-
(gethash (string-downcase color-name) color-names)))
774+
;; Size includes aliases
775+
(defvar *color-names* (make-hash-table :size 848 :test 'equal))
776+
777+
(defun parse-rgb-txt ()
778+
(alexandria:alist-hash-table
779+
(with-input-from-string (stream *rgb.txt*)
780+
(loop :for line := (read-line stream nil)
781+
:while line
782+
:for elt := (ppcre:register-groups-bind (r g b name)
783+
("^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+([a-zA-Z0-9 ]+)" line)
784+
(cons (string-downcase name)
785+
(list (and r (parse-integer r))
786+
(and g (parse-integer g))
787+
(and b (parse-integer b)))))
788+
:if elt
789+
:collect elt))
790+
:test 'equal))
791+
792+
;; Lisp-style color names with a dash instead of space
793+
(defun add-lisp-color-alias (name value)
794+
(when (> (length (ppcre:split "\\s+" name)) 1)
795+
(let ((new-name (ppcre:regex-replace-all "\\s+" name "-")))
796+
(setf (gethash new-name *color-names*) value))))
797+
798+
(defun add-lisp-color-aliases ()
799+
(maphash #'add-lisp-color-alias *color-names*))
800+
801+
(defun get-rgb-from-color-name (color-name)
802+
(when (equal (hash-table-count *color-names*) 0)
803+
(setf *color-names* (parse-rgb-txt))
804+
(add-lisp-color-aliases))
805+
(gethash (string-downcase color-name) *color-names*))
790806

791807
(defstruct (color (:constructor make-color (red green blue))) red green blue)
792808

0 commit comments

Comments
 (0)