bookish-press 0.4.0 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/components/Auth.svelte +27 -24
- package/components/Auth.svelte.d.ts +4 -4
- package/components/Authentication.d.ts +2 -2
- package/components/BookPreview.svelte +75 -59
- package/components/BookPreview.svelte.d.ts +5 -5
- package/components/External.svelte +1 -1
- package/components/External.svelte.d.ts +3 -3
- package/components/Link.svelte +49 -3
- package/components/Link.svelte.d.ts +3 -4
- package/components/app/BookList.svelte +19 -0
- package/components/app/BookList.svelte.d.ts +18 -0
- package/components/app/Button.svelte +49 -0
- package/components/app/Button.svelte.d.ts +22 -0
- package/components/app/Feedback.svelte +47 -0
- package/components/app/Feedback.svelte.d.ts +18 -0
- package/components/app/Head.svelte +15 -0
- package/components/app/Head.svelte.d.ts +18 -0
- package/components/app/Large.svelte +8 -0
- package/components/app/Large.svelte.d.ts +27 -0
- package/components/app/Lead.svelte +12 -0
- package/components/app/Lead.svelte.d.ts +27 -0
- package/components/app/Link.svelte +24 -0
- package/components/app/Link.svelte.d.ts +20 -0
- package/components/app/Options.svelte +24 -0
- package/components/app/Options.svelte.d.ts +19 -0
- package/components/app/Paragraph.svelte +20 -0
- package/components/app/Paragraph.svelte.d.ts +18 -0
- package/components/app/Section.svelte +12 -0
- package/components/app/Section.svelte.d.ts +27 -0
- package/components/app/Table.svelte +32 -0
- package/components/app/Table.svelte.d.ts +27 -0
- package/components/app/TextInput.svelte +38 -0
- package/components/app/TextInput.svelte.d.ts +22 -0
- package/components/chapter/Atom.svelte +20 -6
- package/components/chapter/Atom.svelte.d.ts +3 -3
- package/components/chapter/Block.svelte +26 -21
- package/components/chapter/Block.svelte.d.ts +4 -4
- package/components/chapter/Callout.svelte +38 -7
- package/components/chapter/Callout.svelte.d.ts +4 -4
- package/components/chapter/CaptionedCode.svelte +67 -24
- package/components/chapter/CaptionedCode.svelte.d.ts +4 -4
- package/components/chapter/ChapterBody.svelte +62 -9
- package/components/chapter/ChapterBody.svelte.d.ts +5 -4
- package/components/chapter/Citations.svelte +86 -20
- package/components/chapter/Citations.svelte.d.ts +4 -4
- package/components/chapter/Code.svelte +152 -21
- package/components/chapter/Code.svelte.d.ts +3 -3
- package/components/chapter/Comment.svelte +39 -17
- package/components/chapter/Comment.svelte.d.ts +3 -3
- package/components/chapter/Definition.svelte +52 -18
- package/components/chapter/Definition.svelte.d.ts +5 -8
- package/components/chapter/Embed.svelte +155 -67
- package/components/chapter/Embed.svelte.d.ts +6 -4
- package/components/chapter/ErrorMessage.svelte +7 -2
- package/components/chapter/ErrorMessage.svelte.d.ts +4 -4
- package/components/chapter/ExtendedPrism.d.ts +2 -0
- package/components/chapter/ExtendedPrism.js +69 -0
- package/components/chapter/Figure.svelte +90 -0
- package/components/chapter/Figure.svelte.d.ts +24 -0
- package/components/chapter/Footnote.svelte +75 -12
- package/components/chapter/Footnote.svelte.d.ts +4 -4
- package/components/chapter/Format.svelte +63 -38
- package/components/chapter/Format.svelte.d.ts +5 -4
- package/components/chapter/InlineCode.svelte +16 -6
- package/components/chapter/InlineCode.svelte.d.ts +4 -4
- package/components/chapter/Label.svelte +38 -9
- package/components/chapter/Label.svelte.d.ts +4 -4
- package/components/chapter/Link.svelte +24 -19
- package/components/chapter/Link.svelte.d.ts +4 -4
- package/components/chapter/List.svelte +75 -8
- package/components/chapter/List.svelte.d.ts +4 -4
- package/components/chapter/Marginal.svelte +169 -27
- package/components/chapter/Marginal.svelte.d.ts +6 -3
- package/components/chapter/Paragraph.svelte +79 -6
- package/components/chapter/Paragraph.svelte.d.ts +4 -4
- package/components/chapter/Positioned.svelte +33 -0
- package/components/chapter/Positioned.svelte.d.ts +19 -0
- package/components/chapter/Problem.svelte +15 -0
- package/components/chapter/Problem.svelte.d.ts +27 -0
- package/components/chapter/Python.svelte +68 -21
- package/components/chapter/Python.svelte.d.ts +4 -4
- package/components/chapter/Quote.svelte +64 -11
- package/components/chapter/Quote.svelte.d.ts +4 -4
- package/components/chapter/Rule.svelte +12 -1
- package/components/chapter/Rule.svelte.d.ts +4 -4
- package/components/chapter/Table.svelte +36 -25
- package/components/chapter/Table.svelte.d.ts +4 -4
- package/components/chapter/Text.svelte +61 -36
- package/components/chapter/Text.svelte.d.ts +5 -4
- package/components/editor/BookishEditor.svelte +373 -244
- package/components/editor/BookishEditor.svelte.d.ts +9 -6
- package/components/editor/CalloutEditor.svelte +5 -5
- package/components/editor/CalloutEditor.svelte.d.ts +4 -4
- package/components/editor/CaptionedCodeEditor.svelte +16 -12
- package/components/editor/CaptionedCodeEditor.svelte.d.ts +4 -4
- package/components/editor/CaretContext.d.ts +48 -16
- package/components/editor/CaretState.d.ts +16 -44
- package/components/editor/CaretUtilities.d.ts +2 -2
- package/components/editor/CaretView.svelte +82 -0
- package/components/editor/CaretView.svelte.d.ts +25 -0
- package/components/editor/CitationsEditor.svelte +36 -25
- package/components/editor/CitationsEditor.svelte.d.ts +4 -4
- package/components/editor/Clipboard.d.ts +2 -2
- package/components/editor/Command.d.ts +13 -12
- package/components/editor/Commands.d.ts +1 -1
- package/components/editor/Commands.js +1114 -571
- package/components/editor/ConfirmButton.svelte +18 -12
- package/components/editor/ConfirmButton.svelte.d.ts +5 -4
- package/components/editor/DefinitionEditor.svelte +29 -21
- package/components/editor/DefinitionEditor.svelte.d.ts +4 -4
- package/components/editor/EmbedEditor.svelte +93 -43
- package/components/editor/EmbedEditor.svelte.d.ts +3 -3
- package/components/editor/Icon.svelte +17 -0
- package/components/editor/Icon.svelte.d.ts +16 -0
- package/components/editor/ImageChooser.svelte +53 -34
- package/components/editor/ImageChooser.svelte.d.ts +3 -3
- package/components/editor/InlineCodeEditor.svelte +7 -4
- package/components/editor/InlineCodeEditor.svelte.d.ts +4 -4
- package/components/editor/LabelEditor.svelte +20 -11
- package/components/editor/LabelEditor.svelte.d.ts +4 -4
- package/components/editor/LanguageEditor.svelte +10 -7
- package/components/editor/LanguageEditor.svelte.d.ts +3 -3
- package/components/editor/LinkEditor.svelte +64 -39
- package/components/editor/LinkEditor.svelte.d.ts +4 -4
- package/components/editor/Note.svelte +4 -3
- package/components/editor/Note.svelte.d.ts +6 -2
- package/components/editor/Permissions.svelte +95 -0
- package/components/editor/Permissions.svelte.d.ts +20 -0
- package/components/editor/PositionEditor.svelte +9 -6
- package/components/editor/PositionEditor.svelte.d.ts +4 -4
- package/components/editor/QuoteEditor.svelte +7 -2
- package/components/editor/QuoteEditor.svelte.d.ts +4 -4
- package/components/editor/Switch.svelte +55 -28
- package/components/editor/Switch.svelte.d.ts +4 -4
- package/components/editor/TableEditor.svelte +10 -0
- package/components/editor/TableEditor.svelte.d.ts +17 -0
- package/components/editor/TextEditor.svelte +83 -45
- package/components/editor/TextEditor.svelte.d.ts +5 -4
- package/components/editor/Toggle.svelte +11 -8
- package/components/editor/Toggle.svelte.d.ts +4 -4
- package/components/editor/Toolbar.svelte +191 -144
- package/components/editor/Toolbar.svelte.d.ts +5 -8
- package/components/editor/ToolbarGroup.svelte +17 -23
- package/components/editor/ToolbarGroup.svelte.d.ts +3 -4
- package/components/editor/ToolbarSpacer.svelte +8 -1
- package/components/editor/ToolbarSpacer.svelte.d.ts +6 -2
- package/components/editor/URLEditor.svelte +6 -8
- package/components/editor/URLEditor.svelte.d.ts +3 -3
- package/components/editor/UndoState.d.ts +3 -3
- package/components/editor/icons/annotate.svg +1 -0
- package/components/editor/icons/block.svg +1 -0
- package/components/editor/icons/bold.svg +1 -0
- package/components/editor/icons/bullets.svg +1 -0
- package/components/editor/icons/callout.svg +1 -0
- package/components/editor/icons/citation.svg +8 -0
- package/components/editor/icons/clear.svg +1 -0
- package/components/editor/icons/clipboard.svg +1 -0
- package/components/editor/icons/code.svg +1 -0
- package/components/editor/icons/columnafter.svg +1 -0
- package/components/editor/icons/columnbefore.svg +1 -0
- package/components/editor/icons/comment.svg +1 -0
- package/components/editor/icons/copy.svg +1 -0
- package/components/editor/icons/cut.svg +1 -0
- package/components/editor/icons/define.svg +7 -0
- package/components/editor/icons/deletecolumn.svg +1 -0
- package/components/editor/icons/deleterow.svg +1 -0
- package/components/editor/icons/footnote.svg +8 -0
- package/components/editor/icons/header1.svg +7 -0
- package/components/editor/icons/header2.svg +7 -0
- package/components/editor/icons/header3.svg +7 -0
- package/components/editor/icons/home.svg +1 -0
- package/components/editor/icons/indent.svg +1 -0
- package/components/editor/icons/italic.svg +1 -0
- package/components/editor/icons/label.svg +1 -0
- package/components/editor/icons/left.svg +1 -0
- package/components/editor/icons/level.svg +1 -0
- package/components/editor/icons/link.svg +1 -0
- package/components/editor/icons/list.svg +1 -0
- package/components/editor/icons/media.svg +1 -0
- package/components/editor/icons/middle.svg +1 -0
- package/components/editor/icons/numbers.svg +10 -0
- package/components/editor/icons/paragraph.svg +1 -0
- package/components/editor/icons/paste.svg +10 -0
- package/components/editor/icons/quote.svg +1 -0
- package/components/editor/icons/redo.svg +1 -0
- package/components/editor/icons/right.svg +1 -0
- package/components/editor/icons/rowabove.svg +1 -0
- package/components/editor/icons/rowbelow.svg +1 -0
- package/components/editor/icons/rule.svg +1 -0
- package/components/editor/icons/sub.svg +1 -0
- package/components/editor/icons/super.svg +1 -0
- package/components/editor/icons/table.svg +1 -0
- package/components/editor/icons/text.svg +1 -0
- package/components/editor/icons/time.svg +1 -0
- package/components/editor/icons/undo.svg +1 -0
- package/components/editor/icons/unindent.svg +1 -0
- package/components/editor/icons/unlink.svg +1 -0
- package/components/page/Acknowledgements.svelte +35 -24
- package/components/page/Acknowledgements.svelte.d.ts +4 -4
- package/components/page/Authors.svelte +34 -17
- package/components/page/Authors.svelte.d.ts +7 -6
- package/components/page/BookLoader.svelte +59 -0
- package/components/page/BookLoader.svelte.d.ts +16 -0
- package/components/page/BulkReferenceEditor.svelte +54 -23
- package/components/page/BulkReferenceEditor.svelte.d.ts +4 -4
- package/components/page/Chapter.svelte +234 -143
- package/components/page/Chapter.svelte.d.ts +3 -3
- package/components/page/ChapterContext.d.ts +4 -4
- package/components/page/ChapterNumber.svelte +9 -0
- package/components/page/ChapterNumber.svelte.d.ts +27 -0
- package/components/page/ChapterTitle.svelte +16 -0
- package/components/page/ChapterTitle.svelte.d.ts +18 -0
- package/components/page/Contexts.d.ts +42 -22
- package/components/page/Contexts.js +129 -17
- package/components/page/DefinitionView.svelte +129 -90
- package/components/page/DefinitionView.svelte.d.ts +3 -3
- package/components/page/Description.svelte +31 -19
- package/components/page/Description.svelte.d.ts +4 -4
- package/components/page/Edition.svelte +135 -80
- package/components/page/Edition.svelte.d.ts +5 -6
- package/components/page/EditionLoader.svelte +99 -0
- package/components/page/EditionLoader.svelte.d.ts +18 -0
- package/components/page/Editions.svelte +106 -0
- package/components/page/Editions.svelte.d.ts +14 -0
- package/components/page/Glossary.svelte +65 -49
- package/components/page/Glossary.svelte.d.ts +4 -4
- package/components/page/Header.svelte +143 -56
- package/components/page/Header.svelte.d.ts +8 -6
- package/components/page/Index.svelte +116 -80
- package/components/page/Index.svelte.d.ts +4 -4
- package/components/page/Instructions.svelte +18 -17
- package/components/page/Instructions.svelte.d.ts +6 -4
- package/components/page/License.svelte +39 -23
- package/components/page/License.svelte.d.ts +4 -4
- package/components/page/Loading.svelte +102 -12
- package/components/page/Loading.svelte.d.ts +6 -2
- package/components/page/Media.svelte +81 -53
- package/components/page/Media.svelte.d.ts +4 -4
- package/components/page/MediaPreview.svelte +26 -8
- package/components/page/MediaPreview.svelte.d.ts +3 -3
- package/components/page/Muted.svelte +10 -0
- package/components/page/Muted.svelte.d.ts +27 -0
- package/components/page/Outline.svelte +279 -59
- package/components/page/Outline.svelte.d.ts +3 -3
- package/components/page/Page.svelte +40 -9
- package/components/page/Page.svelte.d.ts +3 -3
- package/components/page/PageHeader.svelte +14 -0
- package/components/page/PageHeader.svelte.d.ts +18 -0
- package/components/page/PageParagraph.svelte +18 -0
- package/components/page/PageParagraph.svelte.d.ts +27 -0
- package/components/page/PossibleChapter.svelte +7 -7
- package/components/page/PossibleChapter.svelte.d.ts +4 -4
- package/components/page/PossibleReference.svelte +6 -11
- package/components/page/PossibleReference.svelte.d.ts +6 -7
- package/components/page/Print.svelte +27 -3
- package/components/page/Print.svelte.d.ts +4 -4
- package/components/page/Publish.svelte +134 -0
- package/components/page/Publish.svelte.d.ts +14 -0
- package/components/page/Reference.svelte +259 -117
- package/components/page/Reference.svelte.d.ts +5 -5
- package/components/page/References.svelte +45 -48
- package/components/page/References.svelte.d.ts +4 -4
- package/components/page/Rows.svelte +54 -0
- package/components/page/Rows.svelte.d.ts +27 -0
- package/components/page/Search.svelte +88 -63
- package/components/page/Search.svelte.d.ts +4 -4
- package/components/page/Status.svelte +46 -39
- package/components/page/Status.svelte.d.ts +4 -9
- package/components/page/SubdomainEditor.svelte +41 -27
- package/components/page/SubdomainEditor.svelte.d.ts +4 -4
- package/components/page/TableOfContents.svelte +264 -191
- package/components/page/TableOfContents.svelte.d.ts +4 -4
- package/components/page/TableOfContentsImage.svelte +8 -8
- package/components/page/TableOfContentsImage.svelte.d.ts +3 -3
- package/components/page/TableOfContentsRow.svelte +97 -34
- package/components/page/TableOfContentsRow.svelte.d.ts +4 -4
- package/components/page/ThemeEditor.svelte +177 -39
- package/components/page/ThemeEditor.svelte.d.ts +4 -4
- package/components/page/ThemeEditorPreview.svelte +35 -23
- package/components/page/ThemeEditorPreview.svelte.d.ts +5 -5
- package/components/page/ThemeSetEditor.svelte +15 -13
- package/components/page/ThemeSetEditor.svelte.d.ts +4 -4
- package/components/page/ThemeVariableEditor.svelte +24 -15
- package/components/page/ThemeVariableEditor.svelte.d.ts +3 -3
- package/components/page/Title.svelte +12 -0
- package/components/page/Title.svelte.d.ts +27 -0
- package/components/page/Unknown.svelte +28 -21
- package/components/page/Unknown.svelte.d.ts +4 -4
- package/components/page/margins.js +50 -33
- package/index.d.ts +13 -0
- package/index.js +14 -0
- package/models/CRUD.d.ts +27 -0
- package/models/CRUD.js +262 -0
- package/models/Firebase.d.ts +1 -0
- package/models/Firebase.js +26 -16
- package/models/book/Book.d.ts +40 -39
- package/models/book/Book.js +121 -121
- package/models/book/BookMedia.d.ts +3 -3
- package/models/book/BookMedia.js +22 -16
- package/models/book/BookSaveStatus.d.ts +7 -0
- package/models/book/BookSaveStatus.js +8 -0
- package/models/book/Chapter.d.ts +50 -39
- package/models/book/Chapter.js +189 -198
- package/models/book/ChapterID.js +7 -7
- package/models/book/Definition.d.ts +1 -1
- package/models/book/Edition.d.ts +87 -61
- package/models/book/Edition.js +460 -309
- package/models/book/Reference.d.ts +24 -0
- package/models/book/Reference.js +78 -0
- package/models/book/Schema.d.ts +168 -0
- package/models/book/Schema.js +115 -0
- package/models/book/Theme.d.ts +44 -37
- package/models/book/Theme.js +452 -52
- package/models/book/ThemeColors.d.ts +1 -1
- package/models/book/Words.d.ts +2 -0
- package/models/book/Words.js +110 -0
- package/models/chapter/AtomNode.d.ts +4 -4
- package/models/chapter/AtomNode.js +20 -13
- package/models/chapter/BlockNode.d.ts +9 -10
- package/models/chapter/BlockNode.js +32 -13
- package/models/chapter/BlocksNode.d.ts +10 -10
- package/models/chapter/BlocksNode.js +315 -120
- package/models/chapter/BlocksNode.test.js +494 -228
- package/models/chapter/Bookkeeping.d.ts +1 -1
- package/models/chapter/CalloutNode.d.ts +3 -3
- package/models/chapter/CalloutNode.js +34 -12
- package/models/chapter/Caret.d.ts +9 -7
- package/models/chapter/Caret.js +11 -6
- package/models/chapter/ChapterNode.d.ts +11 -11
- package/models/chapter/ChapterNode.js +70 -33
- package/models/chapter/CitationsNode.d.ts +3 -3
- package/models/chapter/CitationsNode.js +31 -12
- package/models/chapter/CodeNode.d.ts +11 -6
- package/models/chapter/CodeNode.js +143 -34
- package/models/chapter/CommentNode.d.ts +5 -5
- package/models/chapter/CommentNode.js +29 -13
- package/models/chapter/DefinitionNode.d.ts +2 -2
- package/models/chapter/DefinitionNode.js +15 -7
- package/models/chapter/Edit.d.ts +3 -3
- package/models/chapter/EmbedNode.d.ts +9 -5
- package/models/chapter/EmbedNode.js +108 -35
- package/models/chapter/ErrorNode.d.ts +2 -2
- package/models/chapter/ErrorNode.js +34 -12
- package/models/chapter/FootnoteNode.d.ts +5 -5
- package/models/chapter/FootnoteNode.js +34 -16
- package/models/chapter/FormatNode.d.ts +10 -10
- package/models/chapter/FormatNode.js +237 -106
- package/models/chapter/FormatNode.test.js +87 -45
- package/models/chapter/InlineCodeNode.d.ts +2 -2
- package/models/chapter/InlineCodeNode.js +22 -9
- package/models/chapter/LabelNode.d.ts +4 -4
- package/models/chapter/LabelNode.js +31 -13
- package/models/chapter/LinkNode.d.ts +2 -2
- package/models/chapter/LinkNode.js +21 -9
- package/models/chapter/ListNode.d.ts +8 -8
- package/models/chapter/ListNode.js +99 -38
- package/models/chapter/ListNode.test.js +29 -24
- package/models/chapter/MetadataNode.d.ts +3 -3
- package/models/chapter/MetadataNode.js +13 -5
- package/models/chapter/Node.d.ts +5 -3
- package/models/chapter/Node.js +76 -29
- package/models/chapter/Node.test.js +20 -18
- package/models/chapter/ParagraphNode.d.ts +6 -6
- package/models/chapter/ParagraphNode.js +84 -29
- package/models/chapter/ParagraphNode.test.js +22 -13
- package/models/chapter/Parser.d.ts +27 -27
- package/models/chapter/Parser.js +220 -206
- package/models/chapter/Parser.test.js +16 -16
- package/models/chapter/Position.d.ts +1 -1
- package/models/chapter/QuoteNode.d.ts +6 -6
- package/models/chapter/QuoteNode.js +61 -23
- package/models/chapter/RootNode.d.ts +4 -4
- package/models/chapter/RuleNode.d.ts +2 -2
- package/models/chapter/RuleNode.js +31 -11
- package/models/chapter/TableNode.d.ts +8 -6
- package/models/chapter/TableNode.js +89 -34
- package/models/chapter/TableNode.test.js +22 -24
- package/models/chapter/TextNode.d.ts +6 -6
- package/models/chapter/TextNode.js +72 -32
- package/models/chapter/TextNode.test.js +4 -4
- package/package.json +108 -26
- package/util/getSubdomain.js +8 -6
- package/util/isMobile.js +1 -1
- package/util/mineReference.d.ts +3 -2
- package/util/mineReference.js +67 -29
- package/util/scrollToEyeLevel.js +6 -1
- package/components/chapter/renderPosition.d.ts +0 -3
- package/components/chapter/renderPosition.js +0 -4
- package/components/editor/ToolbarIcon.svelte +0 -22
- package/components/editor/ToolbarIcon.svelte.d.ts +0 -16
- package/components/page/Alert.svelte +0 -11
- package/components/page/Alert.svelte.d.ts +0 -23
- package/components/page/Revisions.svelte +0 -124
- package/components/page/Revisions.svelte.d.ts +0 -14
- package/models/BookLoader.d.ts +0 -2
- package/models/BookLoader.js +0 -67
- package/models/Firestore.d.ts +0 -22
- package/models/Firestore.js +0 -194
- package/models/chapter/ReferenceNode.d.ts +0 -29
- package/models/chapter/ReferenceNode.js +0 -48
- package/models/loadEdition.d.ts +0 -5
- package/models/loadEdition.js +0 -16
|
@@ -1,302 +1,568 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
|
-
import CalloutNode from
|
|
3
|
-
import ChapterNode from
|
|
4
|
-
import CodeNode from
|
|
5
|
-
import EmbedNode from
|
|
6
|
-
import FootnoteNode from
|
|
7
|
-
import FormatNode from
|
|
8
|
-
import ListNode from
|
|
9
|
-
import ParagraphNode from
|
|
2
|
+
import CalloutNode from './CalloutNode';
|
|
3
|
+
import ChapterNode from './ChapterNode';
|
|
4
|
+
import CodeNode from './CodeNode';
|
|
5
|
+
import EmbedNode from './EmbedNode';
|
|
6
|
+
import FootnoteNode from './FootnoteNode';
|
|
7
|
+
import FormatNode from './FormatNode';
|
|
8
|
+
import ListNode from './ListNode';
|
|
9
|
+
import ParagraphNode from './ParagraphNode';
|
|
10
10
|
import Parser from './Parser';
|
|
11
|
-
import QuoteNode from
|
|
12
|
-
import RuleNode from
|
|
13
|
-
import TableNode from
|
|
14
|
-
import TextNode from
|
|
15
|
-
const firstText =
|
|
11
|
+
import QuoteNode from './QuoteNode';
|
|
12
|
+
import RuleNode from './RuleNode';
|
|
13
|
+
import TableNode from './TableNode';
|
|
14
|
+
import TextNode from './TextNode';
|
|
15
|
+
const firstText = 'First paragraph.';
|
|
16
16
|
const firstTextNode = new TextNode(firstText);
|
|
17
|
-
const firstFormat = new FormatNode(
|
|
17
|
+
const firstFormat = new FormatNode('', [firstTextNode]);
|
|
18
18
|
const firstParagraph = new ParagraphNode(0, firstFormat);
|
|
19
|
-
const lastText =
|
|
19
|
+
const lastText = 'Last paragraph.';
|
|
20
20
|
const lastTextNode = new TextNode(lastText);
|
|
21
|
-
const lastFormat = new FormatNode(
|
|
21
|
+
const lastFormat = new FormatNode('', [lastTextNode]);
|
|
22
22
|
const lastParagraph = new ParagraphNode(0, lastFormat);
|
|
23
|
-
const footnoteText = new TextNode(
|
|
24
|
-
const footnote = new FootnoteNode(new FormatNode(
|
|
23
|
+
const footnoteText = new TextNode('This is my footnote.');
|
|
24
|
+
const footnote = new FootnoteNode(new FormatNode('', [footnoteText]));
|
|
25
25
|
const paragraphChapter = new ChapterNode([firstParagraph, lastParagraph]);
|
|
26
26
|
const numberedList = new ListNode([firstFormat, lastFormat], true);
|
|
27
27
|
const bulletedList = new ListNode([firstFormat.copy(), lastFormat.copy()], false);
|
|
28
|
-
const beforeBold = new TextNode(
|
|
29
|
-
const bold = new TextNode(
|
|
30
|
-
const afterBold = new TextNode(
|
|
31
|
-
const boldChapter = new ChapterNode([
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
const beforeBold = new TextNode('I am a ');
|
|
29
|
+
const bold = new TextNode('bold');
|
|
30
|
+
const afterBold = new TextNode(' word.');
|
|
31
|
+
const boldChapter = new ChapterNode([
|
|
32
|
+
new ParagraphNode(0, new FormatNode('', [beforeBold, new FormatNode('*', [bold]), afterBold])),
|
|
33
|
+
]);
|
|
34
|
+
const itemOneTextNode = new TextNode('one');
|
|
35
|
+
const itemOneFormat = new FormatNode('', [itemOneTextNode]);
|
|
36
|
+
const itemTwoTextNode = new TextNode('two');
|
|
37
|
+
const itemTwoFormat = new FormatNode('', [itemTwoTextNode]);
|
|
38
|
+
const paragraphListChapter = new ChapterNode([
|
|
39
|
+
firstParagraph,
|
|
40
|
+
new ListNode([itemOneFormat, itemTwoFormat], true),
|
|
41
|
+
lastParagraph,
|
|
42
|
+
]);
|
|
43
|
+
test('Insert a block', () => {
|
|
44
|
+
expect(paragraphChapter
|
|
45
|
+
.withBlockInserted(firstParagraph, new RuleNode(), true)
|
|
46
|
+
?.toBookdown()).toBe(`-\n\n${firstText}\n\n${lastText}`);
|
|
47
|
+
expect(paragraphChapter
|
|
48
|
+
.withBlockInserted(firstParagraph, new RuleNode(), false)
|
|
49
|
+
?.toBookdown()).toBe(`${firstText}\n\n-\n\n${lastText}`);
|
|
50
|
+
expect(paragraphChapter
|
|
51
|
+
.withBlockInserted(lastParagraph, new RuleNode(), false)
|
|
52
|
+
?.toBookdown()).toBe(`${firstText}\n\n${lastText}\n\n-`);
|
|
36
53
|
});
|
|
37
|
-
test(
|
|
54
|
+
test('Remove a block', () => {
|
|
38
55
|
expect(paragraphChapter.withoutBlock(firstParagraph)?.toBookdown()).toBe(lastText);
|
|
39
56
|
});
|
|
40
|
-
test(
|
|
41
|
-
expect(
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
test('Remove all blocks', () => {
|
|
58
|
+
expect(paragraphChapter
|
|
59
|
+
.withoutRange({
|
|
60
|
+
start: { node: firstTextNode, index: 0 },
|
|
61
|
+
end: { node: lastTextNode, index: lastText.length },
|
|
62
|
+
})
|
|
63
|
+
?.root.toBookdown()).toBe('');
|
|
44
64
|
});
|
|
45
|
-
test(
|
|
65
|
+
test('Merge adjascent lists', () => {
|
|
66
|
+
expect(new ChapterNode([numberedList, bulletedList]).toBookdown()).toBe(`1. ${firstText}\n2. ${lastText}\n\n* ${firstText}\n* ${lastText}`);
|
|
67
|
+
expect(new ChapterNode([numberedList, numberedList]).toBookdown()).toBe(`1. ${firstText}\n2. ${lastText}\n3. ${firstText}\n4. ${lastText}`);
|
|
68
|
+
expect(new ChapterNode([bulletedList, bulletedList]).toBookdown()).toBe(`* ${firstText}\n* ${lastText}\n* ${firstText}\n* ${lastText}`);
|
|
69
|
+
});
|
|
70
|
+
test('Delete across start of paragraph/list boundary', () => {
|
|
71
|
+
expect(paragraphListChapter
|
|
72
|
+
.withoutRange({
|
|
73
|
+
start: { node: firstTextNode, index: 1 },
|
|
74
|
+
end: { node: itemOneTextNode, index: 1 },
|
|
75
|
+
})
|
|
76
|
+
?.root.toBookdown()).toBe('F\n\nne\n\n1. two\n\nLast paragraph.');
|
|
77
|
+
});
|
|
78
|
+
test('Delete across end of paragraph/list boundary', () => {
|
|
79
|
+
expect(paragraphListChapter
|
|
80
|
+
.withoutRange({
|
|
81
|
+
start: { node: itemOneTextNode, index: 1 },
|
|
82
|
+
end: { node: lastTextNode, index: 1 },
|
|
83
|
+
})
|
|
84
|
+
?.root.toBookdown()).toBe('First paragraph.\n\n1. o\n\nast paragraph.');
|
|
85
|
+
});
|
|
86
|
+
test('Format range', () => {
|
|
46
87
|
// Bold part of a paragraph.
|
|
47
|
-
expect(paragraphChapter
|
|
48
|
-
.
|
|
88
|
+
expect(paragraphChapter
|
|
89
|
+
.withRangeFormatted({
|
|
90
|
+
start: { node: firstTextNode, index: 6 },
|
|
91
|
+
end: { node: firstTextNode, index: 10 },
|
|
92
|
+
}, '*')
|
|
93
|
+
?.root.toBookdown()).toBe(`First *para*graph.\n\n${lastText}`);
|
|
49
94
|
// Remove part of a paragraph.
|
|
50
|
-
expect(paragraphChapter
|
|
51
|
-
.
|
|
95
|
+
expect(paragraphChapter
|
|
96
|
+
.withRangeFormatted({
|
|
97
|
+
start: { node: firstTextNode, index: 6 },
|
|
98
|
+
end: { node: firstTextNode, index: 10 },
|
|
99
|
+
}, undefined)
|
|
100
|
+
?.root.toBookdown()).toBe(`First graph.\n\n${lastText}`);
|
|
52
101
|
// Unbold the bold part of a paragraph with the selection outside the bold.
|
|
53
|
-
expect(boldChapter
|
|
54
|
-
.
|
|
102
|
+
expect(boldChapter
|
|
103
|
+
.withRangeFormatted({
|
|
104
|
+
start: { node: beforeBold, index: beforeBold.getLength() },
|
|
105
|
+
end: { node: afterBold, index: 0 },
|
|
106
|
+
}, '')
|
|
107
|
+
?.root.toBookdown()).toBe(`I am a bold word.`);
|
|
55
108
|
// Unbold the bold part of a paragraph with the selection inside the bold.
|
|
56
|
-
expect(boldChapter
|
|
57
|
-
.
|
|
109
|
+
expect(boldChapter
|
|
110
|
+
.withRangeFormatted({
|
|
111
|
+
start: { node: bold, index: 0 },
|
|
112
|
+
end: { node: bold, index: bold.getLength() },
|
|
113
|
+
}, '')
|
|
114
|
+
?.root.toBookdown()).toBe(`I am a bold word.`);
|
|
58
115
|
// Expand the bold part of a paragraph.
|
|
59
|
-
expect(boldChapter
|
|
60
|
-
.
|
|
116
|
+
expect(boldChapter
|
|
117
|
+
.withRangeFormatted({
|
|
118
|
+
start: {
|
|
119
|
+
node: beforeBold,
|
|
120
|
+
index: beforeBold.getLength() - 2,
|
|
121
|
+
},
|
|
122
|
+
end: { node: afterBold, index: 0 },
|
|
123
|
+
}, '*')
|
|
124
|
+
?.root.toBookdown()).toBe(`I am *a bold* word.`);
|
|
61
125
|
// Delete across a paragraph boundary.
|
|
62
|
-
expect(paragraphChapter
|
|
63
|
-
.
|
|
126
|
+
expect(paragraphChapter
|
|
127
|
+
.withoutRange({
|
|
128
|
+
start: { node: firstTextNode, index: 6 },
|
|
129
|
+
end: { node: lastTextNode, index: 5 },
|
|
130
|
+
})
|
|
131
|
+
?.root.toBookdown()).toBe(`First paragraph.`);
|
|
64
132
|
// Bold across a paragraph boundary.
|
|
65
|
-
expect(paragraphChapter
|
|
66
|
-
.
|
|
133
|
+
expect(paragraphChapter
|
|
134
|
+
.withRangeFormatted({
|
|
135
|
+
start: { node: firstTextNode, index: 6 },
|
|
136
|
+
end: { node: lastTextNode, index: 4 },
|
|
137
|
+
}, '*')
|
|
138
|
+
?.root.toBookdown()).toBe(`First *paragraph.*\n\n*Last* paragraph.`);
|
|
67
139
|
});
|
|
68
|
-
test(
|
|
140
|
+
test('Split selection', () => {
|
|
69
141
|
const caret = { node: firstTextNode, index: 5 };
|
|
70
142
|
const chapter = new ChapterNode([firstParagraph]);
|
|
71
143
|
// Split a paragraph
|
|
72
144
|
const split = chapter.withSelectionSplit({ start: caret, end: caret });
|
|
73
|
-
expect(split?.root.toBookdown()).toBe(
|
|
74
|
-
expect(split?.range.start.node.toBookdown()).toBe(
|
|
145
|
+
expect(split?.root.toBookdown()).toBe('First\n\n paragraph.');
|
|
146
|
+
expect(split?.range.start.node.toBookdown()).toBe(' paragraph.');
|
|
75
147
|
expect(split?.range.start.index).toBe(0);
|
|
76
148
|
// Delete a selection and then split
|
|
77
|
-
const selectSplit = chapter.withSelectionSplit({
|
|
78
|
-
|
|
149
|
+
const selectSplit = chapter.withSelectionSplit({
|
|
150
|
+
start: { node: firstTextNode, index: 5 },
|
|
151
|
+
end: { node: firstTextNode, index: 10 },
|
|
152
|
+
});
|
|
153
|
+
expect(selectSplit?.root.toBookdown()).toBe('First\n\ngraph.');
|
|
79
154
|
// Split at the beginning
|
|
80
155
|
const startCaret = { node: firstTextNode, index: 0 };
|
|
81
|
-
const startSplit = chapter.withSelectionSplit({
|
|
156
|
+
const startSplit = chapter.withSelectionSplit({
|
|
157
|
+
start: startCaret,
|
|
158
|
+
end: startCaret,
|
|
159
|
+
});
|
|
82
160
|
expect(startSplit?.root.toBookdown()).toBe(`\n\n${firstText}`);
|
|
83
161
|
// Split at the end
|
|
84
162
|
const endCaret = { node: firstTextNode, index: 16 };
|
|
85
|
-
const endSplit = chapter.withSelectionSplit({
|
|
163
|
+
const endSplit = chapter.withSelectionSplit({
|
|
164
|
+
start: endCaret,
|
|
165
|
+
end: endCaret,
|
|
166
|
+
});
|
|
86
167
|
expect(endSplit?.root.toBookdown()).toBe(`${firstText}\n\n`);
|
|
87
168
|
});
|
|
88
|
-
test(
|
|
89
|
-
const chapterAtomEnd = new ChapterNode([
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
expect(
|
|
97
|
-
|
|
169
|
+
test('Without atom', () => {
|
|
170
|
+
const chapterAtomEnd = new ChapterNode([
|
|
171
|
+
new ParagraphNode(0, new FormatNode('', [firstFormat, footnote])),
|
|
172
|
+
]);
|
|
173
|
+
expect(chapterAtomEnd.withoutAtom(footnote)?.root.toBookdown()).toBe(`${firstText}`);
|
|
174
|
+
const chapterAtomBegin = new ChapterNode([
|
|
175
|
+
new ParagraphNode(0, new FormatNode('', [footnote, firstFormat])),
|
|
176
|
+
]);
|
|
177
|
+
expect(chapterAtomBegin.withoutAtom(footnote)?.root.toBookdown()).toBe(`${firstText}`);
|
|
178
|
+
const chapterAtomMiddle = new ChapterNode([
|
|
179
|
+
new ParagraphNode(0, new FormatNode('', [firstFormat, footnote, lastFormat])),
|
|
180
|
+
]);
|
|
181
|
+
expect(chapterAtomMiddle.withoutAtom(footnote)?.root.toBookdown()).toBe(`${firstText}${lastText}`);
|
|
98
182
|
});
|
|
99
|
-
test(
|
|
100
|
-
const endOfFirst = {
|
|
183
|
+
test('Insert atom', () => {
|
|
184
|
+
const endOfFirst = {
|
|
185
|
+
node: firstTextNode,
|
|
186
|
+
index: firstTextNode.getLength(),
|
|
187
|
+
};
|
|
101
188
|
// Insert empty footnote
|
|
102
|
-
expect(paragraphChapter
|
|
103
|
-
.
|
|
189
|
+
expect(paragraphChapter
|
|
190
|
+
.withSegmentAtSelection({ start: endOfFirst, end: endOfFirst }, (text) => new FootnoteNode(new FormatNode('', [new TextNode(text)])))
|
|
191
|
+
?.root.toBookdown()).toBe(`${firstText}{}\n\n${lastText}`);
|
|
104
192
|
// Convert selection to footnote
|
|
105
|
-
expect(paragraphChapter
|
|
106
|
-
.
|
|
193
|
+
expect(paragraphChapter
|
|
194
|
+
.withSegmentAtSelection({
|
|
195
|
+
start: { node: firstTextNode, index: 6 },
|
|
196
|
+
end: { node: firstTextNode, index: 15 },
|
|
197
|
+
}, (text) => new FootnoteNode(new FormatNode('', [new TextNode(text)])))
|
|
198
|
+
?.root.toBookdown()).toBe(`First {paragraph}.\n\n${lastText}`);
|
|
107
199
|
});
|
|
108
|
-
test(
|
|
200
|
+
test('Convert paragraphs to lists', () => {
|
|
109
201
|
// Convert a single paragraph to a list item.
|
|
110
|
-
expect(paragraphChapter
|
|
111
|
-
.
|
|
202
|
+
expect(paragraphChapter
|
|
203
|
+
.withParagraphsAsLists({
|
|
204
|
+
start: { node: firstTextNode, index: 0 },
|
|
205
|
+
end: { node: firstTextNode, index: 0 },
|
|
206
|
+
}, false)
|
|
207
|
+
?.toBookdown()).toBe(`* ${firstText}\n\n${lastText}`);
|
|
112
208
|
// Convert two paragraphs to a single list
|
|
113
|
-
expect(paragraphChapter
|
|
114
|
-
.
|
|
209
|
+
expect(paragraphChapter
|
|
210
|
+
.withParagraphsAsLists({
|
|
211
|
+
start: { node: firstTextNode, index: 0 },
|
|
212
|
+
end: { node: lastTextNode, index: 0 },
|
|
213
|
+
}, true)
|
|
214
|
+
?.toBookdown()).toBe(`1. ${firstText}\n2. ${lastText}`);
|
|
115
215
|
// Convert paragraphs that span a blocks boundary to separate lists.
|
|
116
|
-
expect(new ChapterNode([firstParagraph, new CalloutNode([lastParagraph])])
|
|
117
|
-
.
|
|
216
|
+
expect(new ChapterNode([firstParagraph, new CalloutNode([lastParagraph])])
|
|
217
|
+
.withParagraphsAsLists({
|
|
218
|
+
start: { node: firstTextNode, index: 0 },
|
|
219
|
+
end: { node: lastTextNode, index: 0 },
|
|
220
|
+
}, true)
|
|
221
|
+
?.toBookdown()).toBe(`1. ${firstText}\n\n=\n1. ${lastText}\n=`);
|
|
118
222
|
// Convert non-paragraphs to lists
|
|
119
|
-
expect(new ChapterNode([numberedList]).withParagraphsAsLists({
|
|
120
|
-
|
|
223
|
+
expect(new ChapterNode([numberedList]).withParagraphsAsLists({
|
|
224
|
+
start: { node: firstTextNode, index: 0 },
|
|
225
|
+
end: { node: lastTextNode, index: 0 },
|
|
226
|
+
}, true)).toBeUndefined();
|
|
121
227
|
});
|
|
122
|
-
test(
|
|
228
|
+
test('Convert lists to paragraphs', () => {
|
|
123
229
|
// Convert lists to paragraphs
|
|
124
|
-
expect(new ChapterNode([numberedList])
|
|
125
|
-
.
|
|
230
|
+
expect(new ChapterNode([numberedList])
|
|
231
|
+
.withListsAsParagraphs({
|
|
232
|
+
start: { node: firstTextNode, index: 0 },
|
|
233
|
+
end: { node: firstTextNode, index: 5 },
|
|
234
|
+
})
|
|
235
|
+
?.toBookdown()).toBe(`${firstText}\n\n${lastText}`);
|
|
126
236
|
// Convert both items to paragraphs.
|
|
127
|
-
expect(new ChapterNode([numberedList])
|
|
128
|
-
.
|
|
237
|
+
expect(new ChapterNode([numberedList])
|
|
238
|
+
.withListsAsParagraphs({
|
|
239
|
+
start: { node: firstTextNode, index: 0 },
|
|
240
|
+
end: { node: lastTextNode, index: 5 },
|
|
241
|
+
})
|
|
242
|
+
?.toBookdown()).toBe(`${firstText}\n\n${lastText}`);
|
|
129
243
|
// Convert non-list to paragraphs.
|
|
130
|
-
expect(paragraphChapter
|
|
131
|
-
.
|
|
244
|
+
expect(paragraphChapter
|
|
245
|
+
.withListsAsParagraphs({
|
|
246
|
+
start: { node: firstTextNode, index: 0 },
|
|
247
|
+
end: { node: lastTextNode, index: 5 },
|
|
248
|
+
})
|
|
249
|
+
?.toBookdown()).toBeUndefined();
|
|
132
250
|
// Convert two contiguous lists to paragraphs.
|
|
133
|
-
expect(new ChapterNode([numberedList, bulletedList])
|
|
134
|
-
.
|
|
251
|
+
expect(new ChapterNode([numberedList, bulletedList])
|
|
252
|
+
.withListsAsParagraphs({
|
|
253
|
+
start: { node: firstTextNode, index: 0 },
|
|
254
|
+
end: {
|
|
255
|
+
node: bulletedList
|
|
256
|
+
.getFirstItem()
|
|
257
|
+
?.getFirstTextNode(),
|
|
258
|
+
index: 0,
|
|
259
|
+
},
|
|
260
|
+
})
|
|
261
|
+
?.toBookdown()).toBe(`${firstText}\n\n${lastText}\n\n${firstText}\n\n${lastText}`);
|
|
135
262
|
// Convert two non-contiguous lists to paragraphs.
|
|
136
|
-
expect(new ChapterNode([
|
|
137
|
-
|
|
263
|
+
expect(new ChapterNode([
|
|
264
|
+
numberedList,
|
|
265
|
+
new ParagraphNode(0, new FormatNode('', [new TextNode('Intruder!')])),
|
|
266
|
+
bulletedList,
|
|
267
|
+
])
|
|
268
|
+
.withListsAsParagraphs({
|
|
269
|
+
start: { node: firstTextNode, index: 0 },
|
|
270
|
+
end: {
|
|
271
|
+
node: bulletedList
|
|
272
|
+
.getFirstItem()
|
|
273
|
+
?.getFirstTextNode(),
|
|
274
|
+
index: 0,
|
|
275
|
+
},
|
|
276
|
+
})
|
|
277
|
+
?.toBookdown()).toBe(`${firstText}\n\n${lastText}\n\nIntruder!\n\n${firstText}\n\n${lastText}`);
|
|
138
278
|
// Convert various subparts of a nested list into paragraphs.
|
|
139
|
-
const oneText = new TextNode(
|
|
140
|
-
const twoText = new TextNode(
|
|
141
|
-
const threeText = new TextNode(
|
|
142
|
-
const fourText = new TextNode(
|
|
143
|
-
const list = new ListNode([
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
279
|
+
const oneText = new TextNode('one');
|
|
280
|
+
const twoText = new TextNode('two');
|
|
281
|
+
const threeText = new TextNode('three');
|
|
282
|
+
const fourText = new TextNode('four');
|
|
283
|
+
const list = new ListNode([
|
|
284
|
+
new FormatNode('', [oneText]),
|
|
285
|
+
new ListNode([
|
|
286
|
+
new FormatNode('', [twoText]),
|
|
287
|
+
new FormatNode('', [threeText]),
|
|
288
|
+
], true),
|
|
289
|
+
new FormatNode('', [fourText]),
|
|
290
|
+
], true);
|
|
291
|
+
expect(new ChapterNode([list])
|
|
292
|
+
.withListsAsParagraphs({
|
|
293
|
+
start: { node: oneText, index: 0 },
|
|
294
|
+
end: { node: fourText, index: 0 },
|
|
295
|
+
})
|
|
296
|
+
?.toBookdown()).toBe(`${oneText.getText()}\n\n${twoText.getText()}\n\n${threeText.getText()}\n\n${fourText.getText()}`);
|
|
297
|
+
expect(new ChapterNode([list])
|
|
298
|
+
.withListsAsParagraphs({
|
|
299
|
+
start: { node: oneText, index: 0 },
|
|
300
|
+
end: { node: twoText, index: 0 },
|
|
301
|
+
})
|
|
302
|
+
?.toBookdown()).toBe(`${oneText.getText()}\n\n${twoText.getText()}\n\n${threeText.getText()}\n\n${fourText.getText()}`);
|
|
303
|
+
expect(new ChapterNode([list])
|
|
304
|
+
.withListsAsParagraphs({
|
|
305
|
+
start: { node: twoText, index: 0 },
|
|
306
|
+
end: { node: threeText, index: 0 },
|
|
307
|
+
})
|
|
308
|
+
?.toBookdown()).toBe(`${oneText.getText()}\n\n${twoText.getText()}\n\n${threeText.getText()}\n\n${fourText.getText()}`);
|
|
150
309
|
});
|
|
151
|
-
test(
|
|
152
|
-
expect(new ChapterNode([numberedList])
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
310
|
+
test('Indent/unindent list items', () => {
|
|
311
|
+
expect(new ChapterNode([numberedList])
|
|
312
|
+
.withListsIndented({
|
|
313
|
+
start: { node: firstTextNode, index: 0 },
|
|
314
|
+
end: { node: firstTextNode, index: 0 },
|
|
315
|
+
}, true)
|
|
316
|
+
?.toBookdown()).toBe('1.. First paragraph.\n2. Last paragraph.');
|
|
317
|
+
const indented = new ChapterNode([numberedList]).withListsIndented({
|
|
318
|
+
start: { node: firstTextNode, index: 0 },
|
|
319
|
+
end: { node: lastTextNode, index: 0 },
|
|
320
|
+
}, true);
|
|
321
|
+
expect(indented?.toBookdown()).toBe('1.. First paragraph.\n2.. Last paragraph.');
|
|
322
|
+
expect(indented
|
|
323
|
+
?.withListsIndented({
|
|
324
|
+
start: { node: firstTextNode, index: 0 },
|
|
325
|
+
end: { node: lastTextNode, index: 0 },
|
|
326
|
+
}, false)
|
|
327
|
+
?.toBookdown()).toBe('1. First paragraph.\n2. Last paragraph.');
|
|
156
328
|
});
|
|
157
|
-
test(
|
|
158
|
-
expect(new ChapterNode([numberedList])
|
|
159
|
-
.
|
|
329
|
+
test('Style lists', () => {
|
|
330
|
+
expect(new ChapterNode([numberedList])
|
|
331
|
+
.withListAsStyle(numberedList, false)
|
|
332
|
+
?.toBookdown()).toBe(`* ${firstText}\n* ${lastText}`);
|
|
160
333
|
});
|
|
161
|
-
test(
|
|
334
|
+
test('Backspace/delete', () => {
|
|
162
335
|
const chapter = new ChapterNode([firstParagraph, lastParagraph]);
|
|
163
|
-
expect(chapter
|
|
164
|
-
.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
.toBe(`${firstText}
|
|
169
|
-
expect(chapter
|
|
170
|
-
.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
336
|
+
expect(chapter
|
|
337
|
+
.withoutAdjacentContent({ node: lastTextNode, index: 1 }, true)
|
|
338
|
+
?.root.toBookdown()).toBe(`${firstText}\n\nLst paragraph.`);
|
|
339
|
+
expect(chapter
|
|
340
|
+
.withoutAdjacentContent({ node: lastTextNode, index: 1 }, false)
|
|
341
|
+
?.root.toBookdown()).toBe(`${firstText}\n\nast paragraph.`);
|
|
342
|
+
expect(chapter
|
|
343
|
+
.withoutAdjacentContent({ node: lastTextNode, index: 0 }, false)
|
|
344
|
+
?.root.toBookdown()).toBe(`${firstText}${lastText}`);
|
|
345
|
+
expect(chapter
|
|
346
|
+
.withoutAdjacentContent({ node: firstTextNode, index: firstTextNode.getLength() }, true)
|
|
347
|
+
?.root.toBookdown()).toBe(`${firstText}${lastText}`);
|
|
348
|
+
expect(chapter
|
|
349
|
+
.withoutAdjacentContent({ node: firstTextNode, index: 0 }, false)
|
|
350
|
+
?.root.toBookdown()).toBeUndefined();
|
|
351
|
+
const beforeText = new TextNode('Before');
|
|
352
|
+
const beforeParagraph = new ParagraphNode(0, new FormatNode('', [beforeText]));
|
|
353
|
+
const afterText = new TextNode('After');
|
|
354
|
+
const afterParagraph = new ParagraphNode(0, new FormatNode('', [afterText]));
|
|
355
|
+
const listChapter = new ChapterNode([
|
|
356
|
+
beforeParagraph,
|
|
357
|
+
numberedList,
|
|
358
|
+
afterParagraph,
|
|
359
|
+
]);
|
|
178
360
|
// Do nothing when backspacing at the beginning of a list.
|
|
179
|
-
expect(listChapter
|
|
180
|
-
.
|
|
361
|
+
expect(listChapter
|
|
362
|
+
.withoutAdjacentContent({ node: firstTextNode, index: 0 }, false)
|
|
363
|
+
?.root.toBookdown()).toBeUndefined();
|
|
181
364
|
// Delete a character in a list
|
|
182
|
-
expect(listChapter
|
|
183
|
-
.
|
|
365
|
+
expect(listChapter
|
|
366
|
+
.withoutAdjacentContent({ node: firstTextNode, index: 0 }, true)
|
|
367
|
+
?.root.toBookdown()).toBe(`Before\n\n1. irst paragraph.\n2. ${lastText}\n\nAfter`);
|
|
184
368
|
// Can't forward delete into a list
|
|
185
|
-
expect(listChapter
|
|
186
|
-
.
|
|
369
|
+
expect(listChapter
|
|
370
|
+
.withoutAdjacentContent({ node: beforeText, index: beforeText.getLength() }, true)
|
|
371
|
+
?.root.toBookdown()).toBe(`Before${firstText}\n\n1. ${lastText}\n\nAfter`);
|
|
187
372
|
// Backspace a paragraph into the last list item
|
|
188
|
-
expect(listChapter
|
|
189
|
-
.
|
|
373
|
+
expect(listChapter
|
|
374
|
+
.withoutAdjacentContent({ node: afterText, index: 0 }, false)
|
|
375
|
+
?.root.toBookdown()).toBe(`Before\n\n1. ${firstText}\n2. ${lastText}After`);
|
|
190
376
|
// Select two list items for deletion.
|
|
191
|
-
expect(listChapter
|
|
192
|
-
.
|
|
377
|
+
expect(listChapter
|
|
378
|
+
.withoutRange({
|
|
379
|
+
start: { node: firstTextNode, index: 0 },
|
|
380
|
+
end: { node: lastTextNode, index: 5 },
|
|
381
|
+
})
|
|
382
|
+
?.root.toBookdown()).toBe(`Before\n\n1. paragraph.\n\nAfter`);
|
|
193
383
|
// Backspace over a block
|
|
194
384
|
const quoteChapter = new ChapterNode([new QuoteNode([]), firstParagraph]);
|
|
195
|
-
expect(quoteChapter
|
|
196
|
-
.
|
|
385
|
+
expect(quoteChapter
|
|
386
|
+
.withoutAdjacentContent({ node: firstTextNode, index: 0 }, false)
|
|
387
|
+
?.root.toBookdown()).toBe(`${firstText}`);
|
|
197
388
|
});
|
|
198
|
-
test(
|
|
389
|
+
test('Copy/paste', () => {
|
|
199
390
|
// Build a document with everything.
|
|
200
|
-
const sentence1 = new TextNode(
|
|
201
|
-
const paragraph1 = new ParagraphNode(0, new FormatNode(
|
|
202
|
-
const sentence2 = new TextNode(
|
|
203
|
-
const boldSentence3 = new TextNode(
|
|
204
|
-
const paragraph2 = new ParagraphNode(0, new FormatNode(
|
|
205
|
-
const sentence3 = new TextNode(
|
|
206
|
-
const paragraph3 = new ParagraphNode(0, new FormatNode(
|
|
207
|
-
const imageCaption = new TextNode(
|
|
208
|
-
const imageCredit = new TextNode(
|
|
209
|
-
const image = new EmbedNode(
|
|
210
|
-
const js = new TextNode(
|
|
211
|
-
const code = new CodeNode(js,
|
|
212
|
-
const item1 = new TextNode(
|
|
213
|
-
const item1a = new TextNode(
|
|
214
|
-
const item2 = new TextNode(
|
|
215
|
-
const item3 = new TextNode(
|
|
216
|
-
const list = new ListNode([
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
const
|
|
391
|
+
const sentence1 = new TextNode('Hello, I am a sentence.');
|
|
392
|
+
const paragraph1 = new ParagraphNode(0, new FormatNode('', [sentence1]));
|
|
393
|
+
const sentence2 = new TextNode('Hello, I am another sentence.');
|
|
394
|
+
const boldSentence3 = new TextNode(' Can you believe my size?');
|
|
395
|
+
const paragraph2 = new ParagraphNode(0, new FormatNode('', [sentence2, new FormatNode('*', [boldSentence3])]));
|
|
396
|
+
const sentence3 = new TextNode('Lonely last.');
|
|
397
|
+
const paragraph3 = new ParagraphNode(0, new FormatNode('', [sentence3]));
|
|
398
|
+
const imageCaption = new TextNode('no image');
|
|
399
|
+
const imageCredit = new TextNode('Amy');
|
|
400
|
+
const image = new EmbedNode('nope', 'nothing', new FormatNode('', [imageCaption]), new FormatNode('', [imageCredit]));
|
|
401
|
+
const js = new TextNode('let a = 1;');
|
|
402
|
+
const code = new CodeNode(js, 'js', '|', new FormatNode('', [new TextNode('assignment')]));
|
|
403
|
+
const item1 = new TextNode('one');
|
|
404
|
+
const item1a = new TextNode('one a');
|
|
405
|
+
const item2 = new TextNode('two');
|
|
406
|
+
const item3 = new TextNode('three');
|
|
407
|
+
const list = new ListNode([
|
|
408
|
+
new FormatNode('', [item1]),
|
|
409
|
+
new ListNode([new FormatNode('', [item1a])], true),
|
|
410
|
+
new FormatNode('', [item2]),
|
|
411
|
+
new FormatNode('', [item3]),
|
|
412
|
+
], true);
|
|
413
|
+
const afterList = new TextNode('Post-list');
|
|
414
|
+
const afterListParagraph = new ParagraphNode(0, new FormatNode('', [afterList]));
|
|
415
|
+
const cellr1c1 = new TextNode('a');
|
|
416
|
+
const cellr1c2 = new TextNode('b');
|
|
417
|
+
const cellr1c3 = new TextNode('c');
|
|
418
|
+
const cellr2c1 = new TextNode('d');
|
|
419
|
+
const cellr2c2 = new TextNode('e');
|
|
420
|
+
const cellr2c3 = new TextNode('f');
|
|
421
|
+
const cellr3c1 = new TextNode('g');
|
|
422
|
+
const cellr3c2 = new TextNode('h');
|
|
423
|
+
const cellr3c3 = new TextNode('i');
|
|
228
424
|
const table = new TableNode([
|
|
229
|
-
[
|
|
230
|
-
|
|
231
|
-
|
|
425
|
+
[
|
|
426
|
+
new FormatNode('', [cellr1c1]),
|
|
427
|
+
new FormatNode('', [cellr1c2]),
|
|
428
|
+
new FormatNode('', [cellr1c3]),
|
|
429
|
+
],
|
|
430
|
+
[
|
|
431
|
+
new FormatNode('', [cellr2c1]),
|
|
432
|
+
new FormatNode('', [cellr2c2]),
|
|
433
|
+
new FormatNode('', [cellr2c3]),
|
|
434
|
+
],
|
|
435
|
+
[
|
|
436
|
+
new FormatNode('', [cellr3c1]),
|
|
437
|
+
new FormatNode('', [cellr3c2]),
|
|
438
|
+
new FormatNode('', [cellr3c3]),
|
|
439
|
+
],
|
|
440
|
+
]);
|
|
441
|
+
const calloutOne = new TextNode('one');
|
|
442
|
+
const calloutTwo = new TextNode('two');
|
|
443
|
+
const calloutThree = new TextNode('three');
|
|
444
|
+
const callout = new CalloutNode([
|
|
445
|
+
new ParagraphNode(0, new FormatNode('', [calloutOne])),
|
|
446
|
+
new ParagraphNode(0, new FormatNode('', [calloutTwo])),
|
|
447
|
+
new ParagraphNode(0, new FormatNode('', [calloutThree])),
|
|
232
448
|
]);
|
|
233
|
-
const calloutOne = new TextNode("one");
|
|
234
|
-
const calloutTwo = new TextNode("two");
|
|
235
|
-
const calloutThree = new TextNode("three");
|
|
236
|
-
const callout = new CalloutNode([new ParagraphNode(0, new FormatNode("", [calloutOne])), new ParagraphNode(0, new FormatNode("", [calloutTwo])), new ParagraphNode(0, new FormatNode("", [calloutThree]))]);
|
|
237
449
|
const quoteOne = new TextNode("I'm tired");
|
|
238
|
-
const quoteCredit = new TextNode(
|
|
239
|
-
const quote = new QuoteNode([new ParagraphNode(0, new FormatNode(
|
|
240
|
-
const chapter = new ChapterNode([
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
450
|
+
const quoteCredit = new TextNode('Boomy');
|
|
451
|
+
const quote = new QuoteNode([new ParagraphNode(0, new FormatNode('', [quoteOne]))], new FormatNode('', [quoteCredit]));
|
|
452
|
+
const chapter = new ChapterNode([
|
|
453
|
+
paragraph1,
|
|
454
|
+
paragraph2,
|
|
455
|
+
paragraph3,
|
|
456
|
+
image,
|
|
457
|
+
code,
|
|
458
|
+
list,
|
|
459
|
+
afterListParagraph,
|
|
460
|
+
table,
|
|
461
|
+
callout,
|
|
462
|
+
quote,
|
|
463
|
+
]);
|
|
464
|
+
const partialSegment = chapter.copyRange({
|
|
465
|
+
start: { node: sentence1, index: 12 },
|
|
466
|
+
end: { node: sentence1, index: 22 },
|
|
467
|
+
});
|
|
468
|
+
const reversedPartialSegment = chapter.copyRange({
|
|
469
|
+
start: { node: sentence1, index: 22 },
|
|
470
|
+
end: { node: sentence1, index: 12 },
|
|
471
|
+
});
|
|
472
|
+
const consecutivePartialParagraphs = chapter.copyRange({
|
|
473
|
+
start: { node: sentence1, index: 12 },
|
|
474
|
+
end: { node: sentence2, index: 5 },
|
|
475
|
+
});
|
|
476
|
+
const threeParagraphs = chapter.copyRange({
|
|
477
|
+
start: { node: sentence1, index: sentence1.getLength() - 1 },
|
|
478
|
+
end: { node: sentence3, index: 6 },
|
|
479
|
+
});
|
|
245
480
|
// Paragraphs
|
|
246
|
-
expect(partialSegment?.toBookdown())
|
|
247
|
-
|
|
248
|
-
expect(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
481
|
+
expect(partialSegment?.toBookdown()).toBe('a sentence');
|
|
482
|
+
expect(reversedPartialSegment?.toBookdown()).toBe('a sentence');
|
|
483
|
+
expect(consecutivePartialParagraphs?.toBookdown()).toBe('a sentence.\n\nHello');
|
|
484
|
+
expect(threeParagraphs?.toBookdown()).toBe(`.\n\n${sentence2.toBookdown()}*${boldSentence3.toBookdown()}*\n\nLonely`);
|
|
485
|
+
const partialImageCaption = chapter.copyRange({
|
|
486
|
+
start: { node: imageCaption, index: 3 },
|
|
487
|
+
end: { node: imageCaption, index: 8 },
|
|
488
|
+
});
|
|
489
|
+
const partialImageCredit = chapter.copyRange({
|
|
490
|
+
start: { node: imageCredit, index: 2 },
|
|
491
|
+
end: { node: imageCredit, index: 3 },
|
|
492
|
+
});
|
|
493
|
+
const imageCaptionAndCredit = chapter.copyRange({
|
|
494
|
+
start: { node: imageCaption, index: 3 },
|
|
495
|
+
end: { node: imageCredit, index: 1 },
|
|
496
|
+
});
|
|
497
|
+
const paragraphAndImage = chapter.copyRange({
|
|
498
|
+
start: { node: sentence3, index: 7 },
|
|
499
|
+
end: { node: imageCaption, index: 2 },
|
|
500
|
+
});
|
|
258
501
|
// Images
|
|
259
|
-
expect(partialImageCaption?.toBookdown())
|
|
260
|
-
|
|
261
|
-
expect(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const imageAndCode = chapter.copyRange({ start: { node: imageCredit, index: 0 }, end: { node: js, index: 3 } });
|
|
502
|
+
expect(partialImageCaption?.toBookdown()).toBe(`image`);
|
|
503
|
+
expect(partialImageCredit?.toBookdown()).toBe(`y`);
|
|
504
|
+
expect(imageCaptionAndCredit?.toBookdown()).toBe(`|nope|nothing|image|A|`);
|
|
505
|
+
expect(paragraphAndImage?.toBookdown()).toBe(`last.\n\n|nope|nothing|no||`);
|
|
506
|
+
const imageAndCode = chapter.copyRange({
|
|
507
|
+
start: { node: imageCredit, index: 0 },
|
|
508
|
+
end: { node: js, index: 3 },
|
|
509
|
+
});
|
|
268
510
|
// Code
|
|
269
|
-
expect(imageAndCode?.toBookdown())
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
511
|
+
expect(imageAndCode?.toBookdown()).toBe(`|nope|nothing||Amy|\n\n\`js\nlet\n\``);
|
|
512
|
+
const partialList = chapter.copyRange({
|
|
513
|
+
start: { node: item1a, index: 4 },
|
|
514
|
+
end: { node: item2, index: 1 },
|
|
515
|
+
});
|
|
516
|
+
const partialListAndParagraph = chapter.copyRange({
|
|
517
|
+
start: { node: item2, index: 0 },
|
|
518
|
+
end: { node: afterList, index: 4 },
|
|
519
|
+
});
|
|
273
520
|
// Lists
|
|
274
|
-
expect(partialList?.toBookdown())
|
|
275
|
-
|
|
276
|
-
expect(partialListAndParagraph?.toBookdown())
|
|
277
|
-
.toBe(`\n\n1. two\n2. three\n\nPost`);
|
|
521
|
+
expect(partialList?.toBookdown()).toBe(`1.. a\n2. t`);
|
|
522
|
+
expect(partialListAndParagraph?.toBookdown()).toBe(`1. two\n2. three\n\nPost`);
|
|
278
523
|
// Tables
|
|
279
|
-
const partialTable = chapter.copyRange({
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
524
|
+
const partialTable = chapter.copyRange({
|
|
525
|
+
start: { node: cellr2c2, index: 0 },
|
|
526
|
+
end: { node: cellr3c2, index: 1 },
|
|
527
|
+
});
|
|
528
|
+
const partialTableAndParagraph = chapter.copyRange({
|
|
529
|
+
start: { node: afterList, index: 0 },
|
|
530
|
+
end: { node: cellr1c2, index: 1 },
|
|
531
|
+
});
|
|
532
|
+
expect(partialTable?.toBookdown()).toBe(`,|e|f\n,g|h|\n`);
|
|
533
|
+
expect(partialTableAndParagraph?.toBookdown()).toBe(`Post-list\n\n,a|b|\n`);
|
|
285
534
|
// Callouts
|
|
286
|
-
const partialCallout = chapter.copyRange({
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
535
|
+
const partialCallout = chapter.copyRange({
|
|
536
|
+
start: { node: calloutOne, index: 0 },
|
|
537
|
+
end: { node: calloutTwo, index: 1 },
|
|
538
|
+
});
|
|
539
|
+
const partialTableAndCallout = chapter.copyRange({
|
|
540
|
+
start: { node: cellr3c3, index: 0 },
|
|
541
|
+
end: { node: calloutTwo, index: 3 },
|
|
542
|
+
});
|
|
543
|
+
expect(partialCallout?.toBookdown()).toBe(`=\none\n\nt\n=`);
|
|
544
|
+
expect(partialTableAndCallout?.toBookdown()).toBe(`,||i\n\n\n=\none\n\ntwo\n=`);
|
|
292
545
|
// Quote
|
|
293
|
-
const partialCalloutAndQuote = chapter.copyRange({
|
|
294
|
-
|
|
295
|
-
|
|
546
|
+
const partialCalloutAndQuote = chapter.copyRange({
|
|
547
|
+
start: { node: calloutThree, index: 0 },
|
|
548
|
+
end: { node: quoteOne, index: 9 },
|
|
549
|
+
});
|
|
550
|
+
expect(partialCalloutAndQuote?.toBookdown()).toBe(`=\nthree\n=\n\n"\nI'm tired\n"`);
|
|
296
551
|
});
|
|
297
|
-
test(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
552
|
+
test.each([
|
|
553
|
+
['Hi.\n\nI am paragraphs.', '<p>Hi.</p><p>I am paragraphs.</p>'],
|
|
554
|
+
[
|
|
555
|
+
'* I am one\n\n* I am two\n\n* I am three',
|
|
556
|
+
'<ul><li>I am one</li><li>I am two</li><li>I am three</li></ul>',
|
|
557
|
+
],
|
|
558
|
+
[
|
|
559
|
+
'1. I am one\n\n2. I am two\n\n3. I am three',
|
|
560
|
+
'<ol><li>I am one</li><li>I am two</li><li>I am three</li></ol>',
|
|
561
|
+
],
|
|
562
|
+
[
|
|
563
|
+
'|image.jpg|A picture|A caption|A credit|',
|
|
564
|
+
'<img src="image.jpg" alt="A picture" />',
|
|
565
|
+
],
|
|
566
|
+
])('%s to HTML', (input, output) => {
|
|
567
|
+
expect(Parser.parseChapter(undefined, input).toHTML()).toBe(output);
|
|
302
568
|
});
|