Skip to content

madbot_cli.editor

Read the texts written in the editor of madbot, such as a description, as plain text.

madbot keeps such a text as an EditorJS object ({"blocks": [...]}), while a deposit file gives it as a text, which madbot reads as Markdown on write (**bold** becomes <b>bold</b>, - a a list). fields writes the plain text, the checks read it, and plan compares the words of both sides without the markup, so that the values match once applied.

Attributes

NameDescription
LINKA link of an EditorJS text: its address is part of the text compared.
MD_BOLDNo description.
MD_CHECKBOXNo description.
MD_CODEThe inline Markdown madbot turns into HTML in a paragraph or a quote.
MD_HEADERNo description.
MD_ITALICNo description.
MD_LINKNo description.
MD_LISTNo description.
MD_SEPARATORThe lines madbot reads as a header, a list item, a checkbox or a table rule.
QUOTE_PREFIXESThe marks of a call-out and of details, which madbot keeps as a variant.
TAGSThe inline HTML of an EditorJS text, such as <b>; not a < of the text.

Functions

NameDescription
block_textsGive the texts of one EditorJS block: a paragraph, a header, a list, code or a table.
blocks_ofGive the blocks of an EditorJS object, or of its JSON string.
code_textRead a block of code of Markdown, as madbot keeps it.
editor_textGive the plain text of an EditorJS object or of its JSON string.
inline_textRemove the inline Markdown madbot turns into HTML, as its text reads once saved.
item_textsGive the texts of the items of an EditorJS list, nested items included.
markdown_textsGive the texts madbot keeps of a text of a file, which it reads as Markdown.
plainPut the plain text in place of every EditorJS text of a value.
quote_textRead a quote of Markdown, without its mark of a call-out or of details.
sameTell whether madbot already holds the value of the file.
table_textsRead a table of Markdown: the cells of each row, without its rule.
wordsGive the text of an editor value as plan compares it: without markup, spaces folded.
LINK = re.compile('<a href="([^"]*)"[^>]*>(.*?)</a>')

A link of an EditorJS text: its address is part of the text compared.

MD_BOLDattributemodule attribute#

MD_BOLD = re.compile('\\*\\*([^\\*]+)\\*\\*')

MD_CHECKBOXattributemodule attribute#

MD_CHECKBOX = re.compile('^\\[([x ])\\]\\s+(.+)$')

MD_CODEattributemodule attribute#

MD_CODE = re.compile('`([^`]+)`')

The inline Markdown madbot turns into HTML in a paragraph or a quote.

MD_HEADERattributemodule attribute#

MD_HEADER = re.compile('^(#{1,6})\\s+(.+)$')

MD_ITALICattributemodule attribute#

MD_ITALIC = re.compile('\\*([^\\*]+)\\*')
MD_LINK = re.compile('\\[([^\\]]+)\\]\\(([^\\)]+)\\)')

MD_LISTattributemodule attribute#

MD_LIST = re.compile('^(\\s*)([-*]|\\d+\\.)\\s+(.+)$')

MD_SEPARATORattributemodule attribute#

MD_SEPARATOR = re.compile('^-+$')

The lines madbot reads as a header, a list item, a checkbox or a table rule.

QUOTE_PREFIXESattributemodule attribute#

QUOTE_PREFIXES = ('💡 ', 'ℹ️ ')

The marks of a call-out and of details, which madbot keeps as a variant.

TAGSattributemodule attribute#

TAGS = re.compile('</?[A-Za-z][^<>]*>')

The inline HTML of an EditorJS text, such as <b>; not a < of the text.

block_textsfunction#

def block_texts(block: Any, *, links: bool = False) -> list[str]

Give the texts of one EditorJS block: a paragraph, a header, a list, code or a table.

Parameters

NameTypeDefaultDescription
blockAnyrequiredThe block.
linksboolFalseKeep the address of each link after its text, as text (address).

Returns

list of str
Its texts, without their inline HTML.

blocks_offunction#

def blocks_of(value: Any) -> list | None

Give the blocks of an EditorJS object, or of its JSON string.

Parameters

NameTypeDescription
valueAnyA value of a metadata field.

Returns

list or None
The blocks; None when the value is not an EditorJS text.

code_textfunction#

def code_text(lines: list[str], i: int) -> tuple[str, int]

Read a block of code of Markdown, as madbot keeps it.

Parameters

NameTypeDescription
lineslist of strThe lines of the text.
iintThe line after the opening fence.

Returns

tuple
The code, and the line after the closing fence.

editor_textfunction#

def editor_text(value: Any) -> str | None

Give the plain text of an EditorJS object or of its JSON string.

Parameters

NameTypeDescription
valueAnyA value of a metadata field.

Returns

str or None
Its blocks as paragraphs, separated by a blank line; None when the value is not an EditorJS text.

inline_textfunction#

def inline_text(text: str) -> str

Remove the inline Markdown madbot turns into HTML, as its text reads once saved.

Parameters

NameTypeDescription
textstrA paragraph or a quote of a file.

Returns

str
The text, a link as text (address).

item_textsfunction#

def item_texts(items: Any) -> list[str]

Give the texts of the items of an EditorJS list, nested items included.

Parameters

NameTypeDescription
itemsAnyThe items of a list block.

Returns

list of str
The text of each item, then of its own items.

markdown_textsfunction#

def markdown_texts(text: str) -> list[str]

Give the texts madbot keeps of a text of a file, which it reads as Markdown.

Follows how madbot turns Markdown into EditorJS: a header, a list item or a table cell keeps its text as written, a paragraph or a quote loses its inline Markdown.

Parameters

NameTypeDescription
textstrThe text of a file.

Returns

list of str
The texts of the blocks madbot would make.

plainfunction#

def plain(value: Any) -> Any

Put the plain text in place of every EditorJS text of a value.

Parameters

NameTypeDescription
valueAnyA value of a metadata field, such as a list of descriptions each with its language.

Returns

Any
The same value, its editor texts as plain text.

quote_textfunction#

def quote_text(line: str) -> str

Read a quote of Markdown, without its mark of a call-out or of details.

Parameters

NameTypeDescription
linestrThe line, starting with >.

Returns

str
Its text, as madbot keeps it.

samefunction#

def same(current: Any, value: Any) -> bool

Tell whether madbot already holds the value of the file.

Only an editor text is compared by its words: any other text must be the same, a space included.

Parameters

NameTypeDescription
currentAnyThe value madbot holds.
valueAnyThe value of the file.

Returns

bool
True when they are the same, editor texts compared by their words.

table_textsfunction#

def table_texts(lines: list[str], i: int) -> tuple[list[str], int]

Read a table of Markdown: the cells of each row, without its rule.

Parameters

NameTypeDescription
lineslist of strThe lines of the text.
iintIts first row.

Returns

tuple
The text of each row, and the line after the table.

wordsfunction#

def words(value: Any) -> str | None

Give the text of an editor value as plan compares it: without markup, spaces folded.

madbot may cut a text into paragraphs or lines of its own, and keeps its Markdown as HTML: the text is the same whatever its spaces, its line breaks and its markup.

Parameters

NameTypeDescription
valueAnyAn EditorJS object, its JSON string, or a text of a file.

Returns

str or None
The text; None when the value is not a text.