Types
TipTapContent = object content*: seq[TipTapNode] ## The content of the document, which is a sequence of `TipTapNode`
- Represents the entire TipTap document structure
TipTapNode {.acyclic.} = ref object case ## The type of the node, e.g., "paragraph", "text", etc. of ttText: text*: string ## The actual text content for text nodes marks*: seq[TipTapNode] ## Marks applied to the node, such as "bold", "italic", etc. else: content*: seq[TipTapNode] ## The content of the node, which can be a sequence of `TipTapNode` attrs*: Table[string, string] ## Attributes of the node, such as "bold", "italic", etc.
- Represents a node in the TipTap document structure. This can be a text node, paragraph, heading, etc.
TipTapNodeType = enum ttCustom, ttParagraph = "paragraph", ttText = "text", ttHeading = "heading", ttBold = "bold", ttItalic = "italic", ttLink = "link", ttBulletList = "bulletList", ttOrderedList = "orderedList", ttListItem = "listItem", ttTaskList = "taskList", ttImage = "image", ttCodeBlock = "codeBlock", ttCode = "code", ttBlockquote = "blockquote", ttHighlight = "highlight"
- Enumeration of allowed node types in the TipTap editor. This includes basic text formatting nodes, structural nodes like paragraphs and headings, and media nodes like images. Custom node types can also be added as needed
Procs
proc `$`(tt: TipTapContent): string {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Converts the TipTap document to a JSON string representation using openparser/json
proc addChild(parent: var TipTapNode; child: TipTapNode) {....raises: [], tags: [], forbids: [].}
- Adds a child node to the parent node
proc getFirstParagraph(content: TipTapContent): Option[TipTapNode] {....raises: [], tags: [], forbids: [].}
- Retrieves the first paragraph node from the TipTap content
proc jsonValueToString(n: JsonNode): string {....raises: [], tags: [RootEffect], forbids: [].}
- Converts a JSON value to its string representation for attrs storage
proc newTipTapNode(typ: TipTapNodeType): TipTapNode {....raises: [], tags: [], forbids: [].}
- Create a new TipTap node
proc parseTipTapContent(s: string): TipTapContent {. ...raises: [OpenParserJsonError, ValueError, Exception, KeyError], tags: [RootEffect], forbids: [].}
-
Parses a TipTap JSON string into a TipTapContent document using openparser/json via a JsonNode intermediate.
Note: we parse via JsonNode instead of fromJson(s, TipTapContent) because openparser's compile-time fast path does not handle the backticked type field on non-variant objects.
proc toTipTapAttrs(n: JsonNode): Table[string, string] {....raises: [], tags: [RootEffect], forbids: [].}
- Converts a JSON object into an attrs table. Non-string scalars are stringified so {"level": 1} becomes {"level": "1"}
proc toTipTapContent(n: JsonNode): TipTapContent {. ...raises: [KeyError, ValueError], tags: [RootEffect], forbids: [].}
- Converts a JsonNode (parsed with openparser/json) into a TipTapContent document
proc toTipTapNode(n: JsonNode): TipTapNode {....raises: [ValueError, KeyError], tags: [RootEffect], forbids: [].}
- Converts a JsonNode into a TipTapNode. Raises ValueError for unknown node types (via parseEnum)