Can fully parse md4tj file and output an html file

This commit is contained in:
j4nk 2022-12-28 16:43:54 -05:00
parent 054f37b226
commit a1adf3e2fb
2 changed files with 29 additions and 10 deletions

View File

@ -1,4 +1,4 @@
f;;; md4tj_parse --- Summary ;;; md4tj_parse --- Summary
;;; Commentary: ;;; Commentary:
@ -60,18 +60,34 @@ f;;; md4tj_parse --- Summary
;; multiple lines in the case of a block (NI) ;; multiple lines in the case of a block (NI)
(defun md4tj-process-block (codeblock) (defun md4tj-process-block (codeblock)
"Process CODEBLOCK and return html." "Process CODEBLOCK and return html."
(cond ((string-match "^# " codeblock) (md4tj-process-header codeblock)) (cond ((string-match "^#+ " codeblock) (md4tj-process-header (md4tj-process-line codeblock)))
(t (md4tj-process-paragraph 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) (defun md4tj-parse (mdfile outfile)
"Entry point to parse MDFILE and output to 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) (insert-file-contents mdfile)
(goto-char (point-min)) (goto-char (point-min))
(while (< (point) (point-max)) (set-buffer outbuf)
(md4tj-process-block (getline)) (while (with-current-buffer inbuf (< (point) (point-max)))
(forward-line)))) ;; 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) (provide 'md4tj_parse)
;;; md4tj_parse.el ends here ;;; md4tj_parse.el ends here

View File

@ -1,4 +1,7 @@
# Hello world! # Hello `world`!
## Hello world! ## Hello world!
### Hello world! ### Hello world!
#### Hello world! #### Hello ***world***!
[Example website](https://example.com)
[Example image](image.jpg)