diff --git a/TODOS.md b/TODOS.md index 2415c51..24e2325 100644 --- a/TODOS.md +++ b/TODOS.md @@ -45,6 +45,8 @@ - [ ] Use spall to find ways to reduce run time. - [ ] warn/error when unknown key used in mustache. - [ ] Import/export packages. Hugo, jekyll, WordPress, etc. +- [ ] Markdown + - [ ] Add overloads for every extension - accept ^strings.Builder. - [ ] Review every file in thor - [ ] Review assets.odin - [ ] Review content.odin @@ -55,12 +57,14 @@ - [ ] Review minify.odin - [ ] Review `markdown/` - [ ] Review alerts.odin - - [ ] Review emoji.odin + - [x] Review emoji.odin + - [x] Review emoji_test.odin - [ ] Review footnotes.odin - [ ] Review footnotes_test.odin - [ ] Review highlight.odin - [ ] Review markdown.odin - - [ ] Review sectionate.odin + - [x] Review sectionate.odin + - [x] Review sectionate_test.odin - [ ] Review render.odin - [x] Review site.odin - [ ] Review treesitter/treesitter.odin diff --git a/markdown/emoji_test.odin b/markdown/emoji_test.odin index 17ea701..ac8f7a2 100644 --- a/markdown/emoji_test.odin +++ b/markdown/emoji_test.odin @@ -4,17 +4,19 @@ package markdown import "core:testing" @(test) -test_basic_expansion :: proc(t: ^testing.T) { +test_basic_emoji_expansion_works :: proc(t: ^testing.T) { testing.expect_value(t, expand_emoji(":smile:"), "😄") testing.expect_value(t, expand_emoji(":smile: :heart:"), "😄 ❤️") testing.expect_value(t, expand_emoji(":smile::heart:"), "😄❤️") testing.expect_value(t, expand_emoji("Hello :wave:!"), "Hello 👋!") testing.expect_value(t, expand_emoji(":smile: rest"), "😄 rest") testing.expect_value(t, expand_emoji("rest :smile:"), "rest 😄") + testing.expect_value(t, expand_emoji(":100:"), "💯") + testing.expect_value(t, expand_emoji(":stuck_out_tongue:"), "😛") } @(test) -test_no_match :: proc(t: ^testing.T) { +test_emoji_skips_non_matches :: proc(t: ^testing.T) { testing.expect_value(t, expand_emoji("Hello world"), "Hello world") testing.expect_value(t, expand_emoji("Hello:"), "Hello:") testing.expect_value(t, expand_emoji(":notreal:"), ":notreal:") @@ -23,14 +25,9 @@ test_no_match :: proc(t: ^testing.T) { } @(test) -test_invalid_shortcodes :: proc(t: ^testing.T) { +test_emoji_skips_invalid_shortcodes :: proc(t: ^testing.T) { testing.expect_value(t, expand_emoji("::"), "::") testing.expect_value(t, expand_emoji(":Smile:"), ":Smile:") testing.expect_value(t, expand_emoji(": not real :"), ": not real :") } -@(test) -test_valid_formats :: proc(t: ^testing.T) { - testing.expect_value(t, expand_emoji(":100:"), "💯") - testing.expect_value(t, expand_emoji(":stuck_out_tongue:"), "😛") -} diff --git a/markdown/sectionate.odin b/markdown/sectionate.odin index c69ea85..581ada7 100644 --- a/markdown/sectionate.odin +++ b/markdown/sectionate.odin @@ -37,8 +37,10 @@ wrap_sections :: proc(html: string) -> string { found = true } - if !found { + if found { + return strings.to_string(sb) + } else { return html } - return strings.to_string(sb) } + diff --git a/markdown/sectionate_test.odin b/markdown/sectionate_test.odin new file mode 100644 index 0000000..5e410f9 --- /dev/null +++ b/markdown/sectionate_test.odin @@ -0,0 +1,49 @@ +#+test +package markdown + +import "core:testing" + +@(test) +test_wrap_sections_works :: proc(t: ^testing.T) { + testing.expect_value( + t, + wrap_sections("

intro

Title

body

"), + "

intro

Title

body

", + ) + + testing.expect_value( + t, + wrap_sections("

a

A

b

B

c

"), + "

a

A

b

B

c

", + ) + + testing.expect_value( + t, + wrap_sections("

Title

body

"), + "

Title

body

", + ) + + testing.expect_value( + t, + wrap_sections("

intro

Title

"), + "

intro

Title

", + ) +} + +@(test) +test_wrap_sections_doesnt_split_content :: proc(t: ^testing.T) { + testing.expect_value( + t, + wrap_sections("

just text

"), + "

just text

", + ) + + testing.expect_value(t, wrap_sections(""), "") + + testing.expect_value( + t, + wrap_sections("

Big

Small

"), + "

Big

Small

", + ) +} +