Skip to content

Commit b49a1c5

Browse files
committed
add katex support
1 parent 6a33bfc commit b49a1c5

File tree

10 files changed

+7663
-6
lines changed

10 files changed

+7663
-6
lines changed

app/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
<body>
2121
{{content-for "body"}}
2222

23+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.min.css" integrity="sha384-9eLZqc9ds8eNjO3TmqPeYcDj8n+Qfa4nuSiGYa6DjLNcv9BtN69ZIulL9+8CqC9Y" crossorigin="anonymous">
24+
2325
<script src="{{rootURL}}assets/vendor.js"></script>
2426
<script src="{{rootURL}}assets/trouble-maker-frontend.js"></script>
2527

2628
{{content-for "body-footer"}}
29+
30+
2731
</body>
2832
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import showdown from 'showdown';
3+
4+
export function initialize() {
5+
// register showdownKatex as "katex" extension
6+
showdown.extension("katex", showdownKatex());
7+
}
8+
9+
export default {
10+
initialize
11+
};

app/pods/components/choice-editor/template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<h3> {{input type="text" class="input-text" value=choice.title}} </h3>
1010
</div>
1111
<div class="col-5">
12-
{{markdown-to-html choice.title}}
12+
{{markdown-to-html choice.title extensions='katex'}}
1313
</div>
1414
</div>
1515
<div class="row justify-content-center align-items-center">
@@ -22,7 +22,7 @@
2222
</p>
2323
</div>
2424
<div class="col-5">
25-
{{markdown-to-html choice.description}}
25+
{{markdown-to-html choice.description extensions='katex'}}
2626
</div>
2727
</div>
2828
{{else}}

app/pods/components/question-editor/template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{input type="text" class="input-text" value=question.title}}
1515
</div>
1616
<div class="col-5">
17-
{{markdown-to-html question.title}}
17+
{{markdown-to-html question.title extensions='katex'}}
1818
</div>
1919
</div>
2020

@@ -26,7 +26,7 @@
2626
{{textarea type="text" class="input-text py-4" value=question.description}}
2727
</div>
2828
<div class="col-5">
29-
{{markdown-to-html question.description}}
29+
{{markdown-to-html question.description extensions='katex'}}
3030
</div>
3131
</div>
3232

app/pods/components/quiz-editor/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{{textarea type="text" class="input-text py-4" value=quiz.description}}
2525
</div>
2626
<div class="col-3">
27-
{{markdown-to-html quiz.description}}
27+
{{markdown-to-html quiz.description extensions='katex'}}
2828
</div>
2929
</div>
3030
{{#unless quiz.isNew}}

ember-cli-build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ module.exports = function(defaults) {
2020
// please specify an object with the list of modules as keys
2121
// along with the exports of each module as its value.
2222
app.import('node_modules/@coding-blocks/motley/dist/app.min.css')
23+
app.import('node_modules/showdown-katex-studdown/dist/showdown-katex.js')
2324
return app.toTree();
2425
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"ember-confirm-dialog": "^1.2.1",
6161
"ember-modal-dialog": "^3.0.0-beta.0",
6262
"ember-simple-auth": "^1.6.0",
63-
"ember-simple-auth-token": "^4.0.3"
63+
"ember-simple-auth-token": "^4.0.3",
64+
"showdown-katex-studdown": "^0.4.0"
6465
}
6566
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render } from '@ember/test-helpers';
4+
import hbs from 'htmlbars-inline-precompile';
5+
6+
module('Integration | Helper | render-katex', function(hooks) {
7+
setupRenderingTest(hooks);
8+
9+
// Replace this with your real tests.
10+
test('it renders', async function(assert) {
11+
this.set('inputValue', '1234');
12+
13+
await render(hbs`{{render-katex inputValue}}`);
14+
15+
assert.equal(this.element.textContent.trim(), '1234');
16+
});
17+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Application from '@ember/application';
2+
3+
import { initialize } from 'trouble-maker-frontend/initializers/register-katex-showdown';
4+
import { module, test } from 'qunit';
5+
import { setupTest } from 'ember-qunit';
6+
import { run } from '@ember/runloop';
7+
8+
module('Unit | Initializer | register-katex-showdown', function(hooks) {
9+
setupTest(hooks);
10+
11+
hooks.beforeEach(function() {
12+
this.TestApplication = Application.extend();
13+
this.TestApplication.initializer({
14+
name: 'initializer under test',
15+
initialize
16+
});
17+
18+
this.application = this.TestApplication.create({ autoboot: false });
19+
});
20+
21+
hooks.afterEach(function() {
22+
run(this.application, 'destroy');
23+
});
24+
25+
// Replace this with your real tests.
26+
test('it works', async function(assert) {
27+
await this.application.boot();
28+
29+
assert.ok(true);
30+
});
31+
});

0 commit comments

Comments
 (0)