diff --git a/README.md b/README.md index d4fc23f..340f45e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ A language and parser written in Emacs Lisp for my custom extension of Markdown, - [x] Image ### Extended Syntax -- [ ] Table +- [x] Table - [x] Fenced Code Block - [ ] Footnote (Will not implement) - [ ] Heading ID (Will not implement) @@ -40,4 +40,4 @@ A language and parser written in Emacs Lisp for my custom extension of Markdown, - [x] Meta directive - [x] Page title directive - [x] CSS inclusion directive -- [x] Language directive \ No newline at end of file +- [x] Language directive diff --git a/blog/feed.xml b/blog/feed.xml index b9d8af9..1e56418 100644 --- a/blog/feed.xml +++ b/blog/feed.xml @@ -1,4 +1,4 @@ -RSS Testhttp://example.comAn example blog for testing RSS capability of md4tj.en-USTue, 10 Jun 2003 04:00:00 GMTeditor@example.comwebmaster@example.comhttps://www.rssboard.org/rss-specificationmd4tj-rss.elTue, 05 Sep 2023 00:44:58 GMTBlog Post 2https://example.com/blog/blogpost2.htmlhttps://example.com/blog/blogpost2.html +RSS Testhttp://example.comAn example blog for testing RSS capability of md4tj.en-USTue, 10 Jun 2003 04:00:00 GMTeditor@example.comwebmaster@example.comhttps://www.rssboard.org/rss-specificationmd4tj-rss.elSat, 30 Mar 2024 19:58:58 GMTBlog Post 2https://example.com/blog/blogpost2.htmlhttps://example.com/blog/blogpost2.html <br> diff --git a/md4tj.el b/md4tj.el index ba3033d..ab2ce91 100644 --- a/md4tj.el +++ b/md4tj.el @@ -8,7 +8,8 @@ (require 'subr-x) ;; Change this line to wherever dash.el is on the building system ;; Can't use (require) because load-path is set in .emacs -(load-file "~/.emacs.d/elpa/dash-20230415.2324/dash.el") +;;(load-file "~/.emacs.d/elpa/dash-20230415.2324/dash.el") +(load-file "~/.emacs.d/elpa/dash-20240103.1301/dash.el") ;; Basic utilities for subsequent stuff (defun md4tj-util-getline () @@ -93,6 +94,13 @@ (replace-regexp-in-string "`\\(.*\\)`" "\\1" line))))))))) + +(defun md4tj-handle-table-row (line header) + "Return the string for a table row that is a HEADER from LINE." + (let ((opentag (if header "" "")) + (closetag (if header "" ""))) + (if (string-match "^|---.*" line) "" ;; do nothing if the line under the header for the table + (concat "\n" (mapconcat (lambda (x) (concat opentag (md4tj-process-line x) closetag "\n")) (split-string line "|" t " *")) "")))) (defun md4tj-convert-line-to-html (line state inbuf outfile) "Process LINE with STATE and return html, INBUF provided with OUTFILE." @@ -133,6 +141,8 @@ ((string-match "^#+ " cleanline) (md4tj-process-header (md4tj-process-line cleanline))) ((string= "---" cleanline) "
") ;; horizontal line ((= (length cleanline) 0) "
") ;; blank line + ((eq (nth 1 state) 'begintable) (md4tj-handle-table-row cleanline t)) + ((eq (nth 1 state) 'table) (md4tj-handle-table-row cleanline nil)) (t (md4tj-process-paragraph (md4tj-process-line cleanline)))) ;; End of multiline block @@ -152,6 +162,8 @@ ((eq state 'endul) "\n") ((eq state 'endol) "\n") ((eq state 'endcode) "\n\n") + ((eq state 'begintable) "") ;; might need to add to this? + ((eq state 'endtable) "
") (t ""))) (defun md4tj-next-state (currline prevstate) @@ -163,6 +175,7 @@ ((and (not (string-match "^- " currline)) (or (eq prevstate 'beginul) (eq prevstate 'ul))) 'endul) ((and (not (string-match "[0-9]+\\. " currline)) (or (eq prevstate 'beginol) (eq prevstate 'ol))) 'endul) ((and (string-match "```$" currline) (or (eq prevstate 'code) (eq prevstate 'begincode))) 'endcode) + ((and (not (string-match "^|.*|$" currline)) (or (eq prevstate 'begintable) (eq prevstate 'headtable) (eq prevstate 'table))) 'endtable) (t 'nothing)) ;; Begin state (or next line's prevstate) @@ -172,6 +185,8 @@ ((and (string-match "^[0-9]+\\. " currline) (or (eq prevstate 'beginol) (eq prevstate 'ol)) 'ol)) ((and (string-match "^```" currline) (not (or (eq prevstate 'begincode) (eq prevstate 'code))) 'begincode)) ((and (not (string-match "```$" currline)) (or (eq prevstate 'begincode) (eq prevstate 'code)) 'code)) + ((and (string-match "^|.*|$" currline) (not (or (eq prevstate 'table) (eq prevstate 'begintable)))) 'begintable) + ((and (string-match "^|.*|$" currline) (or (eq prevstate 'begintable) (eq prevstate 'table))) 'table) (t 'normal)))) (defun md4tj-begin () @@ -189,6 +204,7 @@ (cond ((or (eq state 'beginul) (eq state 'ul)) "") ((or (eq state 'beginol) (eq state 'ol)) "") ((or (eq state 'begincode) (eq state 'code)) "") + ((or (eq state 'begintable) (eq state 'table)) "") (t "")) "\n" "")) diff --git a/test_file.html b/test_file.html index 19b218c..0dd3ea5 100644 --- a/test_file.html +++ b/test_file.html @@ -18,7 +18,7 @@

Hello world!

-

Hello world!

+

Hello world!

This was included from a separate file!

@@ -75,7 +75,7 @@ int main() {

This is a div that has monospace text.

-

Last updated: Tue 05 Sep 2023 04:44 UTC

+

Last updated: Sat 30 Mar 2024 23:58 UTC


@@ -92,5 +92,25 @@ int main() {

Joy, Departed

Logitech G13

+ +
+ + + + + + + + + + + + + + +
Header 1Header 2Header 3
Item 1Item 2Item 3
+
+ +

Content after the table

\ No newline at end of file diff --git a/test_file.md4tj b/test_file.md4tj index cd7978f..5ed24ff 100644 --- a/test_file.md4tj +++ b/test_file.md4tj @@ -38,4 +38,10 @@ This is a div that has monospace text. [The Void](https://en.wikipedia.org/wiki/The_Void_(video_game)) [The Operative: No One Lives Forever](https://en.wikipedia.org/wiki/The_Operative:_No_One_Lives_Forever) [Joy, Departed](https://en.wikipedia.org/wiki/Talk:Joy,_Departed) -[Logitech G13](https://support.logi.com/hc/en-us/articles/360023467053-G13-Technical-Specifications) \ No newline at end of file +[Logitech G13](https://support.logi.com/hc/en-us/articles/360023467053-G13-Technical-Specifications) + +| Header 1 | Header 2 | Header 3| +|----------|----------|---------| +| *Item 1* | **Item 2** | ~~Item 3~~ | + +Content after the table \ No newline at end of file