@@ -240,36 +240,50 @@ jobs:
240240 BARE_URL = re.compile(r'^(https?://\S+)$')
241241
242242 def convert_hint_blocks(s: str) -> str:
243- def _repl(m):
244- inner = m.group(1).strip()
245-
246- # Collect non-empty lines as-is
247- raw_lines = [ln.strip() for ln in inner.splitlines() if ln.strip()]
248-
249- # Detect **Tip** / **Note** / **Important** (case-insensitive, optional colon)
250- cls_suffix = ""
251- if raw_lines:
252- mlabel = re.match(r'^\*\*(Tip|Note|Important)\*\*:?\s*$', raw_lines[0], re.I)
253- if mlabel:
254- cls_suffix = " " + mlabel.group(1).lower() # -> " tip" | " note" | " important"
255-
256- # Preserve existing behavior for links/URLs and paragraphization
257- paras = []
258- for line in raw_lines:
259- line = MD_LINK.sub(r'<a href="\2">\1</a>', line)
260- bu = BARE_URL.match(line)
261- if bu:
262- u = bu.group(1)
263- line = f'<a href="{u}">{u}</a>'
264- paras.append(f"<p>{line}</p>")
265-
266- content = "\n".join(paras) if paras else "<p></p>"
267- return f'<blockquote class="wp-block-quote{cls_suffix}">\n{content}\n</blockquote>'
268-
269- return HINT_BLOCK.sub(_repl, s)
270-
271-
272- html_img = re.compile(
243+ def _repl(m):
244+ inner = m.group(1).strip()
245+
246+ # Keep only non-empty lines (no empty <p>)
247+ raw_lines = [ln.strip() for ln in inner.splitlines() if ln.strip()]
248+
249+ # Detect label in first paragraph (optional trailing colon)
250+ cls = ""
251+ if raw_lines:
252+ mlabel = re.match(r'^\*\*(Tip|Note|Important)\*\*:?\s*$', raw_lines[0], re.I)
253+ if mlabel:
254+ cls = mlabel.group(1).lower() # "tip" | "note" | "important"
255+
256+ # Convert links and bare URLs in each paragraph (same as before)
257+ paras = []
258+ for line in raw_lines:
259+ line = MD_LINK.sub(r'<a href="\2">\1</a>', line)
260+ bu = BARE_URL.match(line)
261+ if bu:
262+ u = bu.group(1)
263+ line = f'<a href="{u}">{u}</a>'
264+ paras.append(f"<p>{line}</p>")
265+
266+ content = "\n".join(paras) if paras else "<p></p>"
267+
268+ # Use Gutenberg block serialization so WP keeps the custom class
269+ if cls:
270+ return (
271+ f'<!-- wp:quote {{"className":"{cls}"}} -->\n'
272+ f'<blockquote class="wp-block-quote {cls}">\n{content}\n</blockquote>\n'
273+ f'<!-- /wp:quote -->'
274+ )
275+ else:
276+ return (
277+ f'<!-- wp:quote -->\n'
278+ f'<blockquote class="wp-block-quote">\n{content}\n</blockquote>\n'
279+ f'<!-- /wp:quote -->'
280+ )
281+
282+ return HINT_BLOCK.sub(_repl, s)
283+
284+
285+
286+ html_img = re.compile(
273287 r'<img\b[^>]*\bsrc=["\']([^"\']+)["\'][^>]*?(?:\balt=["\']([^"\']*)["\'])?[^>]*>',
274288 re.I
275289 )
0 commit comments