Added support for including files
This commit is contained in:
parent
cc620c9700
commit
eacd91ea6f
|
@ -73,32 +73,37 @@
|
||||||
(defun md4tj-convert-line-to-html (line state)
|
(defun md4tj-convert-line-to-html (line state)
|
||||||
"Process LINE with STATE and return html."
|
"Process LINE with STATE and return html."
|
||||||
(let ((cleanline (md4tj-clean-multiline line)))
|
(let ((cleanline (md4tj-clean-multiline line)))
|
||||||
(if (string-match "^@@" line) "" ;; Don't process if @@ statement
|
;; If this is a signal to include another file
|
||||||
(concat
|
(cond ((string-match "^@@INCLUDE" line) (md4tj-parse-to-string (nth 1 (split-string line))))
|
||||||
;; Beginning of multiline block
|
;; If this is some other signal, ignore
|
||||||
(cond ((eq state 'beginul) "<ul>\n<li>")
|
((string-match "^@@" line) "")
|
||||||
((eq state 'beginol) "<ol>\n<li>")
|
;; Otherwise, process as normal
|
||||||
((eq state 'begincode) "<pre>\n<code>")
|
(t
|
||||||
((eq state 'ul) "<li>")
|
(concat
|
||||||
((eq state 'ol) "<li>")
|
;; Beginning of multiline block
|
||||||
((eq state 'code) "")
|
(cond ((eq state 'beginul) "<ul>\n<li>")
|
||||||
((eq state 'endul) "</ul>\n")
|
((eq state 'beginol) "<ol>\n<li>")
|
||||||
((eq state 'endol) "</ol>\n")
|
((eq state 'begincode) "<pre>\n<code>")
|
||||||
((eq state 'endcode) "</code>\n</pre>\n")
|
((eq state 'ul) "<li>")
|
||||||
(t ""))
|
((eq state 'ol) "<li>")
|
||||||
|
((eq state 'code) "")
|
||||||
;; Body
|
((eq state 'endul) "</ul>\n")
|
||||||
(cond ((or (eq state 'code) (eq state 'begincode)) (md4tj-clean-code-for-html cleanline))
|
((eq state 'endol) "</ol>\n")
|
||||||
((string-match "^#+ " cleanline) (md4tj-process-header (md4tj-process-line cleanline)))
|
((eq state 'endcode) "</code>\n</pre>\n")
|
||||||
((string= "---" cleanline) "<hr>") ;; horizontal line
|
(t ""))
|
||||||
((= (length cleanline) 0) "<br/>") ;; blank line
|
|
||||||
(t (md4tj-process-paragraph (md4tj-process-line cleanline))))
|
;; Body
|
||||||
|
(cond ((or (eq state 'code) (eq state 'begincode)) (md4tj-clean-code-for-html cleanline))
|
||||||
;; End of multiline block
|
((string-match "^#+ " cleanline) (md4tj-process-header (md4tj-process-line cleanline)))
|
||||||
(cond ((or (eq state 'ul) (eq state 'beginul)) "</li>")
|
((string= "---" cleanline) "<hr>") ;; horizontal line
|
||||||
((or (eq state 'ol) (eq state 'beginol)) "</li>")
|
((= (length cleanline) 0) "<br/>") ;; blank line
|
||||||
((eq state 'code) "")
|
(t (md4tj-process-paragraph (md4tj-process-line cleanline))))
|
||||||
(t ""))))))
|
|
||||||
|
;; End of multiline block
|
||||||
|
(cond ((or (eq state 'ul) (eq state 'beginul)) "</li>")
|
||||||
|
((or (eq state 'ol) (eq state 'beginol)) "</li>")
|
||||||
|
((eq state 'code) "")
|
||||||
|
(t "")))))))
|
||||||
|
|
||||||
(defun md4tj-next-state (currline prevstate)
|
(defun md4tj-next-state (currline prevstate)
|
||||||
"Return the state based on CURRLINE and PREVSTATE."
|
"Return the state based on CURRLINE and PREVSTATE."
|
||||||
|
@ -183,5 +188,19 @@
|
||||||
;; Write outbuf to outfile
|
;; Write outbuf to outfile
|
||||||
(write-region nil nil outfile nil)))
|
(write-region nil nil outfile nil)))
|
||||||
|
|
||||||
|
(defun md4tj-parse-to-string (mdfile)
|
||||||
|
"Parse MDFILE, return conversion to HTML as string."
|
||||||
|
(with-temp-buffer
|
||||||
|
(let ((acc nil)
|
||||||
|
(line nil)
|
||||||
|
(state 'normal))
|
||||||
|
(insert-file-contents mdfile)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (< (point) (point-max))
|
||||||
|
(setq line (getline))
|
||||||
|
(setq state (md4tj-next-state line state))
|
||||||
|
(setq acc (concat acc (md4tj-convert-line-to-html line state) "\n"))
|
||||||
|
(forward-line))
|
||||||
|
acc)))
|
||||||
(provide 'md4tj_parse)
|
(provide 'md4tj_parse)
|
||||||
;;; md4tj_parse.el ends here
|
;;; md4tj_parse.el ends here
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en-us">
|
<html lang="en-us">
|
||||||
<head>
|
<head>
|
||||||
|
|
||||||
<title>Test webpage</title>
|
<title>Test webpage</title>
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
@ -13,6 +14,9 @@
|
||||||
<h2>Hello world!</h2>
|
<h2>Hello world!</h2>
|
||||||
<h3>Hello world!</h3>
|
<h3>Hello world!</h3>
|
||||||
<h4>Hello <strong><em>world</em></strong>!</h4>
|
<h4>Hello <strong><em>world</em></strong>!</h4>
|
||||||
|
<br/>
|
||||||
|
<h1>This was included from a separate file!</h1>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<p><a href="https://example.com">Example website</a></p>
|
<p><a href="https://example.com">Example website</a></p>
|
||||||
<p><img src="usbs.png" alt="Example image"></p>
|
<p><img src="usbs.png" alt="Example image"></p>
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
### Hello world!
|
### Hello world!
|
||||||
#### Hello ***world***!
|
#### Hello ***world***!
|
||||||
|
|
||||||
|
@@INCLUDE test_file_include.md4tj
|
||||||
|
|
||||||
[Example website](https://example.com)
|
[Example website](https://example.com)
|
||||||
![Example image](usbs.png)
|
![Example image](usbs.png)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
# This was included from a separate file!
|
Loading…
Reference in New Issue