Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Format Code With Line Numbers In Markdown Notation

DZone's Guide to

Format Code With Line Numbers In Markdown Notation

·
Free Resource

C:\>type Format.groovy | groovy Format
     1: def counter = 1
     2:
     3: System.in.eachLine {
     4:         line ->
     5:
     6:         def result = "    "
     7:         (2 - ("" + counter).length()).times { result += " " }
     8:         result += "${counter}: ${line}"
     9:         println result
    10:         counter++
    11: }

C:\>



def counter = 1

System.in.eachLine {
	line ->
	
	def result = "    "
	(2 - ("" + counter).length()).times { result += " " }
	result += "${counter}: ${line}"
	println result
	counter++
}
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}