Create a dotted list from current noet

How could I create a dotted list of the current note, and - of cource - not add an extra “dot” if it is a dotted-item already.

Q) is this a very high level scripting question on how to parse the lines of a draft, or is this more a, does anyone have an action that will do this for me question?

I’m not sure what you mean with high-level scripting question. I’m looking to some code to perform the described action.

judging by your response, you are looking for someone else to provide the code for you rather than it being a question about how to script it; you tagged the question as a scripting question rather than just being general help.

Can you describe more about your “dots”? Do you mean tTaskpaper ("-" ) or Markdown lists ("- ", "* ", "+ ") by any chance? Or is it something else (e.g. “.”, “•”)?

What should happen with blank lines or lines indented by spaces, tabs, or both? Are there any other circumstances where a line should not be dotted - e.g. Prefixed with a hash tag?

The more detail you can provide for what you are looking for, the more likely is is that someone will be able to get what you want.

It is tagged as scripting, as I need a script

when I line is already dotted, the we keep it as it is
when there is no dot, we add
ideally we add a intended level of a dot when there is a tab or space in front. But, in that case I may presume the dot is already there

I’m not familar with other types of dots, as - as far I have seen - the * is the only character to use. So curently that is sufficient

That does not cover the blank line case so I have made an assumption about that.

Presumption is also not required when specifying something.

The asterisk is not really a “dot”, but without the context for what you are ultimately doing, what syntax you are working with, etc. that leaves it wide open as to what you are attempting to do.

Based on my blank line assumption and my interpretation of what you would prefer, I think these two lines of code would do what you want.

draft.content = draft.content.replace(/^(\s*)\* /gm,"$1").replace(/^(\s*)(\S+)/gm, "$1* $2");
draft.update();

e.g.

* foo
	* bar

quz
	qux

becomes

* foo
	* bar

* quz
	* qux

There is a Markdown List example action in the default “Markdown” action group (or install from link).

It does exact that for the selected text, toggling the - prefix on each line.