mirror of https://github.com/Nonannet/pyladoc.git
Compare commits
No commits in common. "a90d055d3eda626b4a27b4645119cfee9c03c766" and "dda979487f5eb175fd4356f5fbfd0d6641ef40e5" have entirely different histories.
a90d055d3e
...
dda979487f
|
@ -218,7 +218,7 @@ def _fillin_reference_names(input_string: str, item_index: dict[str, int]) -> st
|
||||||
for start, end, ref in replacements:
|
for start, end, ref in replacements:
|
||||||
assert ref in item_index, f"Reference {ref} does not exist in the document"
|
assert ref in item_index, f"Reference {ref} does not exist in the document"
|
||||||
ret.append(input_string[current_pos:start - 1])
|
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
|
current_pos = end
|
||||||
return ''.join(ret) + input_string[current_pos:]
|
return ''.join(ret) + input_string[current_pos:]
|
||||||
|
|
||||||
|
@ -349,14 +349,14 @@ class DocumentWriter():
|
||||||
|
|
||||||
return inline_pattern.sub(inline_repl, result)
|
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)
|
fig = latex_to_figure(latex_equation)
|
||||||
if block:
|
if block:
|
||||||
fig_str = figure_to_string(fig, self._figure_format, base64=self._base64_svgs)
|
ret = ('<div class="equation-container">'
|
||||||
ret = ('<div class="equation-container" '
|
'<div class="equation">%s</div>'
|
||||||
f'id="{full_ref_str}">'
|
'<div class="equation-number">%s</div></div>') % (
|
||||||
f'<div class="equation">{fig_str}</div>'
|
figure_to_string(fig, self._figure_format, base64=self._base64_svgs),
|
||||||
f'<div class="equation-number">{caption}</div></div>')
|
caption)
|
||||||
else:
|
else:
|
||||||
ret = '<span class="inline-equation">' + figure_to_string(fig, self._figure_format, base64=self._base64_svgs) + '</span>'
|
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.modified_html = StringIO()
|
||||||
self.in_latex: bool = False
|
self.in_latex: bool = False
|
||||||
self.eq_caption: str = ''
|
self.eq_caption: str = ''
|
||||||
self.full_ref_str: str = ''
|
|
||||||
self.block: bool = False
|
self.block: bool = False
|
||||||
self.dw = document_writer
|
self.dw = document_writer
|
||||||
|
|
||||||
|
@ -383,8 +382,6 @@ class DocumentWriter():
|
||||||
self.in_latex = True
|
self.in_latex = True
|
||||||
attr_dict = {k: v if v else '' for k, v in attrs}
|
attr_dict = {k: v if v else '' for k, v in attrs}
|
||||||
self.eq_caption = attr_dict.get('caption', '')
|
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'
|
self.block = attr_dict.get('type') == 'block'
|
||||||
elif not self.in_latex:
|
elif not self.in_latex:
|
||||||
tag_text = self.get_starttag_text()
|
tag_text = self.get_starttag_text()
|
||||||
|
@ -394,7 +391,7 @@ class DocumentWriter():
|
||||||
def handle_data(self, data: str) -> None:
|
def handle_data(self, data: str) -> None:
|
||||||
if self.in_latex:
|
if self.in_latex:
|
||||||
self.modified_html.write(
|
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:
|
else:
|
||||||
self.modified_html.write(data)
|
self.modified_html.write(data)
|
||||||
|
|
||||||
|
@ -432,12 +429,10 @@ class DocumentWriter():
|
||||||
has an individual numbering
|
has an individual numbering
|
||||||
centered: Whether to center the figure in LaTeX output
|
centered: Whether to center the figure in LaTeX output
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def render_to_html() -> str:
|
def render_to_html() -> str:
|
||||||
caption_prefix = self._add_item(ref_id, ref_type, prefix_pattern)
|
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 class="figure">%s%s</div>' % (
|
||||||
return '<div id="%s" class="figure">%s%s</div>' % (
|
|
||||||
full_ref_str,
|
|
||||||
figure_to_string(fig, self._figure_format, base64=self._base64_svgs, scale=self._fig_scale),
|
figure_to_string(fig, self._figure_format, base64=self._base64_svgs, scale=self._fig_scale),
|
||||||
'<br>' + caption_prefix + escape_html(caption) if caption else '')
|
'<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'
|
assert isinstance(styler, Styler), 'Jinja2 package is required for rendering tables'
|
||||||
|
|
||||||
def render_to_html() -> str:
|
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)
|
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))
|
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:
|
def render_to_latex() -> str:
|
||||||
self._add_item(ref_id, ref_type, prefix_pattern)
|
self._add_item(ref_id, ref_type, prefix_pattern)
|
||||||
|
@ -589,8 +582,7 @@ class DocumentWriter():
|
||||||
|
|
||||||
def render_to_html() -> str:
|
def render_to_html() -> str:
|
||||||
caption = self._add_item(ref_id, ref_type, '({})')
|
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)
|
||||||
return self._get_equation_html(latex_equation, caption, full_ref_str)
|
|
||||||
|
|
||||||
def render_to_latex() -> str:
|
def render_to_latex() -> str:
|
||||||
self._add_item(ref_id, ref_type, '')
|
self._add_item(ref_id, ref_type, '')
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import pyladoc
|
import pyladoc
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
def test_readme_example():
|
def test_readme_example():
|
||||||
doc = pyladoc.DocumentWriter()
|
doc = pyladoc.DocumentWriter()
|
||||||
|
|
||||||
|
@ -29,4 +28,4 @@ def test_readme_example():
|
||||||
html_code = doc.to_html()
|
html_code = doc.to_html()
|
||||||
print(html_code)
|
print(html_code)
|
||||||
|
|
||||||
assert '<table' in html_code
|
assert '<table' in html_code
|
Loading…
Reference in New Issue