Skip to content
New issue

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

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

Already on GitHub? # to your account

Fixed support of non elixir code blocks #572

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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
> - You can also [buy me a coffee](https://ko-fi.com/C0C316P9FN), as it would encourage me spending
> more of my free time to fixing bugs and developing new features 🤗

## v0.8.2 (not released)

- **bugfix**: [fixed support of non elixir code blocks](https://github.com/phenixdigital/phoenix_storybook/issues/570)

## v0.8.1 (2025-01-20)

- **improvement**: [better formatting of playground's HTML](https://github.com/phenixdigital/phoenix_storybook/pull/562) - 🙏 [@xxdavid](https://github.com/xxdavid)
Expand Down
6 changes: 3 additions & 3 deletions lib/phoenix_storybook/rendering/code_renderer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ defmodule PhoenixStorybook.Rendering.CodeRenderer do
code =
if format? do
case lang do
:elixir -> ElixirLexer.lex(code)
:heex -> HEExLexer.lex(code)
:elixir -> code |> ElixirLexer.lex() |> HTMLFormatter.format_inner_as_binary([])
:heex -> code |> HEExLexer.lex() |> HTMLFormatter.format_inner_as_binary([])
_ -> code
end
|> HTMLFormatter.format_inner_as_binary([])
else
code
end
Expand Down
1 change: 1 addition & 0 deletions lib/phoenix_storybook/stories/doc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ defmodule PhoenixStorybook.Stories.Doc do
"elixir" -> :elixir
"heex" -> :heex
"" -> code |> String.trim_leading() |> guess_lang()
_ -> :unknown
end

CodeRenderer.render_code_block(code, lang, trim: false)
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/components/event_component.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
defmodule EventComponent do
use Phoenix.Component

@doc """
Component doc

```
Some code
```

```css
.my-class {
margin: 0;
}
```
"""
def component(assigns) do
assigns =
assigns
Expand Down
10 changes: 10 additions & 0 deletions test/phoenix_storybook/stories/doc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ defmodule PhoenixStorybook.Stories.DocTest do
assert log =~
"could not fetch module doc from PhoenixStorybook.Stories.DocTest.NoDocLiveComponent"
end

test "it does not crash with css and untyped code blocks" do
%Doc{header: header, body: body} =
"event/event_component.story.exs"
|> compile_story()
|> Doc.fetch_doc_as_html()

refute is_nil(header)
refute is_nil(body)
end
end

defp compile_story(path) do
Expand Down