- Add\Rework UI - Add Split Table and Listing - Add Support Customazeble schems
This commit is contained in:
@@ -4,23 +4,38 @@ from re import Match, compile as re_compile
|
||||
|
||||
|
||||
_LISTING_FLAG_RE = re_compile(r"(?i)(?:^|\s)\+?listing\b")
|
||||
_LANDSCAPE_FLAG_RE = re_compile(r"(?i)(?:^|\s)\+?landscape\b")
|
||||
|
||||
|
||||
def strip_caption_flags(raw: str) -> tuple[str | None, bool, bool]:
|
||||
"""Return (clean_text, with_listing, landscape) from caption / image-title tail."""
|
||||
text = (raw or "").strip()
|
||||
with_listing = bool(_LISTING_FLAG_RE.search(text))
|
||||
landscape = bool(_LANDSCAPE_FLAG_RE.search(text))
|
||||
if with_listing:
|
||||
text = _LISTING_FLAG_RE.sub(" ", text)
|
||||
if landscape:
|
||||
text = _LANDSCAPE_FLAG_RE.sub(" ", text)
|
||||
text = " ".join(text.split()).strip()
|
||||
return (text or None), with_listing, landscape
|
||||
|
||||
|
||||
class Caption(BlockElement):
|
||||
"""Represents caption element
|
||||
|
||||
Syntax: %label Caption text [+listing]
|
||||
Syntax: %label Caption text [+listing] [+landscape]
|
||||
"""
|
||||
|
||||
# Interrupt an open paragraph so «текст:\\n%id …» still becomes a Caption
|
||||
# (otherwise marko treats the % line as paragraph continuation / plain text).
|
||||
breaks_paragraph = True
|
||||
priority = 6
|
||||
pattern = r"\%(\w+)( (.+))?"
|
||||
|
||||
def __init__(self, match: Match[str]):
|
||||
self.unique_name = match.group(1)
|
||||
raw = (match.group(3) or "").strip()
|
||||
self.with_listing = bool(_LISTING_FLAG_RE.search(raw))
|
||||
if self.with_listing:
|
||||
raw = _LISTING_FLAG_RE.sub(" ", raw).strip()
|
||||
self.text = raw or None
|
||||
self.text, self.with_listing, self.landscape = strip_caption_flags(raw)
|
||||
|
||||
@classmethod
|
||||
def match(cls, source: Source) -> Match[str] | None:
|
||||
|
||||
@@ -2,6 +2,8 @@ import re
|
||||
|
||||
from marko.inline import Image as Image_
|
||||
|
||||
from .caption import strip_caption_flags
|
||||
|
||||
|
||||
class Image(Image_):
|
||||
override = True
|
||||
@@ -9,7 +11,11 @@ class Image(Image_):
|
||||
super().__init__(match)
|
||||
|
||||
self.unique_name = None
|
||||
self.with_listing = False
|
||||
self.landscape = False
|
||||
|
||||
if self.title and (m := re.match(r"\%(\w+)( (.+))?", self.title)):
|
||||
self.unique_name = m.group(1)
|
||||
self.title = (m.group(3) or "").strip() or None
|
||||
self.title, self.with_listing, self.landscape = strip_caption_flags(
|
||||
(m.group(3) or "").strip()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user