import re
with open('src/main/resources/templates/dao-tao-detail.html', 'r', encoding='utf-8') as f:
content = f.read()
# 1. Remove hardcoded tabs
old_html = """
"""
new_html = """
"""
content = content.replace(old_html, new_html)
# 2. Add handler
handler = """ case "trainingCourseInfo":
var d = block.data;
var introHtml = d.introText ? d.introText.split('\\n').filter(function(p){return p.trim()!==''}).map(function(p){return ''+p+'
'}).join('') : '';
var hoSoHtml = d.documents ? d.documents.split('\\n').filter(function(p){return p.trim()!==''}).map(function(p){return ''+p+''}).join('') : '';
if(hoSoHtml) hoSoHtml = '';
var luuYHtml = d.notes ? d.notes.split('\\n').filter(function(p){return p.trim()!==''}).map(function(p){return ''+p+''}).join('') : '';
if(luuYHtml) luuYHtml = '';
var locationHtml = d.location ? d.location.split('\\n').filter(function(p){return p.trim()!==''}).map(function(p){return ''+p+'
'}).join('') : '';
html += '';
html += '
';
html += '
';
html += ' ';
html += ' ';
html += '
';
html += '
';
html += '
';
if(introHtml) html += introHtml;
if(d.bannerText) {
html += '
' + d.bannerText + '
';
}
html += '
';
html += '';
if(d.time) html += '| Thời gian: | ' + d.time.replace(/\\n/g, ' ') + ' |
';
if(d.audience) html += '| Đối tượng đăng ký: | ' + d.audience.replace(/\\n/g, ' ') + ' |
';
var thongTinLopHoc = '';
if(d.fileChieuSinh) thongTinLopHoc += 'Thông báo chiêu sinh file đính kèm';
if(d.filePhieuDangKy) thongTinLopHoc += (thongTinLopHoc?' và ':'') + 'phiếu đăng ký file đính kèm';
if(thongTinLopHoc) html += '| Thông tin lớp học | ' + thongTinLopHoc + ' |
';
if(d.quantity) html += '| Số lượng: | ' + d.quantity + ' |
';
if(hoSoHtml) html += '| Hồ sơ đăng ký tham dự: | ' + hoSoHtml + ' |
';
if(luuYHtml) html += '| Lưu ý: | ' + luuYHtml + ' |
';
html += '
';
html += '
';
html += '
';
html += '
';
html += '';
if(d.tuitionFee) html += '| Học phí: | ' + d.tuitionFee + ' |
';
if(locationHtml) html += '| Địa điểm nhận hồ sơ và học phí: | ' + locationHtml + ' |
';
var bankHtml = '';
if(d.bankAccountName) bankHtml += 'Tên tài khoản: ' + d.bankAccountName + '';
if(d.bankAccountNumber) bankHtml += 'Số tài khoản: ' + d.bankAccountNumber + '';
if(d.bankName) bankHtml += 'Tên ngân hàng: ' + d.bankName + '';
if(d.transferContent) bankHtml += 'Nội dung: ' + d.transferContent + '';
if(bankHtml) {
html += '| Hình thức nộp học phí: | |
';
html += '| Chuyển khoản: |
';
}
html += '
';
html += '
';
html += '
';
break;
case "raw":"""
content = content.replace('case "raw":', handler)
# 3. Replace complex parseEditorContent tab split logic
regex_pattern = r"var isJsonSplit = false;.*?if \(!isJsonSplit\) \{.*?if \(contentText\.indexOf\(''\) !== -1\) \{.*?\} else \{.*?parseEditorContent\(contentText, 'postContentParsed'\);.*?parseEditorContent\(excerptText, 'postGeneralInfoParsed'\);.*?\}.*?\}"
content = re.sub(regex_pattern, "parseEditorContent(contentText, 'postContentParsed');", content, flags=re.DOTALL)
# 4. Add switchTrainingTab script
script = """
"""
if 'function switchTrainingTab' not in content:
content = content.replace('