Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support article and approach widgets #6644

Merged
merged 1 commit into from
Jan 9, 2024
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
7 changes: 6 additions & 1 deletion app/commands/markdown/preprocess.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ def convert_inline_links!

link_text = node.each.map(&:to_commonmark).join.strip
link_text.match(%r{^(concept|exercise):([\w-]+)/([\w-]+)$}) do |m|
node.url = "https://exercism.org/tracks/#{m[2]}/#{m[1]}s/#{m[3]}"
node.url = "https://exercism.org/tracks/#{m[2]}/#{m[1].pluralize}/#{m[3]}"
node.each.first.string_content = m[3]
end

link_text.match(%r{^(article|approach):([\w-]+)/([\w-]+)/([\w-]+)$}) do |m|
node.url = "https://exercism.org/tracks/#{m[2]}/exercises/#{m[3]}/#{m[1].pluralize}/#{m[4]}"
node.each.first.string_content = m[4]
end

link_text.match(%r{^video:vimeo/(\d+)$}) do |m|
node.url = "https://player.vimeo.com/video/#{m[1]}"
end
Expand Down
24 changes: 20 additions & 4 deletions test/commands/markdown/parse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,30 +285,46 @@ class Markdown::ParseTest < ActiveSupport::TestCase
end

test "render concept widget link without link" do
# TODO: render concept widget instead of link
expected = %(<p><a href="https://exercism.org/tracks/julia/concepts/if-statements" data-tooltip-type="concept" data-endpoint="/tracks/julia/concepts/if-statements/tooltip">if-statements</a></p>\n) # rubocop:disable Layout/LineLength
assert_equal expected, Markdown::Parse.("[concept:julia/if-statements]()")
end

test "render concept widget link with link" do
# TODO: render concept widget instead of link
expected = %(<p><a href="https://exercism.org/tracks/julia/concepts/if-statements" data-tooltip-type="concept" data-endpoint="/tracks/julia/concepts/if-statements/tooltip">if-statements</a></p>\n) # rubocop:disable Layout/LineLength
assert_equal expected,
Markdown::Parse.("[concept:julia/if-statements](https://exercism.org/tracks/julia/concepts/if-statements)")
end

test "render exercise widget link without link" do
# TODO: render exercise widget instead of link
expected = %(<p><a href="https://exercism.org/tracks/julia/exercises/two-fer" data-tooltip-type="exercise" data-endpoint="/tracks/julia/exercises/two-fer/tooltip">two-fer</a></p>\n) # rubocop:disable Layout/LineLength
assert_equal expected, Markdown::Parse.("[exercise:julia/two-fer]()")
end

test "render exercise widget link with link" do
# TODO: render exercise widget instead of link
expected = %(<p><a href="https://exercism.org/tracks/julia/exercises/two-fer" data-tooltip-type="exercise" data-endpoint="/tracks/julia/exercises/two-fer/tooltip">two-fer</a></p>\n) # rubocop:disable Layout/LineLength
assert_equal expected, Markdown::Parse.("[exercise:julia/two-fer](https://exercism.org/tracks/julia/exercises/two-fer)")
end

test "render article widget link without link" do
expected = %(<p><a href="https://exercism.org/tracks/julia/exercises/reverse-string/articles/performance">performance</a></p>\n)
assert_equal expected, Markdown::Parse.("[article:julia/reverse-string/performance]()")
end

test "render article widget link with link" do
expected = %(<p><a href="https://exercism.org/tracks/julia/exercises/reverse-string/articles/performance">performance</a></p>\n)
assert_equal expected, Markdown::Parse.("[article:julia/reverse-string/performance](https://exercism.org/tracks/julia/exercises/reverse-string/articles/performance)")
end

test "render approach widget link without link" do
expected = %(<p><a href="https://exercism.org/tracks/julia/exercises/two-fer/approaches/default-value">default-value</a></p>\n)
assert_equal expected, Markdown::Parse.("[approach:julia/two-fer/default-value]()")
end

test "render approach widget link with link" do
expected = %(<p><a href="https://exercism.org/tracks/julia/exercises/two-fer/approaches/default-value">default-value</a></p>\n)
assert_equal expected, Markdown::Parse.("[approach:julia/two-fer/default-value](https://exercism.org/tracks/julia/exercises/two-fer/approaches/default-value)")
end

test "don't render exercise widget for approach link" do
expected = %(<p><a href="https://exercism.org/tracks/julia/exercises/two-fer/approaches/default-value">approach</a></p>\n)
assert_equal expected, Markdown::Parse.("[approach](https://exercism.org/tracks/julia/exercises/two-fer/approaches/default-value)")
Expand Down
Loading