diff --git a/md4tj_parse.el b/md4tj_parse.el
index 1e13944..4b72808 100644
--- a/md4tj_parse.el
+++ b/md4tj_parse.el
@@ -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) "
")
+ (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
diff --git a/test_file.md4tj b/test_file.md4tj
index 9de7255..730a5c3 100644
--- a/test_file.md4tj
+++ b/test_file.md4tj
@@ -1,4 +1,7 @@
-# Hello world!
+# Hello `world`!
## Hello world!
### Hello world!
-#### Hello world!
\ No newline at end of file
+#### Hello ***world***!
+
+[Example website](https://example.com)
+[Example image](image.jpg)
\ No newline at end of file