require 'rexml/document'
require 'digest'
K='주주총회결의취소의소'; W="tmp/규칙문서재작성_#{K}_20260913_batch5"
S="사건종류_#{K}/청구취지작성규칙_#{K}_v2.md"; F='1. 베타 0.5 다듬기/output_format_v1.txt'
s=File.read(S); d=File.read("#{W}/draft.md"); dl=d.lines
def norm(x);x.gsub(/[`*]/,'').gsub(/^\s*(?:- \[ \]|- |\d+\. )/,'').strip;end
def esc(x);x.gsub('|','\\|').gsub("\n",'
');end
puts '*** Begin Patch'
def patch(path,str); puts "*** Add File: #{path}\n"+str.lines.map{|l|'+'+l}.join;end
units=[];formats=[];sid='title';heading='';format_lines=[];unmatched=[]
s.lines.each_with_index do |line,idx|
text=line.strip
if text.empty? || text.start_with?('```') || text.match?(/\A[-|: ]+\z/)
format_lines<