From 1550094d19c1f443d61c148ea5d6cfeb64111623 Mon Sep 17 00:00:00 2001 From: j4nk Date: Wed, 4 Jan 2023 12:07:33 -0500 Subject: [PATCH] Added strikethrough and highlight syntax --- README.md | 4 ++-- md4tj_parse.el | 46 +++++++++++++++++++++++++++------------------- test_file.html | 6 +++--- test_file.md4tj | 4 ++-- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 371856b..78d9be0 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,10 @@ A language and parser written in Emacs Lisp for my custom extension of Markdown, - [ ] Footnote (Will not implement) - [ ] Heading ID (Will not implement) - [ ] Definition List (Will not implement) -- [ ] Strikethrough +- [x] Strikethrough - [ ] Task List (Will not implement) - [ ] Emoji (Will not implement) -- [ ] Highlight +- [x] Highlight - [ ] Subscript (Will not implement) - [ ] Superscript (Will not implement) diff --git a/md4tj_parse.el b/md4tj_parse.el index 29a3acc..0fc28c6 100644 --- a/md4tj_parse.el +++ b/md4tj_parse.el @@ -35,30 +35,38 @@ (defun md4tj-process-line (line) "Process all inline elements of the LINE, return HTML." - ;; Finally links + ;; Finally strikethrough (replace-regexp-in-string - "\\[\\([^\\[]*\\)](\\([^\\[]*\\))" - (concat (md4tj-begin-tag "a" (list '("href" "\\2"))) "\\1" (md4tj-end-tag "a")) - ;; Then images + "~~\\(.*\\)~~" + "\\1" + ;; Then highlight (replace-regexp-in-string - "!\\[\\([^\\[]*\\)](\\([^\\[]*\\))" - (md4tj-begin-tag "img" (list '("src" "\\2") '("alt" "\\1"))) - ;; Then videos + "==\\(.*\\)==" + "\\1" + ;; Then links (replace-regexp-in-string - "!!\\[\\([^\\[]*\\)](\\([^\\[]*\\))" - (concat (md4tj-begin-tag "video" (list '("src" "\\2") '("type" "video/webm") '("controls" "true"))) "\\1" (md4tj-end-tag "video")) - ;; Then emphasis - (replace-regexp-in-string - "\\*\\(.*\\)\\*" - "\\1" - ;; Then strong + "\\[\\([^\\[]*\\)](\\([^\\[]*\\))" + (concat (md4tj-begin-tag "a" (list '("href" "\\2"))) "\\1" (md4tj-end-tag "a")) + ;; Then images (replace-regexp-in-string - "\\*\\*\\(.*\\)\\*\\*" - "\\1" - ;; First code + "!\\[\\([^\\[]*\\)](\\([^\\[]*\\))" + (md4tj-begin-tag "img" (list '("src" "\\2") '("alt" "\\1"))) + ;; Then videos (replace-regexp-in-string - "`\\(.*\\)`" - "\\1" line))))))) + "!!\\[\\([^\\[]*\\)](\\([^\\[]*\\))" + (concat (md4tj-begin-tag "video" (list '("src" "\\2") '("type" "video/webm") '("controls" "true"))) "\\1" (md4tj-end-tag "video")) + ;; Then emphasis + (replace-regexp-in-string + "\\*\\(.*\\)\\*" + "\\1" + ;; Then strong + (replace-regexp-in-string + "\\*\\*\\(.*\\)\\*\\*" + "\\1" + ;; First code + (replace-regexp-in-string + "`\\(.*\\)`" + "\\1" line))))))))) (defun md4tj-clean-multiline (line) "Clean LINE of markdown syntax for ul." diff --git a/test_file.html b/test_file.html index 1c4c2c5..370336b 100644 --- a/test_file.html +++ b/test_file.html @@ -26,8 +26,8 @@



@@ -46,6 +46,6 @@ int main() {
-Last updated: Wed Jan 4 10:43:05 2023 +Last updated: Wed Jan 4 11:41:25 2023 \ No newline at end of file diff --git a/test_file.md4tj b/test_file.md4tj index fc20499..8856612 100644 --- a/test_file.md4tj +++ b/test_file.md4tj @@ -13,8 +13,8 @@ ![Example image](usbs.png) !![Example video](test_video.webm) -- unordered item 1 -- unordered item 2 +- unordered ~~item 1~~ +- unordered ==item 2== - unordered item 3 1. ordered item 1