Editor: Add inline code and quotes

This commit is contained in:
Eragon 2022-05-19 22:29:45 +02:00
parent bcbab7033d
commit 0d00b4dfb6
Signed by: Eragon
GPG Key ID: 087126EBFC725006
2 changed files with 18 additions and 2 deletions

View File

@ -124,6 +124,22 @@ function editor_set_title(event, level, diff)
});
}
function editor_quote(event)
{
editor_act_on_lines(event, function(line) {
/* Strip all the initial > (and count them) */
let count = 0;
while(count < line.length && line[count] == '>') count++;
let contents_index = count;
if(count < line.length && line[count] == ' ') contents_index++;
let contents = line.slice(contents_index);
/* Apply the difference */
return '>'.repeat(count + 1) + ' ' + contents;
});
}
previewTimeout = null;
ta = document.querySelector(".editor textarea");
ta.addEventListener('keydown', function(e) {

View File

@ -54,12 +54,12 @@
<span class="separator"></span>
<!-- Code, Citations -->
<button type="button" onclick="editor_btn_type()">
<button type="button" onclick="editor_insert_around(event)" data-before="`" data-after="`" title="`code`">
<svg viewBox="0 0 24 24">
<path d="M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"/>
</svg>
</button>
<button type="button" onclick="editor_btn_type()">
<button type="button" onclick="editor_quote(event)">
<svg viewBox="0 0 24 24">
<path d="M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"/>
</svg>