Created
December 6, 2014 05:25
-
-
Save JoshAshby/8dfada69179232b27c3f to your computer and use it in GitHub Desktop.
Basic start of a quill.js powered thingy that supports KaTeX with a custom format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$output = $("#output") | |
window.editor = new Quill('#editor', { | |
modules: { | |
'toolbar': { container: '#toolbar' }, | |
'link-tooltip': true | |
}, | |
theme: 'snow' | |
}) | |
$('#toolbar').on 'click', '.ql-katex', (e) -> | |
e.preventDefault() | |
editor.focus() | |
range = editor.getSelection() | |
length = editor.getLength() | |
if range? | |
if range.end is range.start | |
end = length | |
else | |
end = range.end | |
editor.formatText(range.start, end, 'katex', true) | |
editor.addFormat 'katex', { tag: 'span', attribute: 'katex' } | |
editor.prepareFormat 'katex', true | |
editor.on 'text-change', (delta, source) -> | |
$output.html editor.getHTML() | |
$output.find('[katex="true"]').each (i, e) -> | |
$this = $(this) | |
formula = $this.text() | |
rendered = katex.renderToString("\\displaystyle { #{formula} }") | |
$this.html rendered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$base-grey: #ACACAC; | |
body { | |
font-family: sans-serif; | |
color: #444444; | |
} | |
.quill-embed { | |
box-shadow: 2px 2px 20px 1px $base-grey; | |
height: 100vh; | |
#toolbar { | |
border-bottom: 1px solid $base-grey; | |
.ql-katex { | |
&:hover { | |
color: #086ACD; | |
} | |
} | |
} | |
#editor { | |
height: 5em; | |
overflow: scroll; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="quill-embed"> | |
<div id="toolbar"> | |
<span class="ql-format-group"> | |
<select title="Font" class="ql-font"> | |
<option value="sans-serif" selected="">Sans Serif</option> | |
<option value="serif">Serif</option> | |
<option value="monospace">Monospace</option> | |
</select> | |
<select title="Size" class="ql-size"> | |
<option value="10px">Small</option> | |
<option value="13px" selected="">Normal</option> | |
<option value="18px">Large</option> | |
<option value="32px">Huge</option> | |
</select> | |
</span> | |
<span class="ql-format-group"> | |
<span title="Bold" class="ql-format-button ql-bold"></span> | |
<span class="ql-format-separator"></span> | |
<span title="Italic" class="ql-format-button ql-italic"></span> | |
<span class="ql-format-separator"></span> | |
<span title="Underline" class="ql-format-button ql-underline"></span> | |
<span class="ql-format-separator"></span> | |
<span title="Strikethrough" class="ql-format-button ql-strike"></span> | |
<span class="ql-format-separator"></span> | |
<span title="KaTeX" class="ql-format-button ql-katex">K</span> | |
</span> | |
<span class="ql-format-group"> | |
<select title="Text Color" class="ql-color"> | |
<option value="rgb(0, 0, 0)" label="rgb(0, 0, 0)" selected=""></option> | |
<option value="rgb(230, 0, 0)" label="rgb(230, 0, 0)"></option> | |
<option value="rgb(255, 153, 0)" label="rgb(255, 153, 0)"></option> | |
<option value="rgb(255, 255, 0)" label="rgb(255, 255, 0)"></option> | |
<option value="rgb(0, 138, 0)" label="rgb(0, 138, 0)"></option> | |
<option value="rgb(0, 102, 204)" label="rgb(0, 102, 204)"></option> | |
<option value="rgb(153, 51, 255)" label="rgb(153, 51, 255)"></option> | |
<option value="rgb(255, 255, 255)" label="rgb(255, 255, 255)"></option> | |
<option value="rgb(250, 204, 204)" label="rgb(250, 204, 204)"></option> | |
<option value="rgb(255, 235, 204)" label="rgb(255, 235, 204)"></option> | |
<option value="rgb(255, 255, 204)" label="rgb(255, 255, 204)"></option> | |
<option value="rgb(204, 232, 204)" label="rgb(204, 232, 204)"></option> | |
<option value="rgb(204, 224, 245)" label="rgb(204, 224, 245)"></option> | |
<option value="rgb(235, 214, 255)" label="rgb(235, 214, 255)"></option> | |
<option value="rgb(187, 187, 187)" label="rgb(187, 187, 187)"></option> | |
<option value="rgb(240, 102, 102)" label="rgb(240, 102, 102)"></option> | |
<option value="rgb(255, 194, 102)" label="rgb(255, 194, 102)"></option> | |
<option value="rgb(255, 255, 102)" label="rgb(255, 255, 102)"></option> | |
<option value="rgb(102, 185, 102)" label="rgb(102, 185, 102)"></option> | |
<option value="rgb(102, 163, 224)" label="rgb(102, 163, 224)"></option> | |
<option value="rgb(194, 133, 255)" label="rgb(194, 133, 255)"></option> | |
<option value="rgb(136, 136, 136)" label="rgb(136, 136, 136)"></option> | |
<option value="rgb(161, 0, 0)" label="rgb(161, 0, 0)"></option> | |
<option value="rgb(178, 107, 0)" label="rgb(178, 107, 0)"></option> | |
<option value="rgb(178, 178, 0)" label="rgb(178, 178, 0)"></option> | |
<option value="rgb(0, 97, 0)" label="rgb(0, 97, 0)"></option> | |
<option value="rgb(0, 71, 178)" label="rgb(0, 71, 178)"></option> | |
<option value="rgb(107, 36, 178)" label="rgb(107, 36, 178)"></option> | |
<option value="rgb(68, 68, 68)" label="rgb(68, 68, 68)"></option> | |
<option value="rgb(92, 0, 0)" label="rgb(92, 0, 0)"></option> | |
<option value="rgb(102, 61, 0)" label="rgb(102, 61, 0)"></option> | |
<option value="rgb(102, 102, 0)" label="rgb(102, 102, 0)"></option> | |
<option value="rgb(0, 55, 0)" label="rgb(0, 55, 0)"></option> | |
<option value="rgb(0, 41, 102)" label="rgb(0, 41, 102)"></option> | |
<option value="rgb(61, 20, 102)" label="rgb(61, 20, 102)"></option> | |
</select> | |
<span class="ql-format-separator"></span> | |
<select title="Background Color" class="ql-background"> | |
<option value="rgb(0, 0, 0)" label="rgb(0, 0, 0)"></option> | |
<option value="rgb(230, 0, 0)" label="rgb(230, 0, 0)"></option> | |
<option value="rgb(255, 153, 0)" label="rgb(255, 153, 0)"></option> | |
<option value="rgb(255, 255, 0)" label="rgb(255, 255, 0)"></option> | |
<option value="rgb(0, 138, 0)" label="rgb(0, 138, 0)"></option> | |
<option value="rgb(0, 102, 204)" label="rgb(0, 102, 204)"></option> | |
<option value="rgb(153, 51, 255)" label="rgb(153, 51, 255)"></option> | |
<option value="rgb(255, 255, 255)" label="rgb(255, 255, 255)" selected=""></option> | |
<option value="rgb(250, 204, 204)" label="rgb(250, 204, 204)"></option> | |
<option value="rgb(255, 235, 204)" label="rgb(255, 235, 204)"></option> | |
<option value="rgb(255, 255, 204)" label="rgb(255, 255, 204)"></option> | |
<option value="rgb(204, 232, 204)" label="rgb(204, 232, 204)"></option> | |
<option value="rgb(204, 224, 245)" label="rgb(204, 224, 245)"></option> | |
<option value="rgb(235, 214, 255)" label="rgb(235, 214, 255)"></option> | |
<option value="rgb(187, 187, 187)" label="rgb(187, 187, 187)"></option> | |
<option value="rgb(240, 102, 102)" label="rgb(240, 102, 102)"></option> | |
<option value="rgb(255, 194, 102)" label="rgb(255, 194, 102)"></option> | |
<option value="rgb(255, 255, 102)" label="rgb(255, 255, 102)"></option> | |
<option value="rgb(102, 185, 102)" label="rgb(102, 185, 102)"></option> | |
<option value="rgb(102, 163, 224)" label="rgb(102, 163, 224)"></option> | |
<option value="rgb(194, 133, 255)" label="rgb(194, 133, 255)"></option> | |
<option value="rgb(136, 136, 136)" label="rgb(136, 136, 136)"></option> | |
<option value="rgb(161, 0, 0)" label="rgb(161, 0, 0)"></option> | |
<option value="rgb(178, 107, 0)" label="rgb(178, 107, 0)"></option> | |
<option value="rgb(178, 178, 0)" label="rgb(178, 178, 0)"></option> | |
<option value="rgb(0, 97, 0)" label="rgb(0, 97, 0)"></option> | |
<option value="rgb(0, 71, 178)" label="rgb(0, 71, 178)"></option> | |
<option value="rgb(107, 36, 178)" label="rgb(107, 36, 178)"></option> | |
<option value="rgb(68, 68, 68)" label="rgb(68, 68, 68)"></option> | |
<option value="rgb(92, 0, 0)" label="rgb(92, 0, 0)"></option> | |
<option value="rgb(102, 61, 0)" label="rgb(102, 61, 0)"></option> | |
<option value="rgb(102, 102, 0)" label="rgb(102, 102, 0)"></option> | |
<option value="rgb(0, 55, 0)" label="rgb(0, 55, 0)"></option> | |
<option value="rgb(0, 41, 102)" label="rgb(0, 41, 102)"></option> | |
<option value="rgb(61, 20, 102)" label="rgb(61, 20, 102)"></option> | |
</select> | |
</span> | |
<span class="ql-format-group"> | |
<span title="List" class="ql-format-button ql-list"></span> | |
<span class="ql-format-separator"></span> | |
<span title="Bullet" class="ql-format-button ql-bullet"></span> | |
<span class="ql-format-separator"></span> | |
<select title="Text Alignment" class="ql-align"> | |
<option value="left" label="Left" selected=""></option> | |
<option value="center" label="Center"></option> | |
<option value="right" label="Right"></option> | |
<option value="justify" label="Justify"></option> | |
</select> | |
</span> | |
</div> | |
<div id="editor"></div> | |
</div> | |
<div id="output"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment