Fix: Tier 2 numbered list, sub-bullet checkmarks, Relocation Cost page, ISP FINANCING, green NB
Browse filesFiles changed (4)
128 unmodified lines129130131132133134378 unmodified lines513514515516517518128 unmodified lines# ── doc_v1 ──if layout_norm == "doc_v1" and isinstance(section_json.get("blocks"), list):blocks.extend(_normalize_doc_v1(section_json["blocks"], skip_title=title))return blocks# ── Fallback ──378 unmodified lines)def _normalize_doc_v1(blocks: list, *, skip_title: str = "") -> list[RenderBlock]:"""Normalise doc_v1 blocks into typed RenderBlocks.128 unmodified lines129130131132133134135136137138139140378 unmodified lines519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748128 unmodified lines# ── doc_v1 ──if layout_norm == "doc_v1" and isinstance(section_json.get("blocks"), list):blocks.extend(_normalize_doc_v1(section_json["blocks"], skip_title=title))# Post-process breakdown section for Relocation Cost layoutif key_norm == "program_features_breakdown":blocks = _postprocess_breakdown(blocks, section_json["blocks"])# Post-process Tier 2 section for sub-bullet stylingif key_norm == "summary_of_universities_cosigner":blocks = _postprocess_tier2(blocks)return blocks# ── Fallback ──378 unmodified lines)# ───────────────────────────────────────────────────────────────# Breakdown section post-processor# ───────────────────────────────────────────────────────────────def _postprocess_breakdown(blocks: list[RenderBlock],raw_blocks: list,) -> list[RenderBlock]:"""Rewrite the breakdown section to match the reference layout.- "Relocation Cost" becomes a banner heading with page-break-before- The relocation table gets a merged right cell (rowspan) with thecost-coverage note moved inside it- "ISP FINANCING" becomes an inline note with mixed bold/italic- "NB: CREDIT FACILITY" is styled green- Dollar amounts in parentheticals keep their original $ format"""from markupsafe import Markup# Find raw blocks for the relocation cost table (pre-normalised, $ intact)raw_reloc_table = Noneraw_note_after_table = Nonefound_reloc = Falsefor i, rb in enumerate(raw_blocks):if not isinstance(rb, dict):continueif rb.get("type") == "subheading" and "relocation" in str(rb.get("text", "")).lower():found_reloc = Truecontinueif found_reloc and rb.get("type") == "table_v1" and raw_reloc_table is None:raw_reloc_table = rbcontinueif found_reloc and raw_reloc_table and rb.get("type") == "paragraph" and raw_note_after_table is None:raw_note_after_table = rbbreakresult: list[RenderBlock] = []i = 0while i < len(blocks):blk = blocks[i]# ── Detect "Relocation Cost" heading ──if (blk.block_type == "heading_2"and "relocation" in blk.data.get("text", "").lower()):# Banner heading with page breakresult.append(RenderBlock(block_type="heading_2",css_class="hb-heading-2 hb-banner-heading page-break",data={"text": blk.data["text"]},))i += 1# Replace the next table with spanning variant that has merged cellif i < len(blocks) and blocks[i].block_type == "table" and raw_reloc_table:raw_rows = raw_reloc_table.get("rows", [])# Build the note text for the merged right cellnote_text = ""if raw_note_after_table:note_text = str(raw_note_after_table.get("text", ""))spanning_rows = _build_relocation_spanning_rows(raw_rows, note_text)result.append(RenderBlock(block_type="table",css_class="hb-table hb-relocation-table",data={"rows": spanning_rows, "variant": "spanning"},))i += 1 # skip the original table# Skip the paragraph that was moved into the merged cellif (i < len(blocks)and blocks[i].block_type == "paragraph"and note_text):i += 1continue# ── "ISP FINANCING" heading → inline note with mixed formatting ──if (blk.block_type == "heading_2"and "isp financing" in blk.data.get("text", "").lower()):# Next block should be the interest rate paragraphrate_text = ""if i + 1 < len(blocks) and blocks[i + 1].block_type == "paragraph":rate_text = blocks[i + 1].data.get("text", "")result.append(RenderBlock(block_type="note",css_class="hb-note hb-isp-financing",data={"parts": [{"text": "ISP FINANCING", "style": "bold"},{"text": " (" + _extract_rate_italic(rate_text) + "): " if rate_text else "", "style": "italic"},{"text": _extract_rate_amount(rate_text), "style": "bold"},],"inline": True,},))i += 1 # skip the headingif rate_text:i += 1 # skip the paragraphcontinue# ── "NB: CREDIT FACILITY" note → green styling ──if (blk.block_type == "note"and "credit facility" in blk.data.get("text", "").lower()):result.append(RenderBlock(block_type="note",css_class="hb-note hb-credit-note",data=blk.data,))i += 1continueresult.append(blk)i += 1return resultdef _build_relocation_spanning_rows(raw_rows: list, note_text: str,) -> list[list[dict]]:"""Build spanning rows for the relocation cost table.Row 0: normal 2-column (consultation fees | Covered in the contribution)Rows 1-7: left cell per row, right cell merged (rowspan) with italic noteRows 8+: left cell only, empty right"""from markupsafe import Markupif not raw_rows:return []rows: list[list[dict]] = []# Row 0 — has "Covered in the contribution"first = raw_rows[0] if raw_rows else ["", ""]rows.append([{"text": Markup(emphasize_keywords(str(first[0] if len(first) > 0 else ""))), "colspan": 1, "rowspan": 1},{"text": Markup("<em>" + h(str(first[1] if len(first) > 1 else "")) + "</em>"), "colspan": 1, "rowspan": 1},])# Rows 1-7: items with dollar amounts that get the merged right cell# These are the visa/fee/rent/ticket rows (have parenthetical dollar amounts)merged_start = 1merged_end = min(8, len(raw_rows)) # Visa Integrity through Air ticketfor idx in range(merged_start, len(raw_rows)):cell_text = str(raw_rows[idx][0] if len(raw_rows[idx]) > 0 else "")left = {"text": Markup(emphasize_keywords(cell_text)), "colspan": 1, "rowspan": 1}if idx == merged_start and note_text:# First merged row gets the rowspan cellspan_count = merged_end - merged_startnote_html = note_text.replace("\n\n", "<br/><br/>")right = {"text": Markup('<em class="hb-merged-note">' + h(note_html).replace("<br/><br/>", "<br/><br/>") + "</em>"),"colspan": 1,"rowspan": span_count,}rows.append([left, right])elif idx < merged_end:# Subsequent merged rows — no right cell (covered by rowspan)rows.append([left])else:# Remaining rows — empty right cellrows.append([left,{"text": "", "colspan": 1, "rowspan": 1},])return rowsdef _extract_rate_italic(text: str) -> str:"""Extract the italic portion: 'Interest rate of 12% – 15% Market Rate PA'."""# Text is like: "Interest rate of 12% – 15% Market Rate: UP TO USD 10,000"m = re.match(r"(Interest rate.*?(?:Market Rate|PA))", text, re.IGNORECASE)if m:return m.group(1).rstrip(": ")# Fallback: everything before the colonif ":" in text:return text.split(":")[0].strip()return textdef _extract_rate_amount(text: str) -> str:"""Extract the amount portion: 'UP TO USD 10,000'."""m = re.search(r"(UP TO.*)", text, re.IGNORECASE)if m:return m.group(1).strip()if ":" in text:return text.split(":", 1)[1].strip()return ""# ───────────────────────────────────────────────────────────────# Tier 2 (cosigner) section post-processor# ───────────────────────────────────────────────────────────────def _postprocess_tier2(blocks: list[RenderBlock]) -> list[RenderBlock]:"""Style the Tier 2 section to match the reference layout.- Second consecutive bullet_list (sub-bullets under Sources of Funds)gets checkmark styling instead of arrows."""result: list[RenderBlock] = []prev_was_bullet = Falsefor blk in blocks:if blk.block_type == "bullet_list":if prev_was_bullet:# This is the sub-bullet list → use checkmark classresult.append(RenderBlock(block_type="bullet_list",css_class="hb-bullet-list hb-sub-bullets",data=blk.data,))else:result.append(blk)prev_was_bullet = Trueelse:prev_was_bullet = Falseresult.append(blk)return resultdef _normalize_doc_v1(blocks: list, *, skip_title: str = "") -> list[RenderBlock]:"""Normalise doc_v1 blocks into typed RenderBlocks.
214 unmodified lines21521621721821922022112 unmodified lines234235236237238239240847 unmodified lines1088108910901091214 unmodified lines.hb-numbered-list,.ol,ol.hb-numbered-list {list-style: decimal;margin: 0 0 8pt 18pt;padding: 0;font-size: 9pt;12 unmodified lines.hb-numbered-list li::before,.ol li::before,ol.hb-numbered-list li::before {content: none;}/* ------------------------------847 unmodified lines.page-content img {max-width: 100%;height: auto;}214 unmodified lines21521621721821922022112 unmodified lines234235236237238239240241242243244245246247248249250251847 unmodified lines109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173214 unmodified lines.hb-numbered-list,.ol,ol.hb-numbered-list {list-style: decimal !important;margin: 0 0 8pt 18pt;padding: 0;font-size: 9pt;12 unmodified lines.hb-numbered-list li::before,.ol li::before,ol.hb-numbered-list li::before {content: none !important;}/* Sub-bullets — checkmarks, indented under parent bullet */.hb-sub-bullets {margin-left: 32pt !important;}.hb-sub-bullets li::before {content: "\2713" !important;color: #000000;font-size: 9pt;}/* ------------------------------847 unmodified lines.page-content img {max-width: 100%;height: auto;}/* ------------------------------BREAKDOWN — RELOCATION COST------------------------------ *//* Banner heading (teal background bar) */.hb-banner-heading {background-color: #199970;color: #FFFFFF !important;padding: 6pt 10pt;margin: 10pt 0 6pt;font-size: 11pt;font-weight: 700;}/* Page break before Relocation Cost */.sec-breakdown .page-break {page-break-before: always;break-before: page;}/* Relocation cost table — merged note cell */.hb-relocation-table {margin: 0 0 10pt;}.hb-relocation-table td {vertical-align: top;padding: 3pt 6pt;border: 1pt solid #CCCCCC;font-size: 9.5pt;}.hb-merged-note {font-style: italic;font-weight: 400;font-size: 9.5pt;line-height: 1.4;display: block;padding: 4pt 2pt;}/* ISP FINANCING line */.hb-isp-financing {margin: 14pt 0 6pt;padding: 6pt 0;border-top: 1.5pt solid #000000;border-bottom: 1.5pt solid #000000;text-align: center;font-size: 10pt;}.hb-isp-financing strong {font-weight: 700;color: #000000;}.hb-isp-financing em {font-style: italic;color: #199970;font-weight: 700;}/* NB: CREDIT FACILITY — green */.hb-credit-note {text-align: center;color: #199970;font-size: 10pt;font-weight: 700;margin: 6pt 0;}
123456{# Block partial: heading_1 / heading_2 #}{% if block.block_type == 'heading_1' %}<h2 class="hb-heading-1">{{ block.data.text | e }}</h2>{% elif block.block_type == 'heading_2' %}<h3 class="hb-heading-2">{{ block.data.text | e }}</h3>{% endif %}123456{# Block partial: heading_1 / heading_2 #}{% if block.block_type == 'heading_1' %}<h2 class="{{ block.css_class | default('hb-heading-1') }}">{{ block.data.text | e }}</h2>{% elif block.block_type == 'heading_2' %}<h3 class="{{ block.css_class | default('hb-heading-2') }}">{{ block.data.text | e }}</h3>{% endif %}
12345678910111213141516{# Block partial: note (standalone or inline-parts) #}{% if block.data.inline and block.data.parts %}<div class="hb-note">{% for part in block.data.parts %}{% if part.style == 'red_bold' %}<strong class="hb-note-keyword">{{ part.text | e }}</strong>{% else %}{{ part.text | e }}{% endif %}{% endfor %}</div>{% else %}<div class="hb-note">{% set text = block.data.text | default('') %}{# Highlight NOTE / ONLY IF keywords in bold + red; rest stays bold via CSS #}{% if text.upper().startswith('NOTE:') %}1234567891011121314151617181920{# Block partial: note (standalone or inline-parts) #}{% if block.data.inline and block.data.parts %}<div class="{{ block.css_class | default('hb-note') }}">{% for part in block.data.parts %}{% if part.style == 'red_bold' %}<strong class="hb-note-keyword">{{ part.text | e }}</strong>{% elif part.style == 'bold' %}<strong>{{ part.text | e }}</strong>{% elif part.style == 'italic' %}<em>{{ part.text | e }}</em>{% else %}{{ part.text | e }}{% endif %}{% endfor %}</div>{% else %}<div class="{{ block.css_class | default('hb-note') }}">{% set text = block.data.text | default('') %}{# Highlight NOTE / ONLY IF keywords in bold + red; rest stays bold via CSS #}{% if text.upper().startswith('NOTE:') %}
app/services/normalizer.py+230
app/static/css/print.css+84-2
app/templates/partials/blocks/heading.html+2-2
app/templates/partials/blocks/note.html+6-2