# -*- coding: utf-8 -*- require 'pp' require 'yaml' require 'json' require "nb_util/version" require 'cli' module NbUtil module_function def yaml2ipynb(argv0) input_filename = ARGV[1] output_filename = ARGV[2] || input_filename.gsub(/(yml|yaml)$/, 'ipynb') cont = YAML.load(File.read(ARGV[1])) contsinglehash = flatten_hash_from cont #pp contsinglehash contsinglehashneed = contsinglehash.select{|k, v| k.match(/title/) || k.match(/cont/) } pp contsinglehashneed contdiffstring = contsinglehashneed.to_s contdiffstring.gsub!(/=>/,'') str = contsinglehashneed.keys contnum=str.count for i in 0..contnum do ignore = str[i].to_s p ignore contdiffstring.sub!(/#{ignore}/,'') end contdiffstring.gsub!(/:\"\"\"/,'# ') contdiffstring.gsub!(/\[/,'') contdiffstring.gsub!(/\]/,'') contdiffstring.gsub!(/{/,'') contdiffstring.gsub!(/}/,'') contdiffstring.gsub!(/\", :\"\"\"/,'\n') contdiffstring.gsub!(/\"/,'') contdiffstring.gsub!(/,/,'\n') pp contdiffstring #cellのデータ cellsData = <