Compare commits

..

4 Commits

Author SHA1 Message Date
53ad572369 added experimental syntax highlighting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2023-10-13 05:10:17 +03:00
28501e458b cleanup and notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2023-10-12 23:35:14 +03:00
ad2df7c676 added code blocks + notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2023-10-12 22:56:12 +03:00
9494439f77 fixes and tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2023-10-12 22:13:38 +03:00
3 changed files with 117 additions and 60 deletions

View File

@ -28,8 +28,6 @@
/*text-size-adjust: none;*/ /*text-size-adjust: none;*/
text-size-adjust: 150%; text-size-adjust: 150%;
} }
.editor { .editor {
@ -144,11 +142,18 @@ editor .outline .block:focus {
} }
.editor .outline .block.focused:not(:focus)>.text { .editor .outline .block.focused:not(:focus)>.text {
background: rgba(0,0,0,0.01); background: rgba(0,0,0,0.01);
border-bottom: solid 2px rgba(0,0,0,0.03);
} }
.editor .outline div[collapsed] { /* collapsed block... */
.editor .outline .block[collapsed] {
border-bottom: solid 1px silver; border-bottom: solid 1px silver;
} }
/* hide children... */
.editor .outline .block[collapsed]>.children {
display: none;
}
/* click/tap zones for expand button... */ /* click/tap zones for expand button... */
.editor .outline .block>.view:before, .editor .outline .block>.view:before,
@ -200,11 +205,6 @@ editor .outline .block:focus {
content: "●"; content: "●";
} }
/* collapse -- hide children... */
.editor .outline .block[collapsed] .block {
display: none;
}
/* XXX are we selecting subtrees or blocks??? */ /* XXX are we selecting subtrees or blocks??? */
.editor .outline [selected] { .editor .outline [selected] {
background: silver; background: silver;
@ -233,7 +233,9 @@ editor .outline .block:focus {
/********************************************************** Styles ***/ /********************************************************** Styles ***/
/* Headings... */
/*------------------------------------------------------ Headings ---*/
.editor .outline .heading-1, .editor .outline .heading-1,
.editor .outline .heading-2, .editor .outline .heading-2,
.editor .outline .heading-3, .editor .outline .heading-3,
@ -276,7 +278,8 @@ editor .outline .block:focus {
} }
/* Quote... */ /*--------------------------------------------------------- Quote ---*/
.editor .outline .quote>.text { .editor .outline .quote>.text {
--indent: 1rem; --indent: 1rem;
--margin: 0.7rem; --margin: 0.7rem;
@ -298,8 +301,8 @@ editor .outline .block:focus {
} }
/* List... */ /*---------------------------------------------------------- List ---*/
/* XXX needs to be in the middle of the first .view but with universal size... */
.editor .outline .list-item>.view:before, .editor .outline .list-item>.view:before,
.editor .outline .list>.children>.block>.view:not(:empty):before { .editor .outline .list>.children>.block>.view:not(:empty):before {
content: "◼"; content: "◼";
@ -325,16 +328,15 @@ editor .outline .block:focus {
} }
/* List... */ /*------------------------------------------------ Numbered lists ---*/
/* XXX nested lists are broken -- seems that I need a container for the children... */
.editor .outline .numbered-list>.children {
counter-reset: numbered-list;
}
.editor .outline .numbered-list>.children>.block>.view:not(:empty):before { .editor .outline .numbered-list>.children>.block>.view:not(:empty):before {
counter-increment: numbered-list; counter-increment: numbered-list;
content: counter(numbered-list) "."; content: counter(numbered-list) ".";
color: gray; color: gray;
} }
/* numbered lists... */
.editor .outline .editor .outline
.numbered-list>.children .numbered-list>.children
>.numbered-list>.children>.block>.view:not(:empty):before { >.numbered-list>.children>.block>.view:not(:empty):before {
@ -361,7 +363,8 @@ editor .outline .block:focus {
} }
/* Notes... */ /*--------------------------------------------------------- Notes ---*/
.editor .outline .NOTE { .editor .outline .NOTE {
--margin: 1rem; --margin: 1rem;
--padding-h: 2rem; --padding-h: 2rem;
@ -376,9 +379,11 @@ editor .outline .block:focus {
.editor .outline .NOTE>.view:empty { .editor .outline .NOTE>.view:empty {
display: none; display: none;
} }
.editor .outline .NOTE>.view:empty ~ .block { .editor .outline .NOTE:focus>.view:empty {
/* XXX calculate this... */ display: block;
margin-left: 1em; }
.editor .outline .NOTE>.view:empty ~ .children {
margin-left: -1rem;
} }
.editor .outline .NOTE>.view:before { .editor .outline .NOTE>.view:before {
content: "" !important; content: "" !important;
@ -391,7 +396,8 @@ editor .outline .block:focus {
} }
/* Highlightes... */ /*--------------------------------------------------- Highlightes ---*/
.editor .outline .highlight { .editor .outline .highlight {
font-weight: bold; font-weight: bold;
background: yellow; background: yellow;
@ -401,7 +407,8 @@ editor .outline .block:focus {
} }
/* Comments... */ /*------------------------------------------------------ Comments ---*/
.editor.hide-comments .outline .comment { .editor.hide-comments .outline .comment {
display: none; display: none;
} }
@ -410,7 +417,8 @@ editor .outline .block:focus {
} }
/* Checkboxes... */ /*---------------------------------------------------- Checkboxes ---*/
.editor .outline .block.todo>.view { .editor .outline .block.todo>.view {
width: calc( width: calc(
100% 100%
@ -447,16 +455,25 @@ editor .outline .block:focus {
} }
/* code... */ /*---------------------------------------------------------- Code ---*/
.editor .outline .block>.view code {
.editor .outline .block>.view pre,
.editor .outline .block>.view>code,
.editor .outline .block>.view :not(pre)>code {
padding: 0.1em 0.3em; padding: 0.1em 0.3em;
font-family: monospace; font-family: monospace;
background: rgba(0,0,0,0.07); background: rgba(0,0,0,0.07);
border-radius: 0.2em; border-radius: 0.2em;
} }
.editor .outline .block>.view pre>code {
display: block;
padding: 0.6em 0.6em;
padding-bottom: 0.8em;
}
/* Tables... */ /*-------------------------------------------------------- Tables ---*/
.editor .outline .block>.view>table { .editor .outline .block>.view>table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;

View File

@ -316,6 +316,8 @@ var Outline = {
if(code.trim() == ''){ if(code.trim() == ''){
elem.text = '' elem.text = ''
return elem } return elem }
// helpers...
var style = function(style, code=undefined){ var style = function(style, code=undefined){
style = [style].flat() style = [style].flat()
that.__styles = [...new Set([ that.__styles = [...new Set([
@ -327,16 +329,29 @@ var Outline = {
elem.style.push(...style) elem.style.push(...style)
return code return code
?? text } } ?? text } }
var quoteText = function(text){
return text
.replace(/(?<!\\)&/g, '&amp;')
.replace(/(?<!\\)</g, '&lt;')
.replace(/(?<!\\)>/g, '&gt;')
.replace(/\\(?!`)/g, '\\\\') }
var quote = function(_, code){
return `<code>${quoteText(code)}</code>` }
var pre = function(_, language, code){
language = language ?
'language-'+language
: language
return `<pre><code class="${language}">${ quoteText(code) }</code></pre>` }
var table = function(_, body){ var table = function(_, body){
return `<table><tr><td>${ return `<table><tr><td>${
body body
.replace(/\s*\|\s*\n\s*\|\s*/gm, '</td></tr>\n<tr><td>') .replace(/\s*\|\s*\n\s*\|\s*/gm, '</td></tr>\n<tr><td>')
.replace(/\s*\|\s*/gm, '</td><td>') .replace(/\s*\|\s*/gm, '</td><td>')
}</td></td></table>` } }</td></td></table>` }
elem.text = code elem.text = code
// hidden attributes... // hidden attributes...
// XXX make this generic... // XXX make this generic...
// XXX should these be hidden from code too???
// collapsed... // collapsed...
.replace(/(\n|^)\s*collapsed::\s*(.*)\s*(\n|$)/, .replace(/(\n|^)\s*collapsed::\s*(.*)\s*(\n|$)/,
function(_, value){ function(_, value){
@ -388,7 +403,9 @@ var Outline = {
.replace(/(?<!\\)\*(?=[^\s*])(([^*]|\\\*)*[^\s*])(?<!\\)\*/gm, '<b>$1</b>') .replace(/(?<!\\)\*(?=[^\s*])(([^*]|\\\*)*[^\s*])(?<!\\)\*/gm, '<b>$1</b>')
.replace(/(?<!\\)~(?=[^\s~])(([^~]|\\~)*[^\s~])(?<!\\)~/gm, '<s>$1</s>') .replace(/(?<!\\)~(?=[^\s~])(([^~]|\\~)*[^\s~])(?<!\\)~/gm, '<s>$1</s>')
.replace(/(?<!\\)_(?=[^\s_])(([^_]|\\_)*[^\s_])(?<!\\)_/gm, '<i>$1</i>') .replace(/(?<!\\)_(?=[^\s_])(([^_]|\\_)*[^\s_])(?<!\\)_/gm, '<i>$1</i>')
.replace(/(?<!\\)`(?=[^\s])(([^`]|\\`)*[^\s])(?<!\\)`/gm, '<code>$1</code>') // code/quoting...
.replace(/(?<!\\)```(.*)\s*\n((\n|.)*)\h*(?<!\\)```\s*/g, pre)
.replace(/(?<!\\)`(?=[^\s])(([^`]|\\`)*[^\s])(?<!\\)`/gm, quote)
// XXX support "\==" in mark... // XXX support "\==" in mark...
.replace(/(?<!\\)==(?=[^\s])(.*[^\s])(?<!\\)==/gm, '<mark>$1</mark>') .replace(/(?<!\\)==(?=[^\s])(.*[^\s])(?<!\\)==/gm, '<mark>$1</mark>')
// links... // links...
@ -571,7 +588,9 @@ var Outline = {
&& (code.innerHTML = this.text()) && (code.innerHTML = this.text())
return this }, return this },
// XXX move the code here into methods/actions...
// XXX add scrollIntoView(..) to nav... // XXX add scrollIntoView(..) to nav...
// XXX use keyboard.js...
keyboard: { keyboard: {
// vertical navigation... // vertical navigation...
// XXX this is a bit hacky but it works -- the caret blinks at // XXX this is a bit hacky but it works -- the caret blinks at
@ -806,7 +825,11 @@ var Outline = {
if(node.nodeName == 'TEXTAREA' if(node.nodeName == 'TEXTAREA'
&& node?.nextElementSibling?.nodeName == 'SPAN'){ && node?.nextElementSibling?.nodeName == 'SPAN'){
var block = node.parentElement var block = node.parentElement
that.update(block, { text: node.value }) } }) that.update(block, { text: node.value }) }
// XXX do a plugin...
window.hljs
&& hljs.highlightAll() })
// update .code... // update .code...
var update_code_timeout var update_code_timeout
outline.addEventListener('change', outline.addEventListener('change',

View File

@ -2,7 +2,10 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link href="editor.css" rel="stylesheet"/> <link rel="stylesheet" href="css/default.css">
<link rel="stylesheet" href="editor.css"/>
<style> <style>
.add-row { .add-row {
@ -10,6 +13,9 @@
} }
</style> </style>
<script src="lib/highlight.min.js"></script>
<script src="generic.js"></script> <script src="generic.js"></script>
<script src="editor.js"></script> <script src="editor.js"></script>
<script> <script>
@ -20,7 +26,11 @@ var setup = function(){
window.editor = { window.editor = {
__proto__: Outline, __proto__: Outline,
}.setup( }.setup(
document.querySelector('.editor')) } document.querySelector('.editor'))
// XXX make this a plugin...
window.hljs
&& hljs.highlightAll() }
</script> </script>
</head> </head>
@ -35,17 +45,22 @@ var setup = function(){
- Tomboy - Tomboy
- Bonsai - Bonsai
- -
- ## ToDo: - ## Bugs:
- BUG: ASAP: editor: `-` at start of line is interpreted as block marker...
- need to either:
- quote the `-` in .text() -- _preferreed_
- split the lines starting with `-` into nested nodes (a-la .load())
- BUG? pressing down from a longer line will jump over a shorter line - BUG? pressing down from a longer line will jump over a shorter line
- here is the line to jump from, for example from here - to reproduce\:
an we'll not get here... - here is the line to jump from, for example from here
- ASAP: fix quotes an we'll not get here...
- Example: /\n\s*\|\s+/ -&gt; &lt;tr&gt;&lt;td&gt; -
- ## ToDo:
- ASAP: editor: bksapce/del at start/end of a block should join it with prev/next - ASAP: editor: bksapce/del at start/end of a block should join it with prev/next
- ASAP: editor: pressing enter in text edit mode should split text into two blocks - ASAP: editor: pressing enter in text edit mode should split text into two blocks
- ASAP: editor: shifting nodes up/down - ASAP: editor: shifting nodes up/down
- ASAP: editor: `-` at start of line is interpreted as block marker...
- ASAP: use \\t for indent... - ASAP: use \\t for indent...
- ASAP: scroll into view is bad...
- on item click, place the cursor where it was clicked before the code expanded... - on item click, place the cursor where it was clicked before the code expanded...
- ~editor: semi-live update styles~ - ~editor: semi-live update styles~
- need to reach checkboxes via keyboard - need to reach checkboxes via keyboard
@ -54,7 +69,7 @@ var setup = function(){
- _...use `[%]`, `%%`, or something similar..._ - _...use `[%]`, `%%`, or something similar..._
- read-only mode - read-only mode
- should bulets be on the same level as nodes or offset?? - should bulets be on the same level as nodes or offset??
- A) justified to bulet: - A) justified to bullet:
* list item * list item
* list item * list item
block text block text
@ -63,6 +78,8 @@ var setup = function(){
* list item * list item
block text block text
- NOTE: this is only a problem if making list-items manually -- disable??? - NOTE: this is only a problem if making list-items manually -- disable???
- FF: figure out a way to draw expand/collapse bullets without the use of CSS' `:has(..)`
- Nerd fonts (options?)
- ~do a better expand/collapse icons~ - ~do a better expand/collapse icons~
- ~loading from DOM -- fill textarea~ - ~loading from DOM -- fill textarea~
- ~focus management~ - ~focus management~
@ -80,10 +97,6 @@ var setup = function(){
- indent/deindent - indent/deindent
- edit node - edit node
- empty item height is a bit off... - empty item height is a bit off...
- ~handle links gracefully -- open/edit
_just click in the empty space_~
- ~<a href="about:blank">this takes the whole element</a>~
- this breaks if link is exactly line width -- should we ensure empty space?
- ~serialize/deserialize~ - ~serialize/deserialize~
- ~add optional text styling to nodes~ - ~add optional text styling to nodes~
- -
@ -125,7 +138,7 @@ var setup = function(){
- y - y
- z - z
- c - c
- &gt; quoted text - > quote
- Notes - Notes
- NOTE: a note text - NOTE: a note text
- NOTE: - NOTE:
@ -136,33 +149,37 @@ var setup = function(){
- XXX Highlight - XXX Highlight
- Basic inline *bold*, _italic_ and ~striked~ - Basic inline *bold*, _italic_ and ~striked~
- Marking ==text== - Marking ==text==
- Code
- Inline quoting `html <b>code</b>`
- code blocks
```javascript
var text = 'Hello, world!'
console.log(text)
```
- Line - Line
- --- - ---
- Markers: ASAP, BUG, FIX, HACK, STUB, WARNING, and CAUTION - Markers: ASAP, BUG, FIX, HACK, STUB, WARNING, and CAUTION
- Inline [X] checkboxes [_] - Basic task management
- To do items/blocks - Inline [X] checkboxes [_]
- [_] undone item - To do items/blocks
_(clicking the checkbox updates the item)_ - [_] undone item
- [X] done item _(clicking the checkbox updates the item)_
- [_] we can also add inline [x] checkboxes - [X] done item
- link - [_] we can also add inline [x] checkboxes
- links
- [example](about:blank) - [example](about:blank)
- https://example.com - https://example.com
- ./path/to/file /path/to -- not supported yet - ./path/to/file /path/to -- _not supported yet_
- Tables - Tables
- | a | b | c | - | a | b | c |
| 1 | 2 | 3 | | 1 | 2 | 3 |
| 11 | 22 | 33 | | 11 | 22 | 33 |
- Symbols -- should these be ligatures? - Symbols -- _should these be ligatures?_
- (i), (c), /!\, ... - (i), (c), /!\, ...
- -- and --- - -- and ---
- markdown: -
- numbered lists - ---
- ~tables~
- code blocks
- ~alerts~
- footnotes??
-
- ### Playground for testing - ### Playground for testing
- A - A
collapsed:: true collapsed:: true