4 Commits

  1. 13
      CHANGELOG.md
  2. 8
      assets/.babelrc
  3. 2
      assets/js/app.js
  4. 122
      assets/package-lock.json
  5. 1
      assets/package.json
  6. 6
      lib/mirage/markdown.ex
  7. 2
      lib/mirage_web/templates/note/index.html.eex
  8. 2
      lib/mirage_web/templates/note/show.html.eex
  9. 2
      mix.exs
  10. 9
      test/mirage_web/controllers/note_controller_test.exs

13
CHANGELOG.md

@ -5,6 +5,19 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.13.0](https://git.inhji.de/inhji/mirage/compare/v0.12.0...v0.13.0) (2021-02-07)
### Features:
* add syntax highlighting through prism.js
### Bug Fixes:
* actually use rendered markdown
## [v0.12.0](https://git.inhji.de/inhji/mirage/compare/v0.11.0...v0.12.0) (2021-02-07)

8
assets/.babelrc

@ -1,5 +1,13 @@
{
"presets": [
"@babel/preset-env"
],
"plugins": [
["prismjs", {
"languages": ["javascript", "css", "markup", "markdown", "elixir", "bash", "sql"],
"plugins": [],
"theme": "tomorrow",
"css": true
}]
]
}

2
assets/js/app.js

@ -13,6 +13,7 @@ import "../css/app.scss"
// import socket from "./socket"
//
import "phoenix_html"
import Prism from 'prismjs'
import {Socket} from "phoenix"
import NProgress from "nprogress"
import {LiveSocket} from "phoenix_live_view"
@ -39,3 +40,4 @@ if (document.querySelector(element)) {
initEditor(element)
}
Prism.highlightAll();

122
assets/package-lock.json

@ -8,6 +8,7 @@
"@codemirror/basic-setup": "^0.17.1",
"@codemirror/lang-markdown": "^0.17.1",
"@codemirror/theme-one-dark": "^0.17.4",
"babel-plugin-prismjs": "^2.0.1",
"minireset.css": "0.0.6",
"nprogress": "^0.2.0",
"phoenix": "file:../deps/phoenix",
@ -1943,6 +1944,14 @@
"object.assign": "^4.1.0"
}
},
"node_modules/babel-plugin-prismjs": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/babel-plugin-prismjs/-/babel-plugin-prismjs-2.0.1.tgz",
"integrity": "sha512-GqQGa3xX3Z2ft97oDbGvEFoxD8nKqb3ZVszrOc5H7icnEUA56BIjVYm86hfZZA82uuHLwTIfCXbEKzKG1BzKzg==",
"peerDependencies": {
"prismjs": "^1.18.0"
}
},
"node_modules/balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -2194,6 +2203,18 @@
"node": ">=6"
}
},
"node_modules/clipboard": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.6.tgz",
"integrity": "sha512-g5zbiixBRk/wyKakSwCKd7vQXDjFnAMGHoEyBogG/bw9kTD9GvdAvaoRR1ALcEzt3pVKxZR0pViekPMIS0QyGg==",
"optional": true,
"peer": true,
"dependencies": {
"good-listener": "^1.2.2",
"select": "^1.1.2",
"tiny-emitter": "^2.0.0"
}
},
"node_modules/clone-deep": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz",
@ -2942,6 +2963,13 @@
"node": ">= 0.4"
}
},
"node_modules/delegate": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/delegate/-/delegate-3.2.0.tgz",
"integrity": "sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==",
"optional": true,
"peer": true
},
"node_modules/dir-glob": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@ -3518,6 +3546,16 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/good-listener": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz",
"integrity": "sha1-1TswzfkxPf+33JoNR3CWqm0UXFA=",
"optional": true,
"peer": true,
"dependencies": {
"delegate": "^3.1.2"
}
},
"node_modules/graceful-fs": {
"version": "4.2.5",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.5.tgz",
@ -6383,6 +6421,18 @@
"node": ">=0.10.0"
}
},
"node_modules/prismjs": {
"version": "1.23.0",
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.23.0.tgz",
"integrity": "sha512-c29LVsqOaLbBHuIbsTxaKENh1N2EQBOHaWv7gkHN4dgRbxSREqDnDbtFJYdpPauS4YCplMSNCABQ6Eeor69bAA==",
"peer": true,
"dependencies": {
"clipboard": "^2.0.0"
},
"optionalDependencies": {
"clipboard": "^2.0.0"
}
},
"node_modules/promise-inflight": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz",
@ -6697,6 +6747,13 @@
"url": "https://opencollective.com/webpack"
}
},
"node_modules/select": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz",
"integrity": "sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=",
"optional": true,
"peer": true
},
"node_modules/semver": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
@ -7103,6 +7160,13 @@
"integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=",
"dev": true
},
"node_modules/tiny-emitter": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.1.0.tgz",
"integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==",
"optional": true,
"peer": true
},
"node_modules/to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
@ -9156,6 +9220,12 @@
"object.assign": "^4.1.0"
}
},
"babel-plugin-prismjs": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/babel-plugin-prismjs/-/babel-plugin-prismjs-2.0.1.tgz",
"integrity": "sha512-GqQGa3xX3Z2ft97oDbGvEFoxD8nKqb3ZVszrOc5H7icnEUA56BIjVYm86hfZZA82uuHLwTIfCXbEKzKG1BzKzg==",
"requires": {}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -9349,6 +9419,18 @@
"integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==",
"dev": true
},
"clipboard": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.6.tgz",
"integrity": "sha512-g5zbiixBRk/wyKakSwCKd7vQXDjFnAMGHoEyBogG/bw9kTD9GvdAvaoRR1ALcEzt3pVKxZR0pViekPMIS0QyGg==",
"optional": true,
"peer": true,
"requires": {
"good-listener": "^1.2.2",
"select": "^1.1.2",
"tiny-emitter": "^2.0.0"
}
},
"clone-deep": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz",
@ -9918,6 +10000,13 @@
"object-keys": "^1.0.12"
}
},
"delegate": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/delegate/-/delegate-3.2.0.tgz",
"integrity": "sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==",
"optional": true,
"peer": true
},
"dir-glob": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@ -10346,6 +10435,16 @@
"slash": "^3.0.0"
}
},
"good-listener": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz",
"integrity": "sha1-1TswzfkxPf+33JoNR3CWqm0UXFA=",
"optional": true,
"peer": true,
"requires": {
"delegate": "^3.1.2"
}
},
"graceful-fs": {
"version": "4.2.5",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.5.tgz",
@ -12490,6 +12589,15 @@
"integrity": "sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==",
"dev": true
},
"prismjs": {
"version": "1.23.0",
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.23.0.tgz",
"integrity": "sha512-c29LVsqOaLbBHuIbsTxaKENh1N2EQBOHaWv7gkHN4dgRbxSREqDnDbtFJYdpPauS4YCplMSNCABQ6Eeor69bAA==",
"peer": true,
"requires": {
"clipboard": "^2.0.0"
}
},
"promise-inflight": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz",
@ -12710,6 +12818,13 @@
"ajv-keywords": "^3.5.2"
}
},
"select": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz",
"integrity": "sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=",
"optional": true,
"peer": true
},
"semver": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
@ -13029,6 +13144,13 @@
"integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=",
"dev": true
},
"tiny-emitter": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.1.0.tgz",
"integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==",
"optional": true,
"peer": true
},
"to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",

1
assets/package.json

@ -18,6 +18,7 @@
"@babel/core": "^7.x",
"@babel/preset-env": "^7.x",
"babel-loader": "^8.x",
"babel-plugin-prismjs": "^2.0.1",
"copy-webpack-plugin": "^7.x",
"css-loader": "^5.x",
"css-minimizer-webpack-plugin": "^1.x",

6
lib/mirage/markdown.ex

@ -3,11 +3,13 @@ defmodule Mirage.Markdown do
def maybe_render_markdown(changeset, markdown_field, html_field) do
if markdown = get_change(changeset, markdown_field) do
html = Earmark.as_html!(markdown)
html = Earmark.as_html!(markdown, %Earmark.Options{
code_class_prefix: "lang- language-"
})
put_change(changeset, html_field, html)
else
changeset
end
end
end
end

2
lib/mirage_web/templates/note/index.html.eex

@ -15,7 +15,7 @@
<section>
<div class="content html width-full bg-content">
<%= Earmark.as_html!(note.content) |> raw %>
<%= raw note.content_html %>
</div>
</section>

2
lib/mirage_web/templates/note/show.html.eex

@ -11,7 +11,7 @@
<div class="width-full bg-content">
<article>
<div class="content html">
<%= Earmark.as_html!(@note.content) |> raw %>
<%= raw @note.content_html %>
</div>
</article>
</div>

2
mix.exs

@ -1,7 +1,7 @@
defmodule Mirage.MixProject do
use Mix.Project
@version "0.12.0"
@version "0.13.0"
def project do
[

9
test/mirage_web/controllers/note_controller_test.exs

@ -5,8 +5,8 @@ defmodule MirageWeb.NoteControllerTest do
setup :register_and_log_in_user
@create_attrs %{content: "some content", title: "some title"}
@update_attrs %{content: "some updated content"}
@create_attrs %{content: "some content", title: "some title", topic_string: "some tag"}
@update_attrs %{content: "some updated content", topic_string: "some other tag"}
@invalid_attrs %{content: nil}
def fixture(:note) do
@ -36,7 +36,8 @@ defmodule MirageWeb.NoteControllerTest do
assert redirected_to(conn) == Routes.note_path(conn, :show, id)
conn = get(conn, Routes.note_path(conn, :show, id))
assert html_response(conn, 200) =~ @create_attrs.title
assert html_response(conn, 200) =~ "some title"
assert html_response(conn, 200) =~ "some tag"
end
test "renders errors when data is invalid", %{conn: conn} do
@ -63,6 +64,8 @@ defmodule MirageWeb.NoteControllerTest do
conn = get(conn, Routes.note_path(conn, :show, note))
assert html_response(conn, 200) =~ "some updated content"
assert html_response(conn, 200) =~ "some other tag"
refute html_response(conn, 200) =~ "some tag"
end
test "renders errors when data is invalid", %{conn: conn, note: note} do

Loading…
Cancel
Save