Added support for markdown tables
This commit is contained in:
parent
0e2d7e7aeb
commit
5770c60bcf
|
@ -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
|
||||
- [x] Language directive
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<rss version="2.0"><channel><title>RSS Test</title><link>http://example.com</link><description>An example blog for testing RSS capability of md4tj.</description><language>en-US</language><pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate><managingEditor>editor@example.com</managingEditor><webMaster>webmaster@example.com</webMaster><docs>https://www.rssboard.org/rss-specification</docs><generator>md4tj-rss.el</generator><lastBuildDate>Tue, 05 Sep 2023 00:44:58 GMT</lastBuildDate><item><title>Blog Post 2</title><link>https://example.com/blog/blogpost2.html</link><guid>https://example.com/blog/blogpost2.html</guid><description>
|
||||
<rss version="2.0"><channel><title>RSS Test</title><link>http://example.com</link><description>An example blog for testing RSS capability of md4tj.</description><language>en-US</language><pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate><managingEditor>editor@example.com</managingEditor><webMaster>webmaster@example.com</webMaster><docs>https://www.rssboard.org/rss-specification</docs><generator>md4tj-rss.el</generator><lastBuildDate>Sat, 30 Mar 2024 19:58:58 GMT</lastBuildDate><item><title>Blog Post 2</title><link>https://example.com/blog/blogpost2.html</link><guid>https://example.com/blog/blogpost2.html</guid><description>
|
||||
|
||||
<br>
|
||||
|
||||
|
|
18
md4tj.el
18
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
|
||||
"`\\(.*\\)`"
|
||||
"<code>\\1</code>" 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 "<th>" "<td>"))
|
||||
(closetag (if header "</th>" "</td>")))
|
||||
(if (string-match "^|---.*" line) "" ;; do nothing if the line under the header for the table
|
||||
(concat "<tr>\n" (mapconcat (lambda (x) (concat opentag (md4tj-process-line x) closetag "\n")) (split-string line "|" t " *")) "</tr>"))))
|
||||
|
||||
(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) "<hr>") ;; horizontal line
|
||||
((= (length cleanline) 0) "<br>") ;; 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) "</ul>\n")
|
||||
((eq state 'endol) "</ol>\n")
|
||||
((eq state 'endcode) "</code>\n</pre>\n")
|
||||
((eq state 'begintable) "<table>") ;; might need to add to this?
|
||||
((eq state 'endtable) "</table>")
|
||||
(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)) "</ul>")
|
||||
((or (eq state 'beginol) (eq state 'ol)) "</ol>")
|
||||
((or (eq state 'begincode) (eq state 'code)) "</code>")
|
||||
((or (eq state 'begintable) (eq state 'table)) "</table>")
|
||||
(t ""))
|
||||
"</body>\n"
|
||||
"</html>"))
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<h3>Hello world!</h3>
|
||||
|
||||
<h4>Hello <strong><em>world</em></strong>!</h4>
|
||||
<h4>Hello <strong><em>world</strong></em>!</h4>
|
||||
|
||||
<h1>This was included from a separate file!</h1>
|
||||
|
||||
|
@ -75,7 +75,7 @@ int main() {
|
|||
|
||||
<p>This is a div that has monospace text.</p>
|
||||
</div>
|
||||
<p id="lastupdated">Last updated: Tue 05 Sep 2023 04:44 UTC</p>
|
||||
<p id="lastupdated">Last updated: Sat 30 Mar 2024 23:58 UTC</p>
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -92,5 +92,25 @@ int main() {
|
|||
<p><a href="https://en.wikipedia.org/wiki/Talk:Joy,_Departed">Joy, Departed</a></p>
|
||||
|
||||
<p><a href="https://support.logi.com/hc/en-us/articles/360023467053-G13-Technical-Specifications">Logitech G13</a></p>
|
||||
|
||||
<br>
|
||||
|
||||
<table><tr>
|
||||
<th>Header 1</th>
|
||||
<th>Header 2</th>
|
||||
<th>Header 3</th>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
<td><em>Item 1</em></td>
|
||||
<td><strong>Item 2</strong></td>
|
||||
<td><s>Item 3</s></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
|
||||
<p>Content after the table</p>
|
||||
</body>
|
||||
</html>
|
|
@ -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)
|
||||
[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
|
Loading…
Reference in New Issue