Markdown Numbered List


#1

Hey guys,
I wanted to duplicate and change this standard List Action http://actions.getdrafts.com/a/1Cf from the directory to be able to toggle numbered Lists.
I set the listMark correctly and tried to adapt the expression to find out if the script should add or remove the mark, but I did not get this part to work (I’m really no js expert :D).
Can someone tell me how to toggle the mark "1. " within this action or maybe post an action to the directory which does the same thing?


#2

Something like this ?

http://actions.getdrafts.com/a/1KG


#3

( Updated now for a wider button and slightly better selection handling )

http://actions.getdrafts.com/a/1KG


#4

More or less thank you, would be the best if it won’t select the lines and just use the current line to toggle the „1.“ because it does not matter for markdown which number is in front of the point;)


#5

If I am understanding, you mean that you would like it to act on one line at a time ?


#6

( I’ve updated the behaviour for single-line selections – the selection now collapses to the end of the line in these cases )

http://actions.getdrafts.com/a/1KG


#7

A Little Bit Strange If it’s the first line and sometimes if it’s the last line with text and afterwards a line without text it’s inserting a „\n“ if it’s the first line or adds a „2.“ to the last line
Thank you very much!


#8

Thanks ! Could you give me, fenced between 3 back-ticks above and below (to avoid forum formatting side-effects),

```txt

a sample text and{^} cursor position

```

which seems to consistently reproduce the problem ?

(Using a {^} mark to show where the cursor is, or two of them if the selection is extended)


#9

example 1:


my sample text{^}

result when running the action at cursor position:


1. my sample text
2. {^}

& all the text is selected

example 2:

my second sample text{^}

result:


1. my second sample text{^}

#10

Perfect – thank you.

I’ve made an adjustment to the editor.setText argument here:

http://actions.getdrafts.com/a/1KG

(Let me know if that hasn’t quite fixed it yet)


#11

Thank you @draft8 awesome work!