Convert space indented text to markdown minus indented
Posted by jpluimers on 2018/01/17
Since I will never be good at regex, this are a few search/replace patterns I used in Atom.io to convert a plain text document space indented like this:
Version 1.23.4.15
First level indented text
Is also a first level indented text
Too a first level indented text
- First level indented text too
Second level indented text
Is also a second level indented text
Too a second level indented text
- Second level indented text too
- A third level indented text
Third level indented text
Is also a third level indented text
Too a third level indented text
98.4.32.1
to a Markdown indented one like this:
Version 1.23.4.15 - First level indented text - Is also a first level indented text - Too a first level indented text - First level indented text too - Second level indented text - Is also a second level indented text - Too a second level indented text - Second level indented text too - A third level indented text - Third level indented text - Is also a third level indented text - Too a third level indented text Version 98.4.32.1
Prepend Version when needed: https://regex101.com/r/CUhUbr/1
- Search:
^(\d+\.\d+\.\d+\.\d+)
- Replace:
Version $1
Add markdown first level indentations to lines that don’t have a markdown first level indentation yet, nor start with Version nor start with a space: https://regex101.com/r/CUhUbr/2
- Search:
^(?!(Version )|(- )|( )|(\d+\.\d+\.\d+\.\d+))(.*)
- Replace:
- $5
Add markdown second level indentations to lines that don’t have a markdown second level indentation yet but do have a regular second level indentation: https://regex101.com/r/CUhUbr/3
- Search:
^ (?!(- )|( ))(.*)
- Replace:
- $3
Add markdown third level indentations to lines that don’t have a markdown third level indentation yet but do have a regular third level indentation: https://regex101.com/r/CUhUbr/4
- Search:
^ (?!(- )|( ))(.*)
- Replace:
- $3
https://regex101.com/r/CUhUbr/1
https://regex101.com/r/CUhUbr/2
https://regex101.com/r/CUhUbr/3
https://regex101.com/r/CUhUbr/4






Leave a comment