tiptap

TipTap content validator for Nim

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.1.0
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-11-21 14:04

Authors

  • George Lemon

Installation

nimble install tiptap
choosenim install tiptap
git clone https://github.com/openpeeps/tiptap-nim

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
tiptap ✓ ✓ ✓ - - - - - - -

Dependencies

Package Version Optional
nim >= 2.0.0 No
openparser >= 0.3.5 No

Source

Repository https://github.com/openpeeps/tiptap-nim
Homepage https://github.com/openpeeps/tiptap-nim
Registry Source nimble_official

README

Tiptap Content Validator for 👑 in Nim language

clue install tiptap

API reference
Github Actions Github Actions

😍 Key Features

  • Fast and lightweight validation of Tiptap JSON content
  • JSON parsing and serialization with openparser/json
  • Easy to use API

[!NOTE] This library only validates Tiptap JSON content structure. It does not render or manipulate the content.

Install

clue install tiptap

For local development:

clue develop

Test

clue test

Examples

Runnable examples live in examples/. Build and run one with clue:

clue build examples/basic.nim --out:/tmp/tiptap_basic
/tmp/tiptap_basic

Parse and validate (examples/basic.nim)

import std/options
import tiptap

let raw = """{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Hello, TipTap!"}]}]}"""

let editor = initTipTap(raw)
echo "doc type: ", editor.content.`type`
echo "valid: ", editor.content.validate()
echo "first paragraph text: ", editor.content.getFirstParagraph().get().content[0].text
echo "json: ", $editor.content

Expected output:

doc type: doc
valid: true
first paragraph text: Hello, TipTap!
json: {"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Hello, TipTap!","marks":[],"attrs":{}}],"attrs":{}}]}

Custom schemas (examples/schema.nim)

import tiptap

let raw = """{"type":"doc","content":[{"type":"heading","attrs":{"level":"1"},"content":[{"type":"text","text":"Title"}]},{"type":"paragraph","content":[{"type":"text","text":"Body","marks":[{"type":"bold"}]}]}]}"""

let doc = parseTipTapContent(raw)
echo "valid with default schema: ", doc.validate()

let ordered = TipTapSchema(layoutRules: @[ttHeading, ttParagraph])
echo "valid heading+paragraph order: ", doc.validate(ordered)

let swapped = TipTapSchema(layoutRules: @[ttParagraph, ttHeading])
echo "valid swapped order (should be false): ", doc.validate(swapped)

let imagesOnly = TipTapSchema(whitelist: {ttImage})
echo "valid images-only (should be false): ", doc.validate(imagesOnly)

Run it:

clue build examples/schema.nim --out:/tmp/tiptap_schema
/tmp/tiptap_schema

Build docs programmatically (examples/build.nim)

import std/tables
import tiptap

var para = newTipTapNode(ttParagraph)
para.content = @[]
para.attrs = initTable[string, string]()

var textNode = newTipTapNode(ttText)
textNode.text = "Built programmatically"
textNode.marks = @[newTipTapNode(ttBold)]
textNode.attrs = initTable[string, string]()

para.addChild(textNode)

var image = newTipTapNode(ttImage)
image.content = @[]
image.attrs = initTable[string, string]()
image.attrs["src"] = "cover.png"
image.attrs["alt"] = "cover"

let doc = TipTapContent(`type`: "doc", content: @[para, image])
echo "valid: ", doc.validate()
echo "json: ", $doc

let reparsed = parseTipTapContent($doc)
echo "round-trip valid: ", reparsed.validate()
echo "round-trip blocks: ", reparsed.content.len

Run it:

clue build examples/build.nim --out:/tmp/tiptap_build
/tmp/tiptap_build

More usage examples are covered in tests/test1.nim.

❤ Contributions & Support

🎩 License

MIT license. Made by Humans from OpenPeeps.
Copyright OpenPeeps & Contributors — All rights reserved.