Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/content_filters/markdown_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ContentFilters::MarkdownFilter < ActionText::Content::Filter
# 2. Use backslash escaping: \*\*not bold\*\* → renders as **not bold** (plain text)
MARKDOWN_PATTERNS = [
/\*\*[^*]+\*\*/, # Bold: **text**
/(?<!^)\*[^*\s][^*]*\*/m, # Italic: *text* (not at line start to avoid "* list items")
/(?<!\*)\*(?![*\s])[^*]+\*(?!\*)/, # Italic: *text* (lookarounds avoid **bold** and "* list items")
/`[^`]+`/, # Inline code: `code`
/```[\s\S]+?```/, # Code blocks: ```code```
/^[#]{1,6}\s/m, # Header levels 1-6: # Header
Expand Down
13 changes: 13 additions & 0 deletions test/helpers/content_filters_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ class ContentFiltersTest < ActionView::TestCase
assert_markdown_rendered "This is *italic* text", /<em>italic<\/em>/
end

test "renders italic text at line start" do
assert_markdown_applicable "*italic* at start"
assert_markdown_rendered "*italic* at start", /<em>italic<\/em>/
end

test "renders italic text spanning multiple lines" do
multiline_italic = "*italic text\nacross lines*"
assert_markdown_applicable multiline_italic
filtered = apply_text_filters(multiline_italic)
assert_match /<em>italic text/, filtered.to_html
assert_match /across lines<\/em>/, filtered.to_html
end

test "renders inline code with backticks" do
assert_markdown_rendered "Use the `print()` function", /<code>print\(\)<\/code>/
end
Expand Down