{classNames} = Trix.config.css @TEST_IMAGE_URL = "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" createDocument = (parts...) -> blocks = for part in parts [string, textAttributes, blockAttributes] = part text = Trix.Text.textForStringWithAttributes(string, textAttributes) new Trix.Block text, blockAttributes new Trix.Document blocks blockComment = "" cursorTarget = Trix.makeElement( tagName: "span" textContent: Trix.ZERO_WIDTH_SPACE data: trixSelection: true, trixCursorTarget: true, trixSerialize: false ).outerHTML removeWhitespace = (string) -> string.replace(/\s/g, "") @fixtures = "bold text": document: createDocument(["abc", bold: true]) html: "
#{blockComment}abc" "code formatted block": document: createDocument(["123", {}, ["code"]]) html: "
#{blockComment}123" "code with newline": document: createDocument(["12\n3", {}, ["code"]]) html: "
#{blockComment}12\n3" "multiple blocks with block comments in their text": document: createDocument(["a#{blockComment}b", {}, ["quote"]], ["#{blockComment}c", {}, ["code"]]) html: "
#{blockComment}a<!--block-->b
#{blockComment}<!--block-->c" serializedHTML: "
a<!--block-->b
<!--block-->c" "unordered list with one item": document: createDocument(["a", {}, ["bulletList", "bullet"]]) html: "
#{blockComment}" "image attachment": do -> attrs = url: TEST_IMAGE_URL, filename: "example.png", filesize: 98203, contentType: "image/png", width: 1, height: 1 attachment = new Trix.Attachment attrs text = Trix.Text.textForAttachmentWithAttributes(attachment) image = Trix.makeElement("img", src: attrs.url, "data-trix-mutable": true, width: 1, height: 1) image.dataset.trixStoreKey = ["imageElement", attachment.id, image.src, image.width, image.height].join("/") caption = Trix.makeElement(tagName: "figcaption", className: classNames.attachment.caption) caption.innerHTML = """#{attrs.filename} """ figure = Trix.makeElement tagName: "figure" className: "attachment attachment-preview png" data = trixAttachment: JSON.stringify(attachment) trixContentType: "image/png" trixId: attachment.id figure.dataset[key] = value for key, value of data figure.setAttribute("contenteditable", false) figure.appendChild(image) figure.appendChild(caption) serializedFigure = figure.cloneNode(true) for attribute in ["data-trix-id", "data-trix-mutable", "data-trix-store-key", "contenteditable"] serializedFigure.removeAttribute(attribute) for element in serializedFigure.querySelectorAll("[#{attribute}]") element.removeAttribute(attribute) html: "
""" href = "https://twitter.com/sstephenson/status/587715996783218688" contentType = "embed/twitter" attachment = new Trix.Attachment {content, contentType, href} text = Trix.Text.textForAttachmentWithAttributes(attachment) figure = Trix.makeElement tagName: "figure" className: "attachment attachment-content" figure.innerHTML = content caption = Trix.makeElement(tagName: "figcaption", className: classNames.attachment.caption) figure.appendChild(caption) data = trixAttachment: JSON.stringify(attachment) trixContentType: contentType trixId: attachment.id figure.dataset[key] = value for key, value of data figure.setAttribute("contenteditable", false) html: """ruby-build 20150413 is out, with definitions for 2.2.2, 2.1.6, and 2.0.0-p645 to address recent security issues: https://t.co/YEwV6NtRD8
— Sam Stephenson (@sstephenson) April 13, 2015
" "nested code and quote formatted block": document: createDocument(["ab3", {}, ["code", "quote"]]) html: "#{blockComment}ab3
" "nested code blocks in quote": document: createDocument( ["a\n", {}, ["quote"]], ["b", {}, ["quote", "code"]], ["\nc\n", {}, ["quote"]], ["d", {}, ["quote", "code"]] ) html: removeWhitespace """#{blockComment}ab3
#{blockComment} a""" serializedHTML: removeWhitespace """
#{blockComment} b#{blockComment}
c
#{blockComment} d
a""" "nested code, quote, and list in quote": document: createDocument( ["a\n", {}, ["quote"]], ["b", {}, ["quote", "code"]], ["\nc\n", {}, ["quote"]], ["d", {}, ["quote", "quote"]], ["\ne\n", {}, ["quote"]], ["f", {}, ["quote", "bulletList", "bullet"]] ) html: removeWhitespace """
b
c
d
#{blockComment} a""" serializedHTML: removeWhitespace """
#{blockComment} b#{blockComment}
c
#{blockComment} d#{blockComment}
e
- #{blockComment} f
a""" "nested quote and list": document: createDocument(["ab3", {}, ["quote", "bulletList", "bullet"]]) html: "
b
c
d
e
- f
" "nested list and quote": document: createDocument(["ab3", {}, ["bulletList", "bullet", "quote"]]) html: "
- #{blockComment}ab3
#{blockComment}ab3
#{blockComment}a
#{blockComment}b
" "nested unordered lists": document: createDocument(["a", {}, ["bulletList", "bullet"]], ["b", {}, ["bulletList", "bullet", "bulletList", "bullet"]], ["c", {}, ["bulletList", "bullet", "bulletList", "bullet"]]) html: "
- #{blockComment}a
- #{blockComment}b
#{blockComment}
a
#{blockComment}" "blocks beginning with formatted text": document: createDocument(["a", { bold: true }, ["quote"]], ["b", { italic: true }, []], ["c", { bold: true }, ["quote"]]) html: "
c
#{blockComment}a
#{blockComment}c" "text with newlines before block": document: createDocument(["a\nb"], ["c", {}, ["quote"]]) html: "
#{blockComment}c" "empty heading block": document: createDocument(["", {}, ["heading1"]]) html: "