Can fully parse md4tj file and output an html file
This commit is contained in:
parent
054f37b226
commit
a1adf3e2fb
|
@ -1,4 +1,4 @@
|
|||
f;;; md4tj_parse --- Summary
|
||||
;;; md4tj_parse --- Summary
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
|
@ -60,18 +60,34 @@ f;;; md4tj_parse --- Summary
|
|||
;; multiple lines in the case of a block (NI)
|
||||
(defun md4tj-process-block (codeblock)
|
||||
"Process CODEBLOCK and return html."
|
||||
(cond ((string-match "^# " codeblock) (md4tj-process-header codeblock))
|
||||
(t (md4tj-process-paragraph codeblock))))
|
||||
|
||||
(cond ((string-match "^#+ " codeblock) (md4tj-process-header (md4tj-process-line codeblock)))
|
||||
((string= "---" codeblock) "<hr>")
|
||||
(t (md4tj-process-paragraph (md4tj-process-line codeblock)))))
|
||||
|
||||
(defun md4tj-next-block ()
|
||||
"Retrieve the next block in the open file."
|
||||
(let ((currline (getline)))
|
||||
(cond ((string-match "^- " currline) nil) ;; TODO ul's
|
||||
((string-match "^[0-9]+\\. " currline) nil) ;; TODO ol's
|
||||
(t currline))))
|
||||
|
||||
(defun md4tj-parse (mdfile outfile)
|
||||
"Entry point to parse MDFILE and output to OUTFILE."
|
||||
(with-temp-buffer
|
||||
(let ((inbuf (generate-new-buffer " in"))
|
||||
(outbuf (generate-new-buffer " out")))
|
||||
(set-buffer inbuf)
|
||||
(insert-file-contents mdfile)
|
||||
(goto-char (point-min))
|
||||
(while (< (point) (point-max))
|
||||
(md4tj-process-block (getline))
|
||||
(forward-line))))
|
||||
(set-buffer outbuf)
|
||||
(while (with-current-buffer inbuf (< (point) (point-max)))
|
||||
;; Insert next line(s) into output file
|
||||
(insert (concat (md4tj-process-block (with-current-buffer
|
||||
inbuf
|
||||
(md4tj-next-block)))
|
||||
"\n"))
|
||||
;; Advance input file by a line
|
||||
(with-current-buffer inbuf (forward-line)))
|
||||
(write-region nil nil outfile nil)))
|
||||
|
||||
(provide 'md4tj_parse)
|
||||
;;; md4tj_parse.el ends here
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# Hello world!
|
||||
# Hello `world`!
|
||||
## Hello world!
|
||||
### Hello world!
|
||||
#### Hello world!
|
||||
#### Hello ***world***!
|
||||
|
||||
[Example website](https://example.com)
|
||||
[Example image](image.jpg)
|
Loading…
Reference in New Issue