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 += ''; if(d.audience) html += ''; 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 += ''; if(d.quantity) html += ''; if(hoSoHtml) html += ''; if(luuYHtml) html += ''; html += '
    Thời gian:' + d.time.replace(/\\n/g, '
    ') + '
    Đối tượng đăng ký:' + d.audience.replace(/\\n/g, '
    ') + '
    Thông tin lớp học

    ' + thongTinLopHoc + '

    Số lượng:' + d.quantity + '
    Hồ sơ đăng ký tham dự:' + hoSoHtml + '
    Lưu ý:' + luuYHtml + '
    '; html += '
    '; html += '
    '; html += '
    '; html += ''; if(d.tuitionFee) html += ''; if(locationHtml) html += ''; 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 += ''; html += ''; } html += '
    Học phí:' + d.tuitionFee + '
    Địa điểm nhận hồ sơ và học phí:' + locationHtml + '
    Hình thức nộp học phí: 
    Chuyển khoản:
      ' + bankHtml + '
    '; 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('', script + '\n ') with open('src/main/resources/templates/dao-tao-detail.html', 'w', encoding='utf-8') as f: f.write(content)