Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AAriam committed Sep 17, 2024
1 parent e49a67b commit 2928961
Show file tree
Hide file tree
Showing 7 changed files with 677 additions and 482 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespaces = true
# ----------------------------------------- Project Metadata -------------------------------------
#
[project]
version = "0.0.0.dev1"
version = "0.0.0.dev2"
name = "MDit"
requires-python = ">=3.10"
dependencies = [
Expand All @@ -43,4 +43,5 @@ dependencies = [
"HTMP",
"ansi-sgr",
"pygments",
"rich",
]
61 changes: 50 additions & 11 deletions src/mdit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def generate(config: dict | list):

def document(
heading: element.Heading | MDContainer | ContainerContentInputType = None,
body: Sequence[ContainerContentInputType] = None,
body: MDContainer | ContainerContentInputType = None,
section: Container | None = None,
footer: ContainerContentInputType = None,
footer: MDContainer | ContainerContentInputType = None,
frontmatter: dict | element.FrontMatter | None = None,
frontmatter_conditions: list[str] | None = None,
separate_sections: bool = False,
Expand All @@ -54,12 +54,11 @@ def document(
# Process heading
if heading and not isinstance(heading, element.Heading):
heading = element.heading(
heading,
content_separator=content_separator_heading,
content=heading,
target_configs=target_configs,
target_default=target_default,
)
body = container(body, content_separator="\n\n")
body = to_block_container(body)
if isinstance(section, Container):
pass
elif not section:
Expand All @@ -70,7 +69,7 @@ def document(
section = section_container(*section)
else:
section = section_container(section)
footer = container(footer, content_separator="\n\n")
footer = to_block_container(footer)
if isinstance(frontmatter, dict):
frontmatter = element.frontmatter(frontmatter)
return Document(
Expand Down Expand Up @@ -158,17 +157,57 @@ def section_container(
return container_


def _to_container(
contents: list[ContainerContentSingleInputType],
def to_block_container(
content: MDContainer | ContainerContentInputType,
separator: str = "\n\n",
html_container: Stringable | None = None,
html_container_attrs: dict | None = None,
html_container_conditions: list[str] | None = None,
target_configs: TargetConfigs = None,
target_default: str = "sphinx",
) -> MDContainer:
return to_md_container(
content,
content_separator=separator,
html_container=html_container,
html_container_attrs=html_container_attrs,
html_container_conditions=html_container_conditions,
target_configs=target_configs,
target_default=target_default,
)


def to_inline_container(
content: MDContainer | ContainerContentInputType,
separator: str = "",
html_container: Stringable | None = None,
html_container_attrs: dict | None = None,
html_container_conditions: list[str] | None = None,
target_configs: TargetConfigs = None,
target_default: str = "sphinx",
) -> MDContainer:
return to_md_container(
content,
content_separator=separator,
html_container=html_container,
html_container_attrs=html_container_attrs,
html_container_conditions=html_container_conditions,
target_configs=target_configs,
target_default=target_default,
)


def to_md_container(
content: MDContainer | ContainerContentInputType,
content_separator: str,
html_container: Stringable | None = None,
html_container_attrs: dict | None = None,
html_container_conditions: list[str] | None = None,
target_configs: TargetConfigs = None,
target_default: str = "sphinx",
) -> MDContainer:
if len(contents) == 1 and isinstance(contents[0], MDContainer):
return contents[0]
if isinstance(content, MDContainer):
return content
container_ = MDContainer(
content_separator=content_separator,
html_container=html_container,
Expand All @@ -177,5 +216,5 @@ def _to_container(
target_configs=target_configs,
target_default=target_default,
)
container_.extend(contents)
container_.extend(content)
return container_
8 changes: 4 additions & 4 deletions src/mdit/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ def source(
heading_number=heading_number,
separate_sections=separate_sections,
)
return doc["index"] if len(doc) == 1 else doc
return doc
return self._str_md_single(
target=target,
filters=filters,
heading_number=heading_number,
heading_number_explicit=heading_number_explicit,
)["index"]
)
return self._source_rich(
target=target,
filters=filters,
Expand Down Expand Up @@ -184,7 +184,7 @@ def _str_md_single(
filters=filters,
heading_number=heading_number + [idx + 1],
)
content.append(subsections_str["index"])
content.append(subsections_str)
footer = self.footer.source(target=target, filters=filters)
if footer:
content.append(footer)
Expand All @@ -205,7 +205,7 @@ def _str_md_single(
page.append(heading)
# Otherwise <details> is used, which displays the title
page.append(_mdit.element.toggle(page_content, title=heading).source(target=target))
return {"index": "\n\n".join(page).strip()}
return "\n\n".join(page).strip()


def _str_md_multi(
Expand Down
Loading

0 comments on commit 2928961

Please sign in to comment.