136 lines
3.3 KiB
Python
136 lines
3.3 KiB
Python
"""
|
|
Silique (https://www.silique.fr)
|
|
Copyright (C) 2024-2025
|
|
|
|
This program is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU Lesser General Public License as published by the
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
|
|
from typing import List
|
|
from ..utils import CommonFormater, dump
|
|
|
|
|
|
class Formater(CommonFormater):
|
|
"""The asciidoc formater"""
|
|
|
|
name = "asciidoc"
|
|
_table_name = "asciidoc"
|
|
level = 40
|
|
|
|
def title(
|
|
self,
|
|
title: str,
|
|
level: int,
|
|
) -> str:
|
|
"""Display family name as a title"""
|
|
char = "="
|
|
return f"{char * (level + 1)} {title}\n\n"
|
|
|
|
def join(
|
|
self,
|
|
lst: List[str],
|
|
) -> str:
|
|
"""Display line in table from a list"""
|
|
string = ""
|
|
previous = ""
|
|
for line in lst:
|
|
if string:
|
|
if self.is_list(previous.split("\n", 1)[-1]):
|
|
string += "\n\n"
|
|
else:
|
|
string += " +\n"
|
|
string += line
|
|
|
|
previous = line
|
|
return "\n" + string
|
|
|
|
def bold(
|
|
self,
|
|
msg: str,
|
|
) -> str:
|
|
"""Set a text to bold"""
|
|
return f"**{msg}**"
|
|
|
|
def italic(
|
|
self,
|
|
msg: str,
|
|
) -> str:
|
|
"""Set a text to italic"""
|
|
return f"__{msg}__"
|
|
|
|
def delete(
|
|
self,
|
|
msg: str,
|
|
) -> str:
|
|
"""Set a text to deleted"""
|
|
return f"+++{msg}+++"
|
|
|
|
def underline(
|
|
self,
|
|
msg: str,
|
|
) -> str:
|
|
"""Set a text to underline"""
|
|
return f"#{msg}#"
|
|
|
|
def stripped(
|
|
self,
|
|
text: str,
|
|
) -> str:
|
|
"""Return stripped text (as help)"""
|
|
return text.strip()
|
|
|
|
def list(
|
|
self,
|
|
choices: list,
|
|
) -> str:
|
|
"""Display a liste of element"""
|
|
prefix = "\n\n* "
|
|
char = "\n* "
|
|
return prefix + char.join([dump(choice) for choice in choices])
|
|
|
|
def prop(
|
|
self,
|
|
prop: str,
|
|
italic: bool,
|
|
) -> str:
|
|
"""Display property"""
|
|
if italic:
|
|
prop = self.italic(prop)
|
|
return f"`{prop}`"
|
|
|
|
def yaml(self, _dump: dict) -> str:
|
|
"""Dump yaml part of documentation"""
|
|
return f"[,yaml]\n----\n---\n{dump(_dump)}\n----\n"
|
|
|
|
def table(self, datas: list, with_header: bool = True) -> str:
|
|
"""Transform list to a table in string format
|
|
we change the first line because we want that col has the same width
|
|
"""
|
|
table = super().table(datas, with_header)
|
|
stable = table.split("\n", 1)
|
|
return '[cols="1a,1a"]\n' + stable[1]
|
|
|
|
def link(
|
|
self,
|
|
comment: str,
|
|
link: str,
|
|
) -> str:
|
|
"""Add a link"""
|
|
return f"`{link}[{comment}]`"
|
|
|
|
def is_list(
|
|
self,
|
|
txt: str,
|
|
) -> str:
|
|
"""verify if a text is a list"""
|
|
return txt.strip().startswith("* ")
|