Skip to content

Commit

Permalink
minor tweaks + added stub toc generator...
Browse files Browse the repository at this point in the history
Signed-off-by: Alex A. Naanou <[email protected]>
  • Loading branch information
flynx committed Nov 8, 2023
1 parent f1288fc commit 5b0967f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 18 deletions.
59 changes: 52 additions & 7 deletions experiments/outline-editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ var getMarkdownOffset = function(markdown, text, i){
// (not implemented) backtracking...
// ...needs thought...
// Q: can we cheat with this? =)
// XXX BUG: clicking right of last line places the caret before the last char...
var getMarkdownOffset = function(markdown, text, i){
i = i ?? text.length
var map = []
Expand Down Expand Up @@ -255,12 +256,12 @@ var blocks = {
return text
// markdown...
// style: headings...
.replace(/^(?<!\\)######\s+(.*)$/m, this.style(editor, elem, 'heading-6'))
.replace(/^(?<!\\)#####\s+(.*)$/m, this.style(editor, elem, 'heading-5'))
.replace(/^(?<!\\)####\s+(.*)$/m, this.style(editor, elem, 'heading-4'))
.replace(/^(?<!\\)###\s+(.*)$/m, this.style(editor, elem, 'heading-3'))
.replace(/^(?<!\\)##\s+(.*)$/m, this.style(editor, elem, 'heading-2'))
.replace(/^(?<!\\)#\s+(.*)$/m, this.style(editor, elem, 'heading-1'))
.replace(/^(?<!\\)######\s+(.*)$/m, this.style(editor, elem, ['heading', 'heading-6']))
.replace(/^(?<!\\)#####\s+(.*)$/m, this.style(editor, elem, ['heading', 'heading-5']))
.replace(/^(?<!\\)####\s+(.*)$/m, this.style(editor, elem, ['heading', 'heading-4']))
.replace(/^(?<!\\)###\s+(.*)$/m, this.style(editor, elem, ['heading', 'heading-3']))
.replace(/^(?<!\\)##\s+(.*)$/m, this.style(editor, elem, ['heading', 'heading-2']))
.replace(/^(?<!\\)#\s+(.*)$/m, this.style(editor, elem, ['heading', 'heading-1']))
// style: list...
//.replace(/^(?<!\\)[-\*]\s+(.*)$/m, style('list-item'))
.replace(/^\s*(.*)(?<!\\):\s*$/m, this.style(editor, elem, 'list'))
Expand Down Expand Up @@ -611,6 +612,47 @@ var tasks = {
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// XXX needs lots more work...
var toc = {
__proto__: plugin,

update: function(editor, elem){
var outline = editor.outline
var tocs = [...outline.querySelectorAll('.toc .view')]
if(tocs.length == 0){
return }
var level = function(node){
var depth = 0
var parent = node
while(parent !== outline
&& parent != null){
if(parent.classList.contains('block')){
depth++ }
parent = parent.parentElement }
return depth }
var headings = [...editor.outline.querySelectorAll('.heading .view')]
.map(function(e){
return `<li>${ e.innerText.split(/\n/)[0] }</li>`
})
var lst = document.createElement('ul')
lst.innerHTML = headings.join('\n')
for(var toc of tocs){
toc.append(lst) } },

__setup__: function(editor){
return this.update(editor) },
__editedcode__: function(evt, editor, elem){
return this.update(editor, elem) },

__parse__: function(text, editor, elem){
return text
.replace(/^\s*TOC\s*$/,
this.style(editor, elem, 'toc', '')) },
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// XXX Hackish...
Expand Down Expand Up @@ -1144,6 +1186,7 @@ var Outline = {
// NOTE: this needs to be before styling to prevent it from
// treating '[_] ... [_]' as italic...
tasks,
//toc,
styling,
// XXX
//attributes,
Expand Down Expand Up @@ -2088,7 +2131,8 @@ var Outline = {
var a = edited.selectionStart
var b = edited.selectionEnd
// position 0: focus empty node above...
if(a == 0){
if(a == 0
&& edited.value.trim() != ''){
this.Block('prev')
this.edit('prev')
// focus new node...
Expand Down Expand Up @@ -2480,6 +2524,7 @@ var Outline = {
setTimeout(function(){
that.focus() }, 0) }
/*/
// XXX this for some reason takes lots of time at this point...
this.focus() }
//*/

Expand Down
26 changes: 15 additions & 11 deletions experiments/outline-editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@
-
- ## Bugs:
focused:: true
- BUG: deleting an element in edit mode breaks code (err)
- click the next line and press `backspace`
-
- BUG: navigation in edit mode broken...
-
- // can't go past this down...
-
- BUG: caret positioning broken
- Example:
- *TODO*::
- text text text
<div>
block element
Expand All @@ -72,30 +75,30 @@
this returns `69` while it should return `5`
_...replacing `\n\n\n` with `\n\n` seems to fix the issue (also works with spaces)_
(BUG also the above line is not italic -- can't reproduce)
- clicking right of the last line places cursor wrong
- _this is a problem with the new version of `getMarkdownOffset(..)`_
- DONE text text text
- DONE text text text
- *DONE*::
collapsed:: true
- text text text
- text text text
text text text
text text text
- DONE M
- M
M can't place cursor before first char
M
- DONE text text text
- text text text
```
text text text
```
text text text
- DONE text text text
- text text text
_text text text_
text text text
- DONE _text text text_
- _text text text_
text text text
- DONE ```
- ```
text text text
```
text text text
- DONE |text|text|text|
- |text|text|text|
|text|text|text|
|text|text|text|
- BUG: parser: code blocks do not ignore single back-quotes...
Expand All @@ -115,6 +118,7 @@
- side margins are a bit too large (account for toolbat to the right)
-
- ## ToDo:
- TOC?
- Q: should we use `HTMLTextAreaElement.autoUpdateSize(..)` or handle it globally in setup???
- _...I'm leaning towards the later..._
- Q: can we place a cursor in a table correctly???
Expand Down

0 comments on commit 5b0967f

Please sign in to comment.