Rich content
Several fields hold formatted documents rather than plain strings: problem statements, editorials, posts, comments, course materials. These fields are rich content, authored in Markdown or LaTeX and readable either as that source or as a parsed tree.
All of them are the same Content object, which has two representations:
- Value — the Markdown or LaTeX as written by an author. Used for editing.
- Render — the same content parsed into a tree. Used for display.
The value is the stored source. The render is derived from it and read-only, produced by the platform's parser, so all clients display identical content without implementing Markdown or LaTeX themselves.
Requesting a representation
Neither representation is returned by default. Rich content is large, and a caller listing a hundred problems rarely needs a hundred statements, so each is requested explicitly through the extra parameter of the read.
The values are named after the field they apply to: a statement's content uses CONTENT_VALUE and CONTENT_RENDER, an issue's description uses DESCRIPTION_VALUE and DESCRIPTION_RENDER.
import eolymp.atlas
import eolymp.core
transport = eolymp.core.HttpClient(token="etkn-...")
client = eolymp.atlas.StatementServiceClient(transport, url="https://api.eolymp.com/spaces/SPACE_ID/problems/PROBLEM_ID")
# for display, request the tree
out = client.LookupStatement(request=eolymp.atlas.LookupStatementInput(
locale="en",
extra=[eolymp.atlas.Statement.Extra.CONTENT_RENDER],
))
print(out.statement.content.render)
# for editing, request the source
out = client.LookupStatement(request=eolymp.atlas.LookupStatementInput(
locale="en",
extra=[eolymp.atlas.Statement.Extra.CONTENT_VALUE],
))
print(out.statement.content.markdown)Both may be requested together. If neither is requested, the content object is returned empty.
Node structure
A node consists of a type, a map of attr, and children. A document is a tree of such nodes and contains nothing else.
The parser is also available directly, without storing anything, which is how content that has not been saved is previewed. POST /spaces/{space_id}/content:render accepts content and returns the tree:
curl https://api.eolymp.com/spaces/SPACE_ID/content:render \
-H "content-type: application/json" \
-d '{"content":{"markdown":"Given $n$ integers, print **max**."}}'{
"render": {
"type": "document",
"children": [
{
"type": "p",
"children": [
{"type": "span", "attr": {"text": "Given "}},
{"type": "inline-math", "attr": {"exp": "n"}},
{"type": "span", "attr": {"text": " integers, print "}},
{"type": "span", "attr": {"style": "bold", "text": "max"}}
]
}
]
}
}Text is carried in a span's text attribute rather than on the node itself, and mathematics keeps its expression in exp for the client to typeset. Other markup produces the corresponding node types: heading with a level, code with a lang and its source, list with li, table with tr and td, and div for a block with a class.
Attribute values are always strings, regardless of what they represent. A heading's level is returned as
"2"and a table's borders as"true". Conversion is the client's responsibility.
Format independence
Markdown and LaTeX parse into the same node vocabulary. The following LaTeX
\textbf{Sum} of $\sum_{i=1}^{n} a_i$.
produces a p containing a bold span, a plain span and an inline-math, identical to the equivalent Markdown. A client able to render the tree can therefore display any content in the platform regardless of how it was authored.
Some fields allow an expanded schema, in which additional LaTeX macros and Markdown markup are supported. A problem statement accepts more than a comment does, so the same source does not necessarily produce the same tree in every field.
Writing content
Set exactly one of markdown or latex. The render is read-only; any value supplied for it is ignored and replaced by the parser's output.
client.CreateStatement(request=eolymp.atlas.CreateStatementInput(
statement=eolymp.atlas.Statement(
locale="en",
title="Two Sum",
content=eolymp.ecm.Content(markdown="Given an array, return two indices summing to a target."),
),
))The markup itself — mathematics, images, layouts, admonitions, and the section markers used by problem statements — is documented in the formatting guides at support.eolymp.com.
Updated 8 days ago
