Compare commits

..

No commits in common. "a90d055d3eda626b4a27b4645119cfee9c03c766" and "dda979487f5eb175fd4356f5fbfd0d6641ef40e5" have entirely different histories.

2 changed files with 13 additions and 22 deletions

View File

@ -218,7 +218,7 @@ def _fillin_reference_names(input_string: str, item_index: dict[str, int]) -> st
for start, end, ref in replacements:
assert ref in item_index, f"Reference {ref} does not exist in the document"
ret.append(input_string[current_pos:start - 1])
ret.append(f'<a href="#pyld-ref-{latex.normalize_label_text(ref)}">{item_index[ref]}</a>')
ret.append(str(item_index[ref]))
current_pos = end
return ''.join(ret) + input_string[current_pos:]
@ -349,14 +349,14 @@ class DocumentWriter():
return inline_pattern.sub(inline_repl, result)
def _get_equation_html(self, latex_equation: str, caption: str, full_ref_str: str, block: bool = False) -> str:
def _get_equation_html(self, latex_equation: str, caption: str, block: bool = False) -> str:
fig = latex_to_figure(latex_equation)
if block:
fig_str = figure_to_string(fig, self._figure_format, base64=self._base64_svgs)
ret = ('<div class="equation-container" '
f'id="{full_ref_str}">'
f'<div class="equation">{fig_str}</div>'
f'<div class="equation-number">{caption}</div></div>')
ret = ('<div class="equation-container">'
'<div class="equation">%s</div>'
'<div class="equation-number">%s</div></div>') % (
figure_to_string(fig, self._figure_format, base64=self._base64_svgs),
caption)
else:
ret = '<span class="inline-equation">' + figure_to_string(fig, self._figure_format, base64=self._base64_svgs) + '</span>'
@ -372,7 +372,6 @@ class DocumentWriter():
self.modified_html = StringIO()
self.in_latex: bool = False
self.eq_caption: str = ''
self.full_ref_str: str = ''
self.block: bool = False
self.dw = document_writer
@ -383,8 +382,6 @@ class DocumentWriter():
self.in_latex = True
attr_dict = {k: v if v else '' for k, v in attrs}
self.eq_caption = attr_dict.get('caption', '')
self.full_ref_str = latex.normalize_label_text(
f"pyld-ref-{attr_dict.get('ref_type', '')}:{attr_dict.get('ref_id', '')}")
self.block = attr_dict.get('type') == 'block'
elif not self.in_latex:
tag_text = self.get_starttag_text()
@ -394,7 +391,7 @@ class DocumentWriter():
def handle_data(self, data: str) -> None:
if self.in_latex:
self.modified_html.write(
self.dw._get_equation_html(data, self.eq_caption, self.full_ref_str, self.block))
self.dw._get_equation_html(data, self.eq_caption, self.block))
else:
self.modified_html.write(data)
@ -432,12 +429,10 @@ class DocumentWriter():
has an individual numbering
centered: Whether to center the figure in LaTeX output
"""
def render_to_html() -> str:
caption_prefix = self._add_item(ref_id, ref_type, prefix_pattern)
full_ref_str = latex.normalize_label_text(f"pyld-ref-{ref_type}:{ref_id}")
return '<div id="%s" class="figure">%s%s</div>' % (
full_ref_str,
return '<div class="figure">%s%s</div>' % (
figure_to_string(fig, self._figure_format, base64=self._base64_svgs, scale=self._fig_scale),
'<br>' + caption_prefix + escape_html(caption) if caption else '')
@ -471,11 +466,9 @@ class DocumentWriter():
assert isinstance(styler, Styler), 'Jinja2 package is required for rendering tables'
def render_to_html() -> str:
full_ref_str = latex.normalize_label_text(f"pyld-ref-{ref_type}:{ref_id}")
caption_prefix = self._add_item(ref_id, ref_type, prefix_pattern)
html_string = styler.to_html(table_uuid=ref_id, caption=caption_prefix + escape_html(caption))
return f'<div id="{full_ref_str}">' + re.sub(r'<style.*?>.*?</style>', '', html_string, flags=re.DOTALL) + '</div>'
return re.sub(r'<style.*?>.*?</style>', '', html_string, flags=re.DOTALL)
def render_to_latex() -> str:
self._add_item(ref_id, ref_type, prefix_pattern)
@ -589,8 +582,7 @@ class DocumentWriter():
def render_to_html() -> str:
caption = self._add_item(ref_id, ref_type, '({})')
full_ref_str = latex.normalize_label_text(f"pyld-ref-{ref_type}:{ref_id}")
return self._get_equation_html(latex_equation, caption, full_ref_str)
return self._get_equation_html(latex_equation, caption)
def render_to_latex() -> str:
self._add_item(ref_id, ref_type, '')

View File

@ -1,7 +1,6 @@
import pyladoc
import pandas as pd
def test_readme_example():
doc = pyladoc.DocumentWriter()
@ -29,4 +28,4 @@ def test_readme_example():
html_code = doc.to_html()
print(html_code)
assert '<table' in html_code
assert '<table' in html_code