File: to_md.rb

package info (click to toggle)
ruby-mina 0.3.7-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 444 kB
  • sloc: ruby: 1,630; makefile: 31
file content (11 lines) | stat: -rw-r--r-- 412 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env ruby
c = /(?:#|\/\/)/  # Comment prefix
lang = "ruby"     # Default language
blocks = STDIN.read.scan(/(?:^[ \t]*#{c} [^\n]*\n)+/)       # Read contiguous comments
blocks.map! { |s| s.gsub!(/(?:^|\n)+[ \t]*#{c} /, "\n") }   # Strip out prefixes

# Code blocks
md = blocks.join("")
md.gsub!(/((?:^    .*\n+)+)/) { |f| "~~~ #{lang}\n" + f.gsub(/^    /, '').gsub(/\s*$/, '') + "\n~~~\n\n" }

puts md