"Convert to Markdown" Script

Hi

I installed the “Convert To Markdown” script from the “more scripts” option because I thought it would be really handy.

If I have a number of lines of text in a note ike this:

Dog.
Cat.
Rabbit.
Snake.
Rhino.
Elephant.

I would like to be able to convert it easily to this, without having to redo the list:

  1. Dog.
  2. Cat.
  3. Rabbit.
  4. Snake.
  5. Rhino.
  6. Elephant.

I’m not bothered about it being indented.

If I select the lines of text in DT and apply the script to convert to a numbered list I get a list as in this image:

If I choose bulleted list from the options it’s fine, as is a To-Do list if I select that but converting to a numbered list I just can’t get to work.

Any suggestions?

Thank you,

Q

Summary

This text will be hidden

There is nothing wrong with that numbered list. The numbers in the Markdown source don’t matter. The rendering converts to the expected numbering. Also, the approach of using one number while editing makes it simpler to rearrange elements. You don’t have the compulsion to stop and manually renumber anything.

2 Likes

The script is named “Convert to Markdown List:wink:

BLUEFROG beat me to it – the syntax is perfectly valid.

But you could check out Brett Terpstra’s Markdown Service Tools, which includes md - Lists - Numbered List. That does increment numbers in the plain text source. And it also works outside of DEVONthink.

1 Like

And here’s an illustration…

reorder-list

1 Like

All part of the learning process, I guess I’m just not familiar with lists with all the same numbers at the start of each row! :joy:

Thanks for the info, another piece of the DEVONthink jigsaw :+1:

Ok, I’ll bite, if I click the elements in the LH list why do the items move around? :upside_down_face:

Q

I think BLUEFROG used the keyboard shortcut for moving paragraphs up/down. Either Command-Control-Arrow Up/Down or Control-Shift-Arrow Up/Down. (He might have used a mouse click to focus the editor.)

2 Likes

Indeed, Command-Control-Up/Down will shift the current line or paragraph in plain text, Markdown source, and rich text documents.

1 Like

Understood. What I’m seeing is a moving around if I just single click on a word, in either column. :thinking:

A screencast would be helpful.

Does this help at all?

Q

There’s no trickery going on here but this should be clearer…

swaplines

I don’t understand. I’m new to this, maybe just tell me what’s going on? :smiling_face_with_three_hearts:

The screencast shows I am using the arrow keys to navigate up and down the Markdown list then using Control-Command-Up or Down arrows to shift lines in the list.

We’re talking completely past each other :laughing: I thought you were referring to behaviour in DEVONthink, not your web browser.

You’re not clicking any words in any column. You are clicking on a GIF in your browser. It doesn’t matter where you click it – in terms of user interaction all of it is the same object.

BLUEFROG shared an animated GIF. An animated GIF can either be encoded to play once, to loop forever, or to loop a certain number of times. It looks like this one is encoded to play once. After it’s done playing, clicking the GIF doesn’t play it again, even though Discourse shows me a play button. Instead it just jumps between the first and last frame.

To play it again, you need to reload the page. You could also right-click and download the GIF or open it in a new tab/window.

I think I’d better shut up and not waste any more of anyone’s time with this. I’ll just accept that if I see a list in a raw file with the number one at the start of each line that it’s just fine and will appear as it should when I preview or export it.

Thanks for the help with this which I’m just going to put down to my ignorance :upside_down_face:

If a student in my Python class turned in an assignment to “convert to numbered list”, but all the numbers were “1.”, that student would not get full points.

This is about utilizing the native rendering of Markdown in a simple and efficient manner. There is no requirement to use consecutive numbers in the Markdown source as the CSS handles the actual rendering. Also, if things are consecutively numbered in the source and someone wants to shift items up and down in the list, they feel compelled to also change the numbering. That’s merely psychological and not required for rendering. So this approach gives the user the freedom to arbitrarily shift line items, knowing the finished result will retain proper numbering.

If I gave this assignment, generate a Markdown document showing an ordered list – via Python, JavaScript, AppleScript, whatever – I would give extra credit to anyone who came up with this simple and elegant approach as it shows they can think around corners. :slight_smile:

Examples…

Any of the line items in the list can be easily shifted to a new position and the numbering is automatically updated. No need for the Markdown to conform to the rendered view. Concentrate on content and position of the line item and you get the numbering for free.

4 Likes

Ok, happy to show my ignorance, again :blush:

In the LH columns are you just indenting lines 2,3,4 - 6,7,8 with a tab?

I also can’t work out how the LH columns are all the same but the RH columns render differently.

This is a bit like the three cups trick.

Q

Maybe you should take a step back and familiarize yourself with Markdown’s syntax and function.
The “left hand” in the image is the edit view. The right hand view is the preview, ie HTML rendered from the Markdown text using the CSS that’s either predefined by DT or provided by the user.
To get sub-lists, you indent by two or more spaces in the editing process. What you get in preview is, again, determined by tge CSS. There’s no obligation to have any indentation in the rendered HTML at all. Butt if you have it, it has nothing to do with tabs.

3 Likes

No no, it’s all good. But I can’t tell for sure if the miscommunication was cleared up?


As chrillek says, maybe you should read up on markdown a bit. It was originally created as an easier way to write HTML.

The preview pane shows the markdown as rendered HTML. How a HTML document is rendered is determined by a style sheet (CSS).

A “numbered list” produces the HTML element <ol>, ordered list. An ordered list has a counter that is automatically incremented by each list item. The list marker is usually styled as a number corresponding to the counter, but it can be styled in many different ways.

Markdown was created by John Gruber. His webpage about it is a good place to start:

3 Likes