aboutsummaryrefslogtreecommitdiffstats
path: root/zencoding-mode.el
diff options
context:
space:
mode:
authorRon Panduwana <panduwana@gmail.com>2011-02-09 23:56:59 +0700
committerRon Panduwana <panduwana@gmail.com>2011-02-09 23:56:59 +0700
commitd6783b24529833edb02e2d3d68b9b01123841ffc (patch)
tree4daf99e6cdc8268377b8a7c83324f0964c4dc368 /zencoding-mode.el
parent500675ec730dc6dc911cf1c716002ff888ab0eb9 (diff)
downloademmet-mode-d6783b24529833edb02e2d3d68b9b01123841ffc.tar.lz
emmet-mode-d6783b24529833edb02e2d3d68b9b01123841ffc.tar.xz
emmet-mode-d6783b24529833edb02e2d3d68b9b01123841ffc.zip
Added tag expansion for table, ul, ol, and dl
Diffstat (limited to 'zencoding-mode.el')
-rw-r--r--zencoding-mode.el43
1 files changed, 35 insertions, 8 deletions
diff --git a/zencoding-mode.el b/zencoding-mode.el
index acc1fa9..175940d 100644
--- a/zencoding-mode.el
+++ b/zencoding-mode.el
@@ -137,11 +137,6 @@
(defun zencoding-tag (input)
"Parse a tag."
- (let ((first-char (substring input 0 1)))
- (if (or (string= "#" first-char)
- (string= "." first-char))
- (setq input (concat "div" input))
- nil))
(zencoding-run zencoding-tagname
(let ((tagname (cadr expr))
(has-body? (cddr expr)))
@@ -153,7 +148,14 @@
(zencoding-pif (zencoding-tag-props expr input)
it
expr-and-input))))
- '(error "expected tagname")))
+ (zencoding-default-tag input)))
+
+(defun zencoding-default-tag (input)
+ "Parse a #id or .class"
+ (zencoding-parse "\\([#|\\.]\\)" 1 "tagname"
+ (zencoding-tag (concat "div" (elt it 0)))))
+
+;'(error "expected tagname")
(defun zencoding-tag-props (tag input)
(zencoding-run zencoding-props
@@ -272,9 +274,28 @@
(zencoding-run zencoding-expr
(let ((child expr))
`((zencoding-siblings ,parent ,child) . ,input))
- '(error "expected second sibling"))))
+ (zencoding-expand parent input))))
'(error "expected first sibling")))
+(defvar zencoding-expandable-tags
+ '("dl" ">(dt+dd)"
+ "ol" ">li"
+ "ul" ">li"
+ "table" ">tr>td"))
+
+(defun zencoding-expand (parent input)
+ "Parse an e+ expression, where e is an expandable tag"
+ (let ((parent-tag (car (elt parent 1))))
+ (let ((expandable (member parent-tag zencoding-expandable-tags)))
+ (if expandable
+ (let ((expansion (zencoding-child parent (concat (cadr expandable)))))
+ (zencoding-pif (zencoding-parse "+\\(.*\\)" 1 "+expr"
+ (zencoding-expr (elt it 1)))
+ `((zencoding-siblings ,(car expansion) ,(car it)))
+ expansion)
+ )
+ '(error "expected second sibling")))))
+
(defun zencoding-name (input)
"Parse a class or identifier name, e.g. news, footer, mainimage"
(zencoding-parse "\\([a-zA-Z][a-zA-Z0-9-_:]*\\)" 2 "class or identifer name"
@@ -407,6 +428,12 @@
("a#q.x+b" "<a id=\"q\" class=\"x\"></a><b></b>")
("a#q.x.y.z+b" "<a id=\"q\" class=\"x y z\"></a><b></b>")
("a#q.x.y.z+b#p.l.m.n" "<a id=\"q\" class=\"x y z\"></a><b id=\"p\" class=\"l m n\"></b>")
+ ;; Tag expansion
+ ("table+" "\n<table>\n<tr>\n<td>\n</td>\n</tr>\n</table>")
+ ("dl+" "\n<dl>\n<dt>\n</dt>\n<dd>\n</dd>\n</dl>")
+ ("ul+" "\n<ul>\n<li>\n</li>\n</ul>")
+ ("ul++ol+" "\n<ul>\n<li>\n</li>\n</ul>\n<ol>\n<li>\n</li>\n</ol>")
+ ("ul#q.x.y m=l+" "\n<ul id=\"q\" class=\"x y\" m=\"l\">\n<li>\n</li>\n</ul>")
;; Parent > child
("a>b" "<a><b></b></a>")
("a>b>c" "<a><b><c></c></b></a>")
@@ -414,7 +441,7 @@
("a#q.x>b" "<a id=\"q\" class=\"x\"><b></b></a>")
("a#q.x.y.z>b" "<a id=\"q\" class=\"x y z\"><b></b></a>")
("a#q.x.y.z>b#p.l.m.n" "<a id=\"q\" class=\"x y z\"><b id=\"p\" class=\"l m n\"></b></a>")
- ("#q>.x" "\n<div id=\"q\">\n<div class=\"x\">\n</div>\n</div>")
+ ("#q>.x" "\n<div id=\"q\">\n<div class=\"x\">\n</div>\n</div>")
("a>b+c" "<a><b></b><c></c></a>")
("a>b+c>d" "<a><b></b><c><d></d></c></a>")
;; Multiplication