boydm / phoenix_markdown Goto Github PK
View Code? Open in Web Editor NEWPhoenix Template Engine for Markdown
License: MIT License
Phoenix Template Engine for Markdown
License: MIT License
phoenix_markdown uses EEx.compile_string
so I thought I could embed eex tags in my .html.md
templates, however this is what happens (pipeline taken from engine.ex
):
iex(1)> "foo <%= 1 + 2 %> bar" |> Earmark.to_html |> EEx.compile_string(engine: Phoenix.HTML.Engine, file: "a", line: 1)
{:safe, [{:|, [], ["", "<p>foo <%= 1 + 2 %> bar</p>\n"]}]}
Earmark is html-encoding <
character so the whole eex <%= >
tag is broken. I know this is not phoenix_markdown fault (and probably neither earmark's), however I am still wondering if we can make it work somehow.
Hi,
A new user here. I was trying to render a piece of markdown in my Phoenix heex template.
I added <%= render("some_markdown.html") %>
to my template, but that doesn't render anything, because it's missing the =
.
Could it be that documentation should contain
<%= render("some_markdown.html") %>
instead of
<% render("some_markdown.html") %>
Line 154 in ef7b5f7
Starting updating my application to the latest versions of everything and ran into this issue where I can't compile.
$ mix deps.compile phoenix_markdown
==> phoenix_markdown
Compiling 2 files (.ex)
error: Earmark.Options.__struct__/0 is undefined, cannot expand struct Earmark.Options. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code
lib/phoenix_markdown/engine.ex:25: PhoenixMarkdown.Engine.compile/2
== Compilation error in file lib/phoenix_markdown/engine.ex ==
** (CompileError) lib/phoenix_markdown/engine.ex: cannot compile module PhoenixMarkdown.Engine (errors have been logged)
(stdlib 3.17) lists.erl:1358: :lists.mapfoldl/3
could not compile dependency :phoenix_markdown, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile phoenix_markdown", update it with "mix deps.update phoenix_markdown" or clean it with "mix deps.clean phoenix_markdown"
My versions...
$ elixir -v
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]
Elixir 1.15.0-dev (f59297a) (compiled with Erlang/OTP 24)
$ mix deps.get
Resolving Hex dependencies...
Resolution completed in 0.258s
Unchanged:
castore 0.1.22
certifi 2.9.0
combine 0.10.0
connection 1.1.0
cowboy 2.9.0
cowboy_telemetry 0.4.0
cowlib 2.11.0
db_connection 2.4.3
decimal 2.0.0
earmark 1.4.35
earmark_parser 1.4.30
ecto 3.9.4
ecto_sql 3.9.2
ecto_sqlite3 0.9.1
elixir_make 0.7.3
esbuild 0.6.1
expo 0.3.0
exqlite 0.13.2
file_system 0.2.10
floki 0.34.0
gettext 0.22.0
hackney 1.18.1
html_entities 0.5.2
idna 6.1.1
jason 1.4.0
metrics 1.0.1
mime 2.0.3
mimerl 1.2.0
myxql 0.6.3
parse_trans 3.3.1
pdf_generator 0.6.2
phoenix 1.7.0-rc.2
phoenix_ecto 4.4.0
phoenix_html 3.3.0
phoenix_live_dashboard 0.7.2
phoenix_live_reload 1.4.1
phoenix_live_view 0.18.11
phoenix_markdown 1.0.3
phoenix_pubsub 2.1.1
phoenix_template 1.0.1
phoenix_view 2.0.2
plug 1.14.0
plug_cowboy 2.6.0
plug_crypto 1.2.3
ranch 1.8.0
ssl_verify_fun 1.1.6
swoosh 1.9.1
telemetry 1.2.1
telemetry_metrics 0.6.1
telemetry_poller 1.0.0
timex 3.7.9
tzdata 1.1.1
unicode_util_compat 0.7.0
websock 0.4.3
websock_adapter 0.4.5
yamerl 0.10.0
yaml_elixir 2.9.0
yaml_front_matter 1.0.0
All dependencies are up to date
I am trying to use the phoenix route helpers (specifically the static_path
helper) to display an image from my app's static directory.
Rendering an image manually works (image gets displayed):
![My Image](/images/my_image.png)
But using the eex tag to embed the URL does not. This:
![My Image](<%= Routes.static_path(@conn, "/images/my_image.png") %>)
Just gets rendered in the document as ![My Image](/images/my_image.png)
.
I'm not familiar with how the library is put together but I wonder if this might be something similar to #8.
If I put the earmark config of the readme in my config.exs I get the following error:
** (Mix.Config.LoadError) could not load config config/config.exs
** (CompileError) config/config.exs:18: Earmark.Options.__struct__/1 is undefined, cannot expand struct Earmark.Options
Maybe phoenix markdown could use struct!/2
so the config does only need to be a map.
Is there any way to render markdown from nested directories? I have categories of markdown pages that I want to store, something like:
category_controller.ex
category1
|--- index.html.md
|--- page1InCat1.html.md
|--- page2InCat1.html.md
|--- page3InCat1.html.md
|--- ...
category2
|--- index.html.md
|--- page1InCat2.html.md
|--- page2InCat2.html.md
|--- page3InCat2.html.md
|--- ...
but I would like to both store these md files elsewhere besides next to the controller, and also render nested markdown files, which currently doesn't seem to work.
I wanted to know how I can render markdown data into the template if that is possible?
I have the following
<%= for magnet <- @magnets do %>
<div class="col-md-6">
<div class="card card-bordered style-primary">
<div class="card-head">
<div class="tools">
<div class="btn-group">
<%= link to: magnet_path(@conn, :edit, magnet), class: "btn btn-icon-toggle btn-refresh" do %>
<span class="md md-edit"></span>
<% end %>
<%= link to: magnet_path(@conn, :delete, magnet), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-icon-toggle btn-refresh" do %>
<span class="md md-delete"></span>
<% end %>
</div>
</div>
<%= link to: magnet_path(@conn, :show, magnet), class: "" do %>
<header><i class="fa fa-fw fa-tag"></i><%= magnet.title %></header>
<% end %>
</div>
<!--end .card-head -->
<div class="card-body style-default-bright">
<p>
<%= magnet.description %>
</p>
</div>
<div class="card-body style-default-bright">
<p>
<%= render "markdown_render.html", assigns %>
</p>
</div>
</div>
</div>
<% end %>
and <%= magnet.content %>
is markdown
How can I have that render inside the <%= render "markdown_render.html", assigns %>
Unfortunately projects depending on PhoenixMarkdown
and ex_doc
(or EarmarkParser
directly) are suffering from some difficulties described here.
This is a little bit unfortunate and I repeat here that indeed Earmark's
dependency on ex_doc
should be removed.
This is however a major undergoing and updating the dependency to 1.4.30 of Earmark is a good idea anyway, given that <=1.3 is not maintained and 1.5 is ante portas (for quite some while, but well Hannibal did not conquer Rome either ๐
)
Thanks for making this @boydm!
I'm trying to use phoenix_markdown
with a newer version of Phoenix but I'm getting a dependency error:
Running dependency resolution...
Failed to use "phoenix" (version 1.3.0-rc.2) because
phoenix_live_reload (version 1.0.8) requires ~> 1.0 or ~> 1.2-rc
phoenix_markdown (versions 0.1.0 to 0.1.4) requires ~> 1.1 * <-- This is in red
mix.lock specifies 1.3.0-rc.2
* This requirement does not match pre-releases. To match pre-releases include a
pre-release in the requirement, such as: "~> 2.0-beta".
** (Mix) Hex dependency resolution failed, relax the version requirements of your
dependencies or unlock them (by using mix deps.update or mix deps.unlock). If
you are unable to resolve the conflicts you can try overriding with
{:dependency, "~> 1.0", override: true}
Is this library forward compatible with newer versions of Phoenix (e.g. 1.3.0-rc.2+)? If so, could this be solved by bumping or making more broad the version of Phoenix phoenix_markdown
relies on?
Thanks for your time.
I turned on config :phoenix_markdown, :server_tags, :all
This renders the path correctly to /start
<%= home_path(@conn, :start %>
The following
This is a link to [Home](<%= home_path(@conn, :start %>)
renders to:
This is a link Home
(whereas Home is a link, but pointing to <%= home_path(@conn, :start %>
.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.