Skip to content

Instantly share code, notes, and snippets.

@mrk21
Created July 13, 2016 00:00
Show Gist options
  • Select an option

  • Save mrk21/001f13f3f394edd19f21999e9da258c3 to your computer and use it in GitHub Desktop.

Select an option

Save mrk21/001f13f3f394edd19f21999e9da258c3 to your computer and use it in GitHub Desktop.
Make UML diagrams from a PlantUML script embedded in Markdown
require 'pp'
require 'fileutils'
file = ARGV[0]
dirname = File.basename(file,'.*')
FileUtils.mkdir_p dirname
source = File.read(file)
i = 1
source.gsub(/(?<=<!---).+?(?=--->)/m) do |m|
name = "#{dirname}/#{i}.txt"
outpath = nil
code = m.split("\n")[1..-1]
code[0].gsub!(/@startuml\{([^{]+)\}/) do
outname = "#{i}_#{$1}"
outpath = "#{dirname}/#{outname}"
"@startuml{#{outname}}"
end
code = code.join("\n")
code = code.gsub(/\\>/,'>')
old_code = File.read(name) rescue nil
if old_code.nil? || code != old_code then
File.write(name, code)
system "plantuml #{name} && open #{outpath}"
end
i+=1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment