bookish-press 0.4.47 → 0.4.48
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/components/Auth.svelte +55 -0
- package/components/Auth.svelte.d.ts +16 -0
- package/{src/lib/components/Authentication.ts → components/Authentication.d.ts} +0 -2
- package/components/Authentication.js +1 -0
- package/{src/lib/components → components}/BookPreview.svelte +22 -27
- package/components/BookPreview.svelte.d.ts +18 -0
- package/{src/lib/components → components}/External.svelte +1 -2
- package/components/External.svelte.d.ts +18 -0
- package/components/Link.svelte +51 -0
- package/components/Link.svelte.d.ts +18 -0
- package/{src/lib/components → components}/app/BookList.svelte +3 -6
- package/components/app/BookList.svelte.d.ts +18 -0
- package/{src/lib/components → components}/app/Button.svelte +4 -5
- package/components/app/Button.svelte.d.ts +22 -0
- package/{src/lib/components → components}/app/Feedback.svelte +7 -11
- package/components/app/Feedback.svelte.d.ts +18 -0
- package/{src/lib/components → components}/app/Head.svelte +1 -2
- package/components/app/Head.svelte.d.ts +18 -0
- package/{src/lib/components → components}/app/Large.svelte +0 -0
- package/components/app/Large.svelte.d.ts +27 -0
- package/{src/lib/components → components}/app/Lead.svelte +0 -0
- package/components/app/Lead.svelte.d.ts +27 -0
- package/{src/lib/components → components}/app/Link.svelte +3 -4
- package/components/app/Link.svelte.d.ts +20 -0
- package/{src/lib/components → components}/app/Options.svelte +4 -5
- package/components/app/Options.svelte.d.ts +19 -0
- package/{src/lib/components → components}/app/Paragraph.svelte +1 -2
- package/components/app/Paragraph.svelte.d.ts +18 -0
- package/{src/lib/components → components}/app/Section.svelte +0 -0
- package/components/app/Section.svelte.d.ts +27 -0
- package/{src/lib/components → components}/app/Table.svelte +0 -0
- package/components/app/Table.svelte.d.ts +27 -0
- package/{src/lib/components → components}/app/TextInput.svelte +9 -12
- package/components/app/TextInput.svelte.d.ts +22 -0
- package/{src/lib/components → components}/chapter/Atom.svelte +12 -18
- package/components/chapter/Atom.svelte.d.ts +19 -0
- package/components/chapter/Block.svelte +37 -0
- package/components/chapter/Block.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Callout.svelte +3 -6
- package/components/chapter/Callout.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/CaptionedCode.svelte +13 -21
- package/components/chapter/CaptionedCode.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/ChapterBody.svelte +9 -13
- package/components/chapter/ChapterBody.svelte.d.ts +19 -0
- package/{src/lib/components → components}/chapter/Citations.svelte +33 -34
- package/components/chapter/Citations.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Code.svelte +58 -62
- package/components/chapter/Code.svelte.d.ts +22 -0
- package/{src/lib/components → components}/chapter/Comment.svelte +18 -30
- package/components/chapter/Comment.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Definition.svelte +17 -23
- package/components/chapter/Definition.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Embed.svelte +77 -97
- package/components/chapter/Embed.svelte.d.ts +20 -0
- package/components/chapter/ErrorMessage.svelte +9 -0
- package/components/chapter/ErrorMessage.svelte.d.ts +17 -0
- package/components/chapter/ExtendedPrism.d.ts +2 -0
- package/{src/lib/components → components}/chapter/ExtendedPrism.js +0 -0
- package/{src/lib/components → components}/chapter/Figure.svelte +26 -34
- package/components/chapter/Figure.svelte.d.ts +24 -0
- package/{src/lib/components → components}/chapter/Footnote.svelte +20 -32
- package/components/chapter/Footnote.svelte.d.ts +19 -0
- package/{src/lib/components → components}/chapter/Format.svelte +34 -39
- package/components/chapter/Format.svelte.d.ts +19 -0
- package/{src/lib/components → components}/chapter/InlineCode.svelte +5 -9
- package/components/chapter/InlineCode.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Label.svelte +14 -23
- package/components/chapter/Label.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Link.svelte +21 -27
- package/components/chapter/Link.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/List.svelte +3 -5
- package/components/chapter/List.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Marginal.svelte +41 -54
- package/components/chapter/Marginal.svelte.d.ts +22 -0
- package/{src/lib/components → components}/chapter/Paragraph.svelte +20 -25
- package/components/chapter/Paragraph.svelte.d.ts +18 -0
- package/{src/lib/components → components}/chapter/Positioned.svelte +1 -4
- package/components/chapter/Positioned.svelte.d.ts +19 -0
- package/{src/lib/components → components}/chapter/Problem.svelte +0 -0
- package/components/chapter/Problem.svelte.d.ts +27 -0
- package/components/chapter/Python.svelte +128 -0
- package/components/chapter/Python.svelte.d.ts +18 -0
- package/{src/lib/components → components}/chapter/Quote.svelte +5 -9
- package/components/chapter/Quote.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Rule.svelte +1 -4
- package/components/chapter/Rule.svelte.d.ts +17 -0
- package/{src/lib/components → components}/chapter/Table.svelte +7 -11
- package/components/chapter/Table.svelte.d.ts +17 -0
- package/components/chapter/Text.svelte +87 -0
- package/components/chapter/Text.svelte.d.ts +18 -0
- package/components/editor/BookishEditor.svelte +884 -0
- package/components/editor/BookishEditor.svelte.d.ts +25 -0
- package/components/editor/CalloutEditor.svelte +10 -0
- package/components/editor/CalloutEditor.svelte.d.ts +17 -0
- package/{src/lib/components → components}/editor/CaptionedCodeEditor.svelte +6 -10
- package/components/editor/CaptionedCodeEditor.svelte.d.ts +17 -0
- package/components/editor/CaretContext.d.ts +50 -0
- package/components/editor/CaretContext.js +1 -0
- package/{src/lib/components/editor/CaretState.ts → components/editor/CaretState.d.ts} +7 -6
- package/components/editor/CaretState.js +1 -0
- package/{src/lib/components/editor/CaretUtilities.ts → components/editor/CaretUtilities.d.ts} +0 -1
- package/components/editor/CaretUtilities.js +1 -0
- package/{src/lib/components → components}/editor/CaretView.svelte +20 -25
- package/components/editor/CaretView.svelte.d.ts +25 -0
- package/components/editor/CitationsEditor.svelte +53 -0
- package/components/editor/CitationsEditor.svelte.d.ts +17 -0
- package/{src/lib/components/editor/Clipboard.ts → components/editor/Clipboard.d.ts} +1 -2
- package/components/editor/Clipboard.js +1 -0
- package/{src/lib/components/editor/Command.ts → components/editor/Command.d.ts} +2 -8
- package/components/editor/Command.js +1 -0
- package/components/editor/Commands.d.ts +3 -0
- package/{src/lib/components/editor/Commands.ts → components/editor/Commands.js} +315 -730
- package/components/editor/ConfirmButton.svelte +49 -0
- package/components/editor/ConfirmButton.svelte.d.ts +19 -0
- package/components/editor/DefinitionEditor.svelte +36 -0
- package/components/editor/DefinitionEditor.svelte.d.ts +17 -0
- package/components/editor/EmbedEditor.svelte +137 -0
- package/components/editor/EmbedEditor.svelte.d.ts +17 -0
- package/{src/lib/components → components}/editor/Icon.svelte +1 -2
- package/components/editor/Icon.svelte.d.ts +16 -0
- package/{src/lib/components → components}/editor/ImageChooser.svelte +19 -24
- package/components/editor/ImageChooser.svelte.d.ts +18 -0
- package/components/editor/InlineCodeEditor.svelte +12 -0
- package/components/editor/InlineCodeEditor.svelte.d.ts +17 -0
- package/{src/lib/components → components}/editor/LabelEditor.svelte +9 -14
- package/components/editor/LabelEditor.svelte.d.ts +17 -0
- package/{src/lib/components → components}/editor/LanguageEditor.svelte +5 -8
- package/components/editor/LanguageEditor.svelte.d.ts +17 -0
- package/components/editor/LinkEditor.svelte +100 -0
- package/components/editor/LinkEditor.svelte.d.ts +17 -0
- package/{src/lib/components → components}/editor/Note.svelte +0 -0
- package/components/editor/Note.svelte.d.ts +27 -0
- package/{src/lib/components → components}/editor/Permissions.svelte +36 -43
- package/components/editor/Permissions.svelte.d.ts +20 -0
- package/components/editor/PositionEditor.svelte +17 -0
- package/components/editor/PositionEditor.svelte.d.ts +18 -0
- package/components/editor/QuoteEditor.svelte +10 -0
- package/components/editor/QuoteEditor.svelte.d.ts +17 -0
- package/{src/lib/components → components}/editor/Switch.svelte +11 -14
- package/components/editor/Switch.svelte.d.ts +20 -0
- package/components/editor/TableEditor.svelte +10 -0
- package/components/editor/TableEditor.svelte.d.ts +17 -0
- package/{src/lib/components → components}/editor/TextEditor.svelte +89 -101
- package/components/editor/TextEditor.svelte.d.ts +24 -0
- package/components/editor/Toggle.svelte +41 -0
- package/components/editor/Toggle.svelte.d.ts +19 -0
- package/components/editor/Toolbar.svelte +249 -0
- package/components/editor/Toolbar.svelte.d.ts +17 -0
- package/{src/lib/components → components}/editor/ToolbarGroup.svelte +3 -5
- package/components/editor/ToolbarGroup.svelte.d.ts +18 -0
- package/{src/lib/components → components}/editor/ToolbarSpacer.svelte +0 -0
- package/components/editor/ToolbarSpacer.svelte.d.ts +23 -0
- package/components/editor/URLEditor.svelte +13 -0
- package/components/editor/URLEditor.svelte.d.ts +18 -0
- package/{src/lib/components/editor/UndoState.ts → components/editor/UndoState.d.ts} +2 -3
- package/components/editor/UndoState.js +1 -0
- package/{src/lib/components → components}/editor/icons/annotate.svg +0 -0
- package/{src/lib/components → components}/editor/icons/block.svg +0 -0
- package/{src/lib/components → components}/editor/icons/bold.svg +0 -0
- package/{src/lib/components → components}/editor/icons/bullets.svg +0 -0
- package/{src/lib/components → components}/editor/icons/callout.svg +0 -0
- package/{src/lib/components → components}/editor/icons/citation.svg +0 -0
- package/{src/lib/components → components}/editor/icons/clear.svg +0 -0
- package/{src/lib/components → components}/editor/icons/clipboard.svg +0 -0
- package/{src/lib/components → components}/editor/icons/code.svg +0 -0
- package/{src/lib/components → components}/editor/icons/columnafter.svg +0 -0
- package/{src/lib/components → components}/editor/icons/columnbefore.svg +0 -0
- package/{src/lib/components → components}/editor/icons/comment.svg +0 -0
- package/{src/lib/components → components}/editor/icons/copy.svg +0 -0
- package/{src/lib/components → components}/editor/icons/cut.svg +0 -0
- package/{src/lib/components → components}/editor/icons/define.svg +0 -0
- package/{src/lib/components → components}/editor/icons/deletecolumn.svg +0 -0
- package/{src/lib/components → components}/editor/icons/deleterow.svg +0 -0
- package/{src/lib/components → components}/editor/icons/footnote.svg +0 -0
- package/{src/lib/components → components}/editor/icons/header1.svg +0 -0
- package/{src/lib/components → components}/editor/icons/header2.svg +0 -0
- package/{src/lib/components → components}/editor/icons/header3.svg +0 -0
- package/{src/lib/components → components}/editor/icons/home.svg +0 -0
- package/{src/lib/components → components}/editor/icons/indent.svg +0 -0
- package/{src/lib/components → components}/editor/icons/italic.svg +0 -0
- package/{src/lib/components → components}/editor/icons/label.svg +0 -0
- package/{src/lib/components → components}/editor/icons/left.svg +0 -0
- package/{src/lib/components → components}/editor/icons/level.svg +0 -0
- package/{src/lib/components → components}/editor/icons/link.svg +0 -0
- package/{src/lib/components → components}/editor/icons/list.svg +0 -0
- package/{src/lib/components → components}/editor/icons/media.svg +0 -0
- package/{src/lib/components → components}/editor/icons/middle.svg +0 -0
- package/{src/lib/components → components}/editor/icons/numbers.svg +0 -0
- package/{src/lib/components → components}/editor/icons/paragraph.svg +0 -0
- package/{src/lib/components → components}/editor/icons/paste.svg +0 -0
- package/{src/lib/components → components}/editor/icons/quote.svg +0 -0
- package/{src/lib/components → components}/editor/icons/redo.svg +0 -0
- package/{src/lib/components → components}/editor/icons/right.svg +0 -0
- package/{src/lib/components → components}/editor/icons/rowabove.svg +0 -0
- package/{src/lib/components → components}/editor/icons/rowbelow.svg +0 -0
- package/{src/lib/components → components}/editor/icons/rule.svg +0 -0
- package/{src/lib/components → components}/editor/icons/sub.svg +0 -0
- package/{src/lib/components → components}/editor/icons/super.svg +0 -0
- package/{src/lib/components → components}/editor/icons/table.svg +0 -0
- package/{src/lib/components → components}/editor/icons/text.svg +0 -0
- package/{src/lib/components → components}/editor/icons/time.svg +0 -0
- package/{src/lib/components → components}/editor/icons/undo.svg +0 -0
- package/{src/lib/components → components}/editor/icons/unindent.svg +0 -0
- package/{src/lib/components → components}/editor/icons/unlink.svg +0 -0
- package/{src/lib/components → components}/page/Acknowledgements.svelte +10 -19
- package/components/page/Acknowledgements.svelte.d.ts +14 -0
- package/components/page/Authors.svelte +85 -0
- package/components/page/Authors.svelte.d.ts +21 -0
- package/components/page/BookLoader.svelte +59 -0
- package/components/page/BookLoader.svelte.d.ts +16 -0
- package/components/page/BulkReferenceEditor.svelte +63 -0
- package/components/page/BulkReferenceEditor.svelte.d.ts +14 -0
- package/components/page/Chapter.svelte +392 -0
- package/components/page/Chapter.svelte.d.ts +18 -0
- package/components/page/ChapterContext.d.ts +10 -0
- package/components/page/ChapterContext.js +1 -0
- package/{src/lib/components → components}/page/ChapterNumber.svelte +0 -0
- package/components/page/ChapterNumber.svelte.d.ts +27 -0
- package/{src/lib/components → components}/page/ChapterTitle.svelte +2 -4
- package/components/page/ChapterTitle.svelte.d.ts +18 -0
- package/components/page/Contexts.d.ts +47 -0
- package/components/page/Contexts.js +133 -0
- package/{src/lib/components → components}/page/DefinitionView.svelte +37 -52
- package/components/page/DefinitionView.svelte.d.ts +18 -0
- package/{src/lib/components → components}/page/Description.svelte +7 -15
- package/components/page/Description.svelte.d.ts +14 -0
- package/components/page/Edition.svelte +161 -0
- package/components/page/Edition.svelte.d.ts +20 -0
- package/components/page/EditionLoader.svelte +99 -0
- package/components/page/EditionLoader.svelte.d.ts +18 -0
- package/{src/lib/components → components}/page/Editions.svelte +18 -22
- package/components/page/Editions.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/Glossary.svelte +28 -33
- package/components/page/Glossary.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/Header.svelte +52 -59
- package/components/page/Header.svelte.d.ts +29 -0
- package/{src/lib/components → components}/page/Index.svelte +41 -48
- package/components/page/Index.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/Instructions.svelte +1 -2
- package/components/page/Instructions.svelte.d.ts +18 -0
- package/{src/lib/components → components}/page/License.svelte +9 -17
- package/components/page/License.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/Loading.svelte +0 -0
- package/components/page/Loading.svelte.d.ts +23 -0
- package/{src/lib/components → components}/page/Media.svelte +27 -44
- package/components/page/Media.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/MediaPreview.svelte +2 -3
- package/components/page/MediaPreview.svelte.d.ts +19 -0
- package/{src/lib/components → components}/page/Muted.svelte +0 -0
- package/components/page/Muted.svelte.d.ts +27 -0
- package/{src/lib/components → components}/page/Outline.svelte +110 -140
- package/components/page/Outline.svelte.d.ts +19 -0
- package/components/page/Page.svelte +84 -0
- package/components/page/Page.svelte.d.ts +19 -0
- package/{src/lib/components → components}/page/PageHeader.svelte +1 -2
- package/components/page/PageHeader.svelte.d.ts +18 -0
- package/{src/lib/components → components}/page/PageParagraph.svelte +0 -0
- package/components/page/PageParagraph.svelte.d.ts +27 -0
- package/components/page/PossibleChapter.svelte +14 -0
- package/components/page/PossibleChapter.svelte.d.ts +14 -0
- package/components/page/PossibleReference.svelte +11 -0
- package/components/page/PossibleReference.svelte.d.ts +18 -0
- package/{src/lib/components → components}/page/Print.svelte +3 -5
- package/components/page/Print.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/Publish.svelte +52 -59
- package/components/page/Publish.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/Reference.svelte +30 -39
- package/components/page/Reference.svelte.d.ts +17 -0
- package/{src/lib/components → components}/page/References.svelte +14 -18
- package/components/page/References.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/Rows.svelte +0 -0
- package/components/page/Rows.svelte.d.ts +27 -0
- package/components/page/Search.svelte +133 -0
- package/components/page/Search.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/Status.svelte +3 -5
- package/components/page/Status.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/SubdomainEditor.svelte +13 -16
- package/components/page/SubdomainEditor.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/TableOfContents.svelte +68 -79
- package/components/page/TableOfContents.svelte.d.ts +14 -0
- package/components/page/TableOfContentsImage.svelte +18 -0
- package/components/page/TableOfContentsImage.svelte.d.ts +16 -0
- package/{src/lib/components → components}/page/TableOfContentsRow.svelte +24 -34
- package/components/page/TableOfContentsRow.svelte.d.ts +24 -0
- package/{src/lib/components → components}/page/ThemeEditor.svelte +33 -44
- package/components/page/ThemeEditor.svelte.d.ts +14 -0
- package/{src/lib/components → components}/page/ThemeEditorPreview.svelte +12 -21
- package/components/page/ThemeEditorPreview.svelte.d.ts +17 -0
- package/components/page/ThemeSetEditor.svelte +19 -0
- package/components/page/ThemeSetEditor.svelte.d.ts +18 -0
- package/{src/lib/components → components}/page/ThemeVariableEditor.svelte +14 -18
- package/components/page/ThemeVariableEditor.svelte.d.ts +18 -0
- package/{src/lib/components → components}/page/Title.svelte +0 -0
- package/components/page/Title.svelte.d.ts +27 -0
- package/{src/lib/components → components}/page/Unknown.svelte +8 -10
- package/components/page/Unknown.svelte.d.ts +16 -0
- package/components/page/margins.d.ts +2 -0
- package/{src/lib/components/page/margins.ts → components/page/margins.js} +46 -79
- package/index.d.ts +15 -0
- package/{src/lib/index.js → index.js} +0 -0
- package/models/CRUD.d.ts +27 -0
- package/models/CRUD.js +262 -0
- package/models/Firebase.d.ts +5 -0
- package/{src/lib/models/Firebase.ts → models/Firebase.js} +16 -26
- package/models/book/Book.d.ts +61 -0
- package/models/book/Book.js +135 -0
- package/models/book/BookMedia.d.ts +23 -0
- package/models/book/BookMedia.js +108 -0
- package/models/book/BookSaveStatus.d.ts +7 -0
- package/models/book/BookSaveStatus.js +8 -0
- package/models/book/Chapter.d.ts +81 -0
- package/models/book/Chapter.js +212 -0
- package/models/book/ChapterID.d.ts +10 -0
- package/{src/lib/models/book/ChapterID.ts → models/book/ChapterID.js} +0 -1
- package/models/book/Definition.d.ts +6 -0
- package/models/book/Definition.js +1 -0
- package/models/book/Edition.d.ts +139 -0
- package/models/book/Edition.js +620 -0
- package/models/book/Reference.d.ts +24 -0
- package/models/book/Reference.js +78 -0
- package/models/book/Schema.d.ts +174 -0
- package/{src/lib/models/book/Schema.ts → models/book/Schema.js} +0 -1
- package/models/book/Theme.d.ts +113 -0
- package/{src/lib/models/book/Theme.ts → models/book/Theme.js} +5 -109
- package/{src/lib/models/book/ThemeColors.ts → models/book/ThemeColors.d.ts} +0 -6
- package/models/book/ThemeColors.js +1 -0
- package/models/book/Words.d.ts +2 -0
- package/{src/lib/models/book/Words.ts → models/book/Words.js} +0 -1
- package/models/chapter/AtomNode.d.ts +18 -0
- package/{src/lib/models/chapter/AtomNode.ts → models/chapter/AtomNode.js} +10 -30
- package/models/chapter/BlockNode.d.ts +20 -0
- package/{src/lib/models/chapter/BlockNode.ts → models/chapter/BlockNode.js} +47 -80
- package/models/chapter/BlocksNode.d.ts +50 -0
- package/{src/lib/models/chapter/BlocksNode.ts → models/chapter/BlocksNode.js} +359 -571
- package/models/chapter/BlocksNode.test.d.ts +1 -0
- package/models/chapter/BlocksNode.test.js +568 -0
- package/{src/lib/models/chapter/Bookkeeping.ts → models/chapter/Bookkeeping.d.ts} +0 -0
- package/models/chapter/Bookkeeping.js +1 -0
- package/models/chapter/CalloutNode.d.ts +17 -0
- package/models/chapter/CalloutNode.js +58 -0
- package/models/chapter/Caret.d.ts +23 -0
- package/{src/lib/models/chapter/Caret.ts → models/chapter/Caret.js} +26 -50
- package/models/chapter/ChapterNode.d.ts +34 -0
- package/models/chapter/ChapterNode.js +117 -0
- package/models/chapter/CitationsNode.d.ts +16 -0
- package/{src/lib/models/chapter/CitationsNode.ts → models/chapter/CitationsNode.js} +10 -17
- package/models/chapter/CodeNode.d.ts +35 -0
- package/{src/lib/models/chapter/CodeNode.ts → models/chapter/CodeNode.js} +62 -125
- package/models/chapter/CommentNode.d.ts +18 -0
- package/models/chapter/CommentNode.js +48 -0
- package/models/chapter/DefinitionNode.d.ts +12 -0
- package/{src/lib/models/chapter/DefinitionNode.ts → models/chapter/DefinitionNode.js} +8 -14
- package/models/chapter/Edit.d.ts +7 -0
- package/models/chapter/Edit.js +1 -0
- package/models/chapter/EmbedNode.d.ts +45 -0
- package/models/chapter/EmbedNode.js +168 -0
- package/models/chapter/ErrorNode.d.ts +17 -0
- package/{src/lib/models/chapter/ErrorNode.ts → models/chapter/ErrorNode.js} +8 -15
- package/models/chapter/FootnoteNode.d.ts +18 -0
- package/models/chapter/FootnoteNode.js +47 -0
- package/models/chapter/FormatNode.d.ts +60 -0
- package/{src/lib/models/chapter/FormatNode.ts → models/chapter/FormatNode.js} +262 -443
- package/models/chapter/FormatNode.test.d.ts +1 -0
- package/models/chapter/FormatNode.test.js +96 -0
- package/models/chapter/InlineCodeNode.d.ts +12 -0
- package/{src/lib/models/chapter/InlineCodeNode.ts → models/chapter/InlineCodeNode.js} +9 -17
- package/models/chapter/LabelNode.d.ts +17 -0
- package/{src/lib/models/chapter/LabelNode.ts → models/chapter/LabelNode.js} +10 -26
- package/models/chapter/LinkNode.d.ts +12 -0
- package/{src/lib/models/chapter/LinkNode.ts → models/chapter/LinkNode.js} +7 -12
- package/models/chapter/ListNode.d.ts +51 -0
- package/{src/lib/models/chapter/ListNode.ts → models/chapter/ListNode.js} +200 -277
- package/models/chapter/ListNode.test.d.ts +1 -0
- package/{src/lib/models/chapter/ListNode.test.ts → models/chapter/ListNode.test.js} +20 -57
- package/models/chapter/MetadataNode.d.ts +17 -0
- package/models/chapter/MetadataNode.js +32 -0
- package/models/chapter/Node.d.ts +38 -0
- package/{src/lib/models/chapter/Node.ts → models/chapter/Node.js} +71 -155
- package/models/chapter/Node.test.d.ts +1 -0
- package/{src/lib/models → models}/chapter/Node.test.js +0 -0
- package/models/chapter/ParagraphNode.d.ts +33 -0
- package/{src/lib/models/chapter/ParagraphNode.ts → models/chapter/ParagraphNode.js} +58 -95
- package/models/chapter/ParagraphNode.test.d.ts +1 -0
- package/models/chapter/ParagraphNode.test.js +30 -0
- package/models/chapter/Parser.d.ts +75 -0
- package/{src/lib/models/chapter/Parser.ts → models/chapter/Parser.js} +184 -369
- package/models/chapter/Parser.test.d.ts +1 -0
- package/{src/lib/models/chapter/Parser.test.ts → models/chapter/Parser.test.js} +0 -7
- package/{src/lib/models/chapter/Position.ts → models/chapter/Position.d.ts} +0 -0
- package/models/chapter/Position.js +1 -0
- package/models/chapter/QuoteNode.d.ts +25 -0
- package/models/chapter/QuoteNode.js +99 -0
- package/{src/lib/models/chapter/RootNode.ts → models/chapter/RootNode.d.ts} +0 -2
- package/models/chapter/RootNode.js +1 -0
- package/models/chapter/RuleNode.d.ts +15 -0
- package/{src/lib/models/chapter/RuleNode.ts → models/chapter/RuleNode.js} +6 -9
- package/models/chapter/TableNode.d.ts +37 -0
- package/{src/lib/models/chapter/TableNode.ts → models/chapter/TableNode.js} +82 -141
- package/models/chapter/TableNode.test.d.ts +1 -0
- package/{src/lib/models/chapter/TableNode.test.ts → models/chapter/TableNode.test.js} +10 -27
- package/models/chapter/TextNode.d.ts +36 -0
- package/{src/lib/models/chapter/TextNode.ts → models/chapter/TextNode.js} +65 -117
- package/models/chapter/TextNode.test.d.ts +1 -0
- package/{src/lib/models/chapter/TextNode.test.ts → models/chapter/TextNode.test.js} +0 -2
- package/package.json +270 -53
- package/util/getSubdomain.d.ts +3 -0
- package/{src/lib/util/getSubdomain.ts → util/getSubdomain.js} +8 -14
- package/util/isMobile.d.ts +2 -0
- package/{src/lib/util/isMobile.ts → util/isMobile.js} +0 -1
- package/util/mineReference.d.ts +4 -0
- package/{src/lib/util/mineReference.ts → util/mineReference.js} +25 -45
- package/util/scrollToEyeLevel.d.ts +2 -0
- package/{src/lib/util/scrollToEyeLevel.ts → util/scrollToEyeLevel.js} +2 -4
- package/.env.example +0 -8
- package/.firebaserc +0 -8
- package/.prettierignore +0 -8
- package/.prettierrc.json +0 -5
- package/_update-notifier-last-checked +0 -0
- package/firebase.json +0 -46
- package/firestore.indexes.json +0 -4
- package/firestore.rules +0 -59
- package/functions/.eslintrc.js +0 -28
- package/functions/package-lock.json +0 -12595
- package/functions/package.json +0 -43
- package/functions/src/index.ts +0 -345
- package/functions/tsconfig.dev.json +0 -3
- package/functions/tsconfig.json +0 -15
- package/scripts/claims.cjs +0 -99
- package/src/app.d.ts +0 -9
- package/src/app.html +0 -24
- package/src/lib/components/Auth.svelte +0 -65
- package/src/lib/components/Link.svelte +0 -58
- package/src/lib/components/chapter/Block.svelte +0 -42
- package/src/lib/components/chapter/ErrorMessage.svelte +0 -12
- package/src/lib/components/chapter/Python.svelte +0 -144
- package/src/lib/components/chapter/Text.svelte +0 -109
- package/src/lib/components/editor/BookishEditor.svelte +0 -1101
- package/src/lib/components/editor/CalloutEditor.svelte +0 -14
- package/src/lib/components/editor/CaretContext.ts +0 -55
- package/src/lib/components/editor/CitationsEditor.svelte +0 -64
- package/src/lib/components/editor/ConfirmButton.svelte +0 -51
- package/src/lib/components/editor/DefinitionEditor.svelte +0 -44
- package/src/lib/components/editor/EmbedEditor.svelte +0 -152
- package/src/lib/components/editor/InlineCodeEditor.svelte +0 -16
- package/src/lib/components/editor/LinkEditor.svelte +0 -110
- package/src/lib/components/editor/PositionEditor.svelte +0 -21
- package/src/lib/components/editor/QuoteEditor.svelte +0 -14
- package/src/lib/components/editor/TableEditor.svelte +0 -14
- package/src/lib/components/editor/Toggle.svelte +0 -47
- package/src/lib/components/editor/Toolbar.svelte +0 -297
- package/src/lib/components/editor/URLEditor.svelte +0 -15
- package/src/lib/components/page/Authors.svelte +0 -92
- package/src/lib/components/page/BookLoader.svelte +0 -77
- package/src/lib/components/page/BulkReferenceEditor.svelte +0 -86
- package/src/lib/components/page/Chapter.svelte +0 -449
- package/src/lib/components/page/ChapterContext.ts +0 -13
- package/src/lib/components/page/Contexts.ts +0 -176
- package/src/lib/components/page/Edition.svelte +0 -189
- package/src/lib/components/page/EditionLoader.svelte +0 -123
- package/src/lib/components/page/Page.svelte +0 -94
- package/src/lib/components/page/PossibleChapter.svelte +0 -16
- package/src/lib/components/page/PossibleReference.svelte +0 -14
- package/src/lib/components/page/Search.svelte +0 -153
- package/src/lib/components/page/TableOfContentsImage.svelte +0 -22
- package/src/lib/components/page/ThemeSetEditor.svelte +0 -21
- package/src/lib/models/CRUD.ts +0 -469
- package/src/lib/models/book/Book.ts +0 -283
- package/src/lib/models/book/BookMedia.ts +0 -182
- package/src/lib/models/book/BookSaveStatus.ts +0 -8
- package/src/lib/models/book/Chapter.ts +0 -462
- package/src/lib/models/book/Definition.ts +0 -2
- package/src/lib/models/book/Edition.ts +0 -1216
- package/src/lib/models/book/Reference.ts +0 -171
- package/src/lib/models/chapter/BlocksNode.test.ts +0 -867
- package/src/lib/models/chapter/CalloutNode.ts +0 -79
- package/src/lib/models/chapter/ChapterNode.ts +0 -169
- package/src/lib/models/chapter/CommentNode.ts +0 -61
- package/src/lib/models/chapter/Edit.ts +0 -6
- package/src/lib/models/chapter/EmbedNode.ts +0 -257
- package/src/lib/models/chapter/FootnoteNode.ts +0 -59
- package/src/lib/models/chapter/FormatNode.test.ts +0 -137
- package/src/lib/models/chapter/MetadataNode.ts +0 -44
- package/src/lib/models/chapter/ParagraphNode.test.ts +0 -54
- package/src/lib/models/chapter/QuoteNode.ts +0 -135
- package/src/params/edition.ts +0 -3
- package/src/routes/+error.svelte +0 -12
- package/src/routes/+layout.svelte +0 -241
- package/src/routes/+page.svelte +0 -43
- package/src/routes/Footer.svelte +0 -0
- package/src/routes/Header.svelte +0 -112
- package/src/routes/[bookid]/+layout.svelte +0 -5
- package/src/routes/[bookid]/[[editionid=edition]]/+error.svelte +0 -14
- package/src/routes/[bookid]/[[editionid=edition]]/+layout.svelte +0 -7
- package/src/routes/[bookid]/[[editionid=edition]]/+page.svelte +0 -5
- package/src/routes/[bookid]/[[editionid=edition]]/[chapterid]/+page.svelte +0 -5
- package/src/routes/[bookid]/[[editionid=edition]]/glossary/+page.svelte +0 -5
- package/src/routes/[bookid]/[[editionid=edition]]/index/[[letter]]/+page.svelte +0 -5
- package/src/routes/[bookid]/[[editionid=edition]]/media/+page.svelte +0 -5
- package/src/routes/[bookid]/[[editionid=edition]]/print/+page.svelte +0 -5
- package/src/routes/[bookid]/[[editionid=edition]]/references/+page.svelte +0 -5
- package/src/routes/[bookid]/[[editionid=edition]]/search/+page.svelte +0 -5
- package/src/routes/[bookid]/editions/+page.svelte +0 -20
- package/src/routes/about/+page.svelte +0 -102
- package/src/routes/confirm/+page.svelte +0 -62
- package/src/routes/email/+page.svelte +0 -99
- package/src/routes/login/+page.svelte +0 -66
- package/src/routes/read/+page.svelte +0 -38
- package/src/routes/write/+error.svelte +0 -10
- package/src/routes/write/+layout.svelte +0 -11
- package/src/routes/write/+page.svelte +0 -114
- package/src/routes/write/[bookid]/+layout.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/+layout.svelte +0 -7
- package/src/routes/write/[bookid]/[[editionid=edition]]/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/[chapterid]/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/glossary/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/index/[[letter]]/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/media/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/print/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/references/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/search/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/theme/+page.svelte +0 -5
- package/src/routes/write/[bookid]/[[editionid=edition]]/unknown/+page.svelte +0 -5
- package/src/routes/write/[bookid]/editions/+page.svelte +0 -20
- package/src/vite-env.d.ts +0 -1
- package/static/icons/favicon.png +0 -0
- package/static/icons/icon.png +0 -0
- package/static/icons/ios-icon.png +0 -0
- package/storage.rules +0 -9
- package/svelte.config.js +0 -19
- package/tsconfig.json +0 -18
- package/tsconfig.node.json +0 -9
- package/vite.config.ts +0 -8
- package/vite.reader.config.ts +0 -32
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type Edition from '../book/Edition';
|
|
2
1
|
import CalloutNode from './CalloutNode';
|
|
3
2
|
import ChapterNode from './ChapterNode';
|
|
4
3
|
import CitationsNode from './CitationsNode';
|
|
@@ -9,7 +8,6 @@ import EmbedNode from './EmbedNode';
|
|
|
9
8
|
import ErrorNode from './ErrorNode';
|
|
10
9
|
import FootnoteNode from './FootnoteNode';
|
|
11
10
|
import FormatNode from './FormatNode';
|
|
12
|
-
import type { Format, FormatNodeSegmentType } from './FormatNode';
|
|
13
11
|
import InlineCodeNode from './InlineCodeNode';
|
|
14
12
|
import LabelNode from './LabelNode';
|
|
15
13
|
import LinkNode from './LinkNode';
|
|
@@ -20,13 +18,8 @@ import Reference from '../book/Reference';
|
|
|
20
18
|
import RuleNode from './RuleNode';
|
|
21
19
|
import TableNode from './TableNode';
|
|
22
20
|
import TextNode from './TextNode';
|
|
23
|
-
import type Position from './Position';
|
|
24
|
-
import type BlockNode from './BlockNode';
|
|
25
|
-
import type Bookkeeping from './Bookkeeping';
|
|
26
|
-
|
|
27
21
|
const numberedRE = /^[0-9]+\.+/;
|
|
28
22
|
const bulletRE = /^\*+\s+/;
|
|
29
|
-
|
|
30
23
|
// TODO This grammar is slightly out of date.
|
|
31
24
|
// A simple recursive descent parser for this grammar.
|
|
32
25
|
// Embeds a tokenizer, since the lexical grammar is simple.
|
|
@@ -52,19 +45,16 @@ const bulletRE = /^\*+\s+/;
|
|
|
52
45
|
// LINK :: [CONTENT|TEXT]
|
|
53
46
|
// FOOTNOTE :: {TEXT}
|
|
54
47
|
// TEXT :: (.+)
|
|
55
|
-
|
|
56
48
|
export default class Parser {
|
|
57
|
-
book
|
|
58
|
-
text
|
|
59
|
-
index
|
|
60
|
-
openedDoubleQuote
|
|
49
|
+
book;
|
|
50
|
+
text;
|
|
51
|
+
index;
|
|
52
|
+
openedDoubleQuote;
|
|
61
53
|
// We pass this to all parsing functions to gather information strewn about the document.
|
|
62
|
-
metadata
|
|
63
|
-
|
|
64
|
-
constructor(book: Edition | undefined, text: string) {
|
|
54
|
+
metadata;
|
|
55
|
+
constructor(book, text) {
|
|
65
56
|
if (typeof text !== 'string')
|
|
66
57
|
throw 'Parser expected a string but received ' + typeof text;
|
|
67
|
-
|
|
68
58
|
this.book = book;
|
|
69
59
|
this.text = text;
|
|
70
60
|
this.index = 0; // Start at the first character.
|
|
@@ -73,91 +63,65 @@ export default class Parser {
|
|
|
73
63
|
symbols: {},
|
|
74
64
|
};
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
static preprocessSymbols(book: Edition, text: string) {
|
|
66
|
+
static preprocessSymbols(book, text) {
|
|
78
67
|
// Replace any remaining symbols with any definitions given.
|
|
79
68
|
if (book && book.getSymbols()) {
|
|
80
|
-
for (const [symbol, definition] of Object.entries(
|
|
81
|
-
book.getSymbols()
|
|
82
|
-
)) {
|
|
69
|
+
for (const [symbol, definition] of Object.entries(book.getSymbols())) {
|
|
83
70
|
// Don't replace escaped at symbols. Otherwise, be liberal in replacing any matching symbol that starts with the symbol
|
|
84
71
|
// name and ends with a word boundary.
|
|
85
|
-
text = text.replace(
|
|
86
|
-
new RegExp('([^\\\\])@' + symbol + '\\b', 'g'),
|
|
87
|
-
'$1' + definition
|
|
88
|
-
);
|
|
72
|
+
text = text.replace(new RegExp('([^\\\\])@' + symbol + '\\b', 'g'), '$1' + definition);
|
|
89
73
|
}
|
|
90
74
|
}
|
|
91
75
|
return text;
|
|
92
76
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return new Parser(
|
|
103
|
-
book,
|
|
104
|
-
book === undefined ? text : Parser.preprocessSymbols(book, text)
|
|
105
|
-
).parseFormat();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
static parseEmbed(book: Edition | undefined, text: string) {
|
|
109
|
-
return new Parser(
|
|
110
|
-
book,
|
|
111
|
-
book === undefined ? text : Parser.preprocessSymbols(book, text)
|
|
112
|
-
).parseEmbed();
|
|
113
|
-
}
|
|
114
|
-
|
|
77
|
+
static parseChapter(book, text) {
|
|
78
|
+
return new Parser(book, book === undefined ? text : Parser.preprocessSymbols(book, text)).parseChapter();
|
|
79
|
+
}
|
|
80
|
+
static parseFormat(book, text) {
|
|
81
|
+
return new Parser(book, book === undefined ? text : Parser.preprocessSymbols(book, text)).parseFormat();
|
|
82
|
+
}
|
|
83
|
+
static parseEmbed(book, text) {
|
|
84
|
+
return new Parser(book, book === undefined ? text : Parser.preprocessSymbols(book, text)).parseEmbed();
|
|
85
|
+
}
|
|
115
86
|
// Get the next character, if there is one, null otherwise.
|
|
116
|
-
peek()
|
|
87
|
+
peek() {
|
|
117
88
|
return this.more() ? this.text.charAt(this.index) : null;
|
|
118
89
|
}
|
|
119
|
-
|
|
120
90
|
// True if there are more characters to parse.
|
|
121
|
-
more()
|
|
91
|
+
more() {
|
|
122
92
|
return this.index < this.text.length;
|
|
123
93
|
}
|
|
124
|
-
|
|
125
94
|
nextIsEmptyParagraph() {
|
|
126
|
-
return (
|
|
127
|
-
this.text.charAt(this.index) === '\n' &&
|
|
95
|
+
return (this.text.charAt(this.index) === '\n' &&
|
|
128
96
|
this.text.charAt(this.index + 1) === '\n' &&
|
|
129
|
-
this.text.charAt(this.index + 2) === '\n'
|
|
130
|
-
);
|
|
97
|
+
this.text.charAt(this.index + 2) === '\n');
|
|
131
98
|
}
|
|
132
|
-
|
|
133
99
|
nextIsWhitespace() {
|
|
134
|
-
return (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
!this.nextIsEmptyParagraph()
|
|
139
|
-
);
|
|
100
|
+
return ((this.peek() === ' ' ||
|
|
101
|
+
this.peek() === '\t' ||
|
|
102
|
+
this.peek() === '\n') &&
|
|
103
|
+
!this.nextIsEmptyParagraph());
|
|
140
104
|
}
|
|
141
|
-
|
|
142
105
|
// Return the current character--if there is one-- and increment the index.
|
|
143
|
-
read(smarten = true)
|
|
144
|
-
if (!this.more())
|
|
145
|
-
|
|
106
|
+
read(smarten = true) {
|
|
107
|
+
if (!this.more())
|
|
108
|
+
return null;
|
|
146
109
|
let char = this.text.charAt(this.index);
|
|
147
|
-
|
|
148
110
|
if (smarten) {
|
|
149
|
-
if (char === '\n')
|
|
150
|
-
|
|
111
|
+
if (char === '\n')
|
|
112
|
+
this.openedDoubleQuote = false;
|
|
151
113
|
// As we read, replace straight quotes with smart quotes.
|
|
152
114
|
if (char === '"') {
|
|
153
115
|
// Replace left quotes after whitespace.
|
|
154
116
|
if (this.openedDoubleQuote) {
|
|
155
117
|
char = '\u201d';
|
|
156
|
-
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
157
120
|
char = '\u201c';
|
|
158
121
|
}
|
|
159
122
|
this.openedDoubleQuote = !this.openedDoubleQuote;
|
|
160
|
-
}
|
|
123
|
+
}
|
|
124
|
+
else if (char === "'") {
|
|
161
125
|
// If there's whitespace before this, it's a left single quote.
|
|
162
126
|
if (/\s/.test(this.text.charAt(this.index - 1)))
|
|
163
127
|
char = '\u2018';
|
|
@@ -166,70 +130,53 @@ export default class Parser {
|
|
|
166
130
|
char = '\u2019';
|
|
167
131
|
}
|
|
168
132
|
}
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
char === '-' &&
|
|
133
|
+
if (char === '-' &&
|
|
172
134
|
this.text.charAt(this.index + 1) === '-' &&
|
|
173
|
-
this.text.charAt(this.index) !== '\n'
|
|
174
|
-
) {
|
|
135
|
+
this.text.charAt(this.index) !== '\n') {
|
|
175
136
|
this.index++;
|
|
176
137
|
char = '\u2014';
|
|
177
138
|
}
|
|
178
139
|
}
|
|
179
|
-
|
|
180
140
|
// Advance to the next character in the document.
|
|
181
141
|
this.index++;
|
|
182
|
-
|
|
183
142
|
return char;
|
|
184
143
|
}
|
|
185
|
-
|
|
186
|
-
unread(): void {
|
|
144
|
+
unread() {
|
|
187
145
|
this.index--;
|
|
188
146
|
}
|
|
189
|
-
|
|
190
147
|
// All of the text including and after the current index.
|
|
191
|
-
rest()
|
|
148
|
+
rest() {
|
|
192
149
|
return this.text.substring(this.index);
|
|
193
150
|
}
|
|
194
|
-
|
|
195
151
|
// The character before
|
|
196
|
-
charBeforeNext()
|
|
152
|
+
charBeforeNext() {
|
|
197
153
|
return this.index === 0 ? null : this.text.charAt(this.index - 1);
|
|
198
154
|
}
|
|
199
|
-
|
|
200
155
|
// The character after
|
|
201
|
-
charAfterNext()
|
|
156
|
+
charAfterNext() {
|
|
202
157
|
return this.index === this.text.length - 1
|
|
203
158
|
? null
|
|
204
159
|
: this.text.charAt(this.index + 1);
|
|
205
160
|
}
|
|
206
|
-
|
|
207
161
|
// All the text until the next newline
|
|
208
|
-
restOfLine()
|
|
209
|
-
const nextNewline =
|
|
210
|
-
|
|
211
|
-
|
|
162
|
+
restOfLine() {
|
|
163
|
+
const nextNewline = this.text.substring(this.index).indexOf('\n') + this.index;
|
|
164
|
+
if (nextNewline < 0)
|
|
165
|
+
return this.text.substring(this.index);
|
|
212
166
|
else
|
|
213
|
-
return this.text.substring(
|
|
214
|
-
this.index,
|
|
215
|
-
Math.max(this.index, nextNewline)
|
|
216
|
-
);
|
|
167
|
+
return this.text.substring(this.index, Math.max(this.index, nextNewline));
|
|
217
168
|
}
|
|
218
|
-
|
|
219
169
|
// True if the given string is occurs next in the text.
|
|
220
|
-
nextIs(text
|
|
221
|
-
if (!this.more())
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
);
|
|
170
|
+
nextIs(text) {
|
|
171
|
+
if (!this.more())
|
|
172
|
+
return false;
|
|
173
|
+
return (this.text.substring(this.index, this.index + text.length) === text);
|
|
225
174
|
}
|
|
226
|
-
|
|
227
175
|
// A critical list that tells inline formatting parsers to stop being greedy.
|
|
228
|
-
nextIsContentDelimiter()
|
|
176
|
+
nextIsContentDelimiter() {
|
|
229
177
|
const next = this.peek();
|
|
230
178
|
const charAfterNext = this.charAfterNext();
|
|
231
|
-
return (
|
|
232
|
-
next === '\n' ||
|
|
179
|
+
return (next === '\n' ||
|
|
233
180
|
next === '_' ||
|
|
234
181
|
next === '*' ||
|
|
235
182
|
next === '`' ||
|
|
@@ -243,69 +190,56 @@ export default class Parser {
|
|
|
243
190
|
next === '{' ||
|
|
244
191
|
(this.charBeforeNext() === ' ' && next === '%') ||
|
|
245
192
|
next === '[' ||
|
|
246
|
-
next === '\\'
|
|
247
|
-
);
|
|
193
|
+
next === '\\');
|
|
248
194
|
}
|
|
249
|
-
|
|
250
195
|
// True if the next part of this string matches the given regular expression.
|
|
251
|
-
nextMatches(regex
|
|
252
|
-
if (!this.more())
|
|
196
|
+
nextMatches(regex) {
|
|
197
|
+
if (!this.more())
|
|
198
|
+
return false;
|
|
253
199
|
return regex.test(this.rest());
|
|
254
200
|
}
|
|
255
|
-
|
|
256
201
|
// Returns true if all of the text between the current character and the next newline is whitespace.
|
|
257
|
-
isBlankLine()
|
|
202
|
+
isBlankLine() {
|
|
258
203
|
return this.restOfLine().trim() === '';
|
|
259
204
|
}
|
|
260
|
-
|
|
261
205
|
// Read until encountering something other than a tab or a space.
|
|
262
|
-
readWhitespace()
|
|
206
|
+
readWhitespace() {
|
|
263
207
|
let peek = this.peek();
|
|
264
208
|
while (peek !== null && /^[ \t]/.test(peek)) {
|
|
265
209
|
this.read();
|
|
266
210
|
peek = this.peek();
|
|
267
211
|
}
|
|
268
212
|
}
|
|
269
|
-
|
|
270
213
|
// Read until the end of the line.
|
|
271
|
-
readUntilNewLine()
|
|
214
|
+
readUntilNewLine() {
|
|
272
215
|
let text = '';
|
|
273
|
-
while (this.more() && this.peek() !== '\n')
|
|
216
|
+
while (this.more() && this.peek() !== '\n')
|
|
217
|
+
text = text + this.read();
|
|
274
218
|
return text;
|
|
275
219
|
}
|
|
276
|
-
|
|
277
220
|
// Read until encountering the given string and return the read text.
|
|
278
|
-
readUntilNewlineOr(string
|
|
221
|
+
readUntilNewlineOr(string) {
|
|
279
222
|
let text = '';
|
|
280
223
|
while (this.more() && !this.nextIs('\n') && !this.nextIs(string))
|
|
281
224
|
text = text + this.read();
|
|
282
225
|
return text;
|
|
283
226
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
let blocks: BlockNode[] = [];
|
|
287
|
-
|
|
227
|
+
parseChapter() {
|
|
228
|
+
let blocks = [];
|
|
288
229
|
// Read any symbols declared for this chapter.
|
|
289
230
|
this.parseSymbols();
|
|
290
|
-
|
|
291
231
|
// Get the remaining text.
|
|
292
232
|
let declarations = this.text.substring(0, this.index);
|
|
293
233
|
let rest = this.rest();
|
|
294
|
-
|
|
295
234
|
// First, replace any occurrences of the symbol with the symbol's text.
|
|
296
235
|
for (const [symbol, text] of Object.entries(this.metadata.symbols)) {
|
|
297
|
-
rest = rest.replace(
|
|
298
|
-
new RegExp('([^\\\\])@' + symbol + '\\b', 'g'),
|
|
299
|
-
'$1' + text
|
|
300
|
-
);
|
|
236
|
+
rest = rest.replace(new RegExp('([^\\\\])@' + symbol + '\\b', 'g'), '$1' + text);
|
|
301
237
|
}
|
|
302
|
-
|
|
303
238
|
// Replace all of the remaining symbols using book symbol definitions.
|
|
304
|
-
if (this.book)
|
|
305
|
-
|
|
239
|
+
if (this.book)
|
|
240
|
+
rest = Parser.preprocessSymbols(this.book, rest);
|
|
306
241
|
// Replace the text with the pre-processed text.
|
|
307
242
|
this.text = declarations + rest;
|
|
308
|
-
|
|
309
243
|
// While there's more text, parse a line.
|
|
310
244
|
let trailingNewlines = 0;
|
|
311
245
|
while (this.more()) {
|
|
@@ -314,90 +248,73 @@ export default class Parser {
|
|
|
314
248
|
blocks.push(this.parseBlock());
|
|
315
249
|
// Read whitespace until we find the next thing.
|
|
316
250
|
while (this.nextIsWhitespace()) {
|
|
317
|
-
if (this.peek() === '\n')
|
|
251
|
+
if (this.peek() === '\n')
|
|
252
|
+
trailingNewlines++;
|
|
318
253
|
this.read();
|
|
319
254
|
}
|
|
320
255
|
}
|
|
321
|
-
|
|
322
256
|
// If there are no blocks, or the chapter ended with two newlines, append an empty paragraph with an empty format node and an empty text node.
|
|
323
257
|
if (blocks.length === 0 || trailingNewlines > 1)
|
|
324
258
|
blocks.push(new ParagraphNode());
|
|
325
|
-
|
|
326
259
|
// Make the chapter node so we can pass it around.
|
|
327
260
|
return new ChapterNode(blocks, this.metadata);
|
|
328
261
|
}
|
|
329
|
-
|
|
330
262
|
parseSymbols() {
|
|
331
263
|
// Read whitespace before the symbols
|
|
332
264
|
this.readWhitespace();
|
|
333
|
-
|
|
334
265
|
// Keep reading symbols
|
|
335
266
|
while (this.nextIs('@')) {
|
|
336
267
|
// Read the @
|
|
337
268
|
this.read();
|
|
338
|
-
|
|
339
269
|
// Read the name.
|
|
340
270
|
let name = this.readUntilNewlineOr(':');
|
|
341
|
-
|
|
342
271
|
// Names need to be letter and numbers only.
|
|
343
272
|
if (!/^[a-zA-Z0-9]+$/.test(name)) {
|
|
344
|
-
new ErrorNode(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
name +
|
|
350
|
-
"' isn't a valid name for a symbol; letters and numbers only"
|
|
351
|
-
);
|
|
273
|
+
new ErrorNode(this.readUntilNewLine(), name.trim() === ''
|
|
274
|
+
? 'Did you mean to declare a symbol? Use an @ symbol, then a name of only numbers and letters, then a colon, then whatever content you want it to represent.'
|
|
275
|
+
: "'" +
|
|
276
|
+
name +
|
|
277
|
+
"' isn't a valid name for a symbol; letters and numbers only");
|
|
352
278
|
return;
|
|
353
279
|
}
|
|
354
|
-
|
|
355
280
|
// Read any whitespace until the colon.
|
|
356
281
|
this.readWhitespace();
|
|
357
|
-
|
|
358
282
|
// Name declarations need to be terminated with a colon before the block starts.
|
|
359
283
|
if (!this.nextIs(':')) {
|
|
360
|
-
new ErrorNode(
|
|
361
|
-
this.readUntilNewLine(),
|
|
362
|
-
"Symbol names are to be followed by a ':'"
|
|
363
|
-
);
|
|
284
|
+
new ErrorNode(this.readUntilNewLine(), "Symbol names are to be followed by a ':'");
|
|
364
285
|
return;
|
|
365
286
|
}
|
|
366
|
-
|
|
367
287
|
// Read the colon
|
|
368
288
|
this.read();
|
|
369
|
-
|
|
370
289
|
// Read any whitespace after the colon.
|
|
371
290
|
this.readWhitespace();
|
|
372
|
-
|
|
373
291
|
// Remember where the text starts
|
|
374
292
|
let startIndex = this.index;
|
|
375
|
-
|
|
376
293
|
// Parse a block, any block.
|
|
377
294
|
this.parseBlock();
|
|
378
|
-
|
|
379
295
|
// Remember the text we parsed.
|
|
380
296
|
this.metadata.symbols[name] = this.text
|
|
381
297
|
.substring(startIndex, this.index)
|
|
382
298
|
.trim();
|
|
383
|
-
|
|
384
299
|
// Read whitespace until we find the next non-whitespace thing.
|
|
385
|
-
while (this.nextIsWhitespace())
|
|
300
|
+
while (this.nextIsWhitespace())
|
|
301
|
+
this.read();
|
|
386
302
|
}
|
|
387
303
|
}
|
|
388
|
-
|
|
389
|
-
parseBlock(): BlockNode {
|
|
304
|
+
parseBlock() {
|
|
390
305
|
// Read comment lines
|
|
391
306
|
while (this.nextIs('%')) {
|
|
392
307
|
this.readUntilNewLine();
|
|
393
308
|
}
|
|
394
|
-
|
|
395
309
|
// Parse and return a header if it starts with a hash
|
|
396
|
-
if (this.nextIs('#'))
|
|
310
|
+
if (this.nextIs('#'))
|
|
311
|
+
return this.parseHeader();
|
|
397
312
|
// Parse and return a horizontal rule if it starts with a dash
|
|
398
|
-
else if (this.nextIs('-'))
|
|
313
|
+
else if (this.nextIs('-'))
|
|
314
|
+
return this.parseRule();
|
|
399
315
|
// Parse and return an embed if it starts with a bar
|
|
400
|
-
else if (this.nextIs('|'))
|
|
316
|
+
else if (this.nextIs('|'))
|
|
317
|
+
return this.parseEmbed();
|
|
401
318
|
// Parse and return a bulleted or numbered list
|
|
402
319
|
else if (this.nextMatches(bulletRE) || this.nextMatches(numberedRE))
|
|
403
320
|
return this.parseList();
|
|
@@ -405,75 +322,69 @@ export default class Parser {
|
|
|
405
322
|
else if (this.nextMatches(/^`[a-zA-Z!]*[ \t]*\n/))
|
|
406
323
|
return this.parseCode();
|
|
407
324
|
// Parse and return a quote block if it starts with "
|
|
408
|
-
else if (this.nextMatches(/^"[ \t]*\n/))
|
|
325
|
+
else if (this.nextMatches(/^"[ \t]*\n/))
|
|
326
|
+
return this.parseQuote();
|
|
409
327
|
// Parse and return a callout if the line starts with =
|
|
410
|
-
else if (this.nextMatches(/^=[ \t]*\n/))
|
|
328
|
+
else if (this.nextMatches(/^=[ \t]*\n/))
|
|
329
|
+
return this.parseCallout();
|
|
411
330
|
// Parse and return a table if the line starts with a ,
|
|
412
|
-
else if (this.nextIs(','))
|
|
331
|
+
else if (this.nextIs(','))
|
|
332
|
+
return this.parseTable();
|
|
413
333
|
// Parse the text as paragraph;
|
|
414
|
-
else
|
|
334
|
+
else
|
|
335
|
+
return this.parseParagraph();
|
|
415
336
|
}
|
|
416
|
-
|
|
417
|
-
parseParagraph(): ParagraphNode {
|
|
337
|
+
parseParagraph() {
|
|
418
338
|
if (this.nextIsEmptyParagraph()) {
|
|
419
339
|
this.read();
|
|
420
340
|
this.read();
|
|
421
341
|
return new ParagraphNode(0, new FormatNode('', [new TextNode()]));
|
|
422
|
-
}
|
|
342
|
+
}
|
|
343
|
+
else
|
|
344
|
+
return new ParagraphNode(0, this.parseFormat());
|
|
423
345
|
}
|
|
424
|
-
|
|
425
|
-
parseHeader(): ParagraphNode {
|
|
346
|
+
parseHeader() {
|
|
426
347
|
// Read a sequence of hashes
|
|
427
348
|
let count = 0;
|
|
428
349
|
while (this.nextIs('#')) {
|
|
429
350
|
this.read();
|
|
430
351
|
count++;
|
|
431
352
|
}
|
|
432
|
-
|
|
433
353
|
// Read any whitespace after the hashes.
|
|
434
354
|
this.readWhitespace();
|
|
435
|
-
|
|
436
355
|
// Parse some content.
|
|
437
356
|
return new ParagraphNode(Math.min(3, count), this.parseFormat());
|
|
438
357
|
}
|
|
439
|
-
|
|
440
|
-
parseRule(): RuleNode {
|
|
358
|
+
parseRule() {
|
|
441
359
|
// Read until the end of the line. Ignore all text that follows.
|
|
442
360
|
this.readUntilNewLine();
|
|
443
|
-
|
|
444
361
|
return new RuleNode();
|
|
445
362
|
}
|
|
446
|
-
|
|
447
|
-
parseList(): ListNode {
|
|
363
|
+
parseList() {
|
|
448
364
|
let numbered = this.nextMatches(numberedRE);
|
|
449
|
-
|
|
450
|
-
const items: (FormatNode | ListNode)[] = [];
|
|
365
|
+
const items = [];
|
|
451
366
|
let lastLevel = undefined;
|
|
452
367
|
let currentLevel = undefined;
|
|
453
|
-
|
|
454
368
|
// Keep parsing bullets until there aren't any. They must be of the same type, otherwise we stop.
|
|
455
369
|
while (this.nextMatches(numberedRE) || this.nextMatches(bulletRE)) {
|
|
456
370
|
numbered = this.nextMatches(numberedRE);
|
|
457
|
-
|
|
458
371
|
// Remember the last level
|
|
459
372
|
lastLevel = currentLevel;
|
|
460
|
-
|
|
461
373
|
// Start the current level at 0
|
|
462
374
|
currentLevel = 0;
|
|
463
|
-
|
|
464
375
|
let digits = undefined;
|
|
465
376
|
if (numbered) {
|
|
466
377
|
// Read the digits and remember how many there were so we can backtrack.
|
|
467
378
|
digits = this.index;
|
|
468
379
|
this.readUntilNewlineOr('.');
|
|
469
380
|
digits = this.index - digits;
|
|
470
|
-
|
|
471
381
|
// Figure out this level.
|
|
472
382
|
while (this.nextIs('.')) {
|
|
473
383
|
this.read();
|
|
474
384
|
currentLevel++;
|
|
475
385
|
}
|
|
476
|
-
}
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
477
388
|
// Figure out this level.
|
|
478
389
|
currentLevel = 0;
|
|
479
390
|
while (this.nextIs('*')) {
|
|
@@ -481,18 +392,15 @@ export default class Parser {
|
|
|
481
392
|
currentLevel++;
|
|
482
393
|
}
|
|
483
394
|
}
|
|
484
|
-
|
|
485
395
|
// If this is the first bullet, or its the same level, just parse another bullet.
|
|
486
396
|
if (lastLevel === undefined || lastLevel === currentLevel) {
|
|
487
397
|
// Read the whitespace after the bullet.
|
|
488
398
|
this.readWhitespace();
|
|
489
399
|
// Parse content after the bullet.
|
|
490
400
|
const format = this.parseFormat();
|
|
491
|
-
items.push(
|
|
492
|
-
format.
|
|
493
|
-
|
|
494
|
-
: format
|
|
495
|
-
);
|
|
401
|
+
items.push(format.isEmpty()
|
|
402
|
+
? format.withSegmentAppended(new TextNode())
|
|
403
|
+
: format);
|
|
496
404
|
}
|
|
497
405
|
// Otherwise, unread the stars, then either stop parsing or parse nested list.
|
|
498
406
|
else {
|
|
@@ -502,7 +410,6 @@ export default class Parser {
|
|
|
502
410
|
this.unread();
|
|
503
411
|
count--;
|
|
504
412
|
}
|
|
505
|
-
|
|
506
413
|
// Unread the digits if there are any
|
|
507
414
|
if (digits !== undefined) {
|
|
508
415
|
while (digits > 0) {
|
|
@@ -510,9 +417,9 @@ export default class Parser {
|
|
|
510
417
|
digits--;
|
|
511
418
|
}
|
|
512
419
|
}
|
|
513
|
-
|
|
514
420
|
// If this new bullet is a lower level, then stop reading bullets.
|
|
515
|
-
if (currentLevel < lastLevel)
|
|
421
|
+
if (currentLevel < lastLevel)
|
|
422
|
+
break;
|
|
516
423
|
// Otherwise, it's greater, and we should read another list.
|
|
517
424
|
else {
|
|
518
425
|
items.push(this.parseList());
|
|
@@ -520,7 +427,6 @@ export default class Parser {
|
|
|
520
427
|
currentLevel = lastLevel;
|
|
521
428
|
}
|
|
522
429
|
}
|
|
523
|
-
|
|
524
430
|
// Read trailing whitespace and newlines.
|
|
525
431
|
this.readWhitespace();
|
|
526
432
|
while (this.nextIsWhitespace()) {
|
|
@@ -529,23 +435,19 @@ export default class Parser {
|
|
|
529
435
|
// Read whitespace before the next block.
|
|
530
436
|
this.readWhitespace();
|
|
531
437
|
}
|
|
532
|
-
|
|
533
438
|
// Stop if we reach an empty paragraph.
|
|
534
|
-
if (this.nextIsEmptyParagraph())
|
|
439
|
+
if (this.nextIsEmptyParagraph())
|
|
440
|
+
break;
|
|
535
441
|
}
|
|
536
442
|
return new ListNode(items, numbered);
|
|
537
443
|
}
|
|
538
|
-
|
|
539
|
-
parseCode(): CodeNode {
|
|
444
|
+
parseCode() {
|
|
540
445
|
// Parse the back tick
|
|
541
446
|
this.read();
|
|
542
|
-
|
|
543
447
|
// Parse through the next new line
|
|
544
448
|
let language = this.readUntilNewLine();
|
|
545
|
-
|
|
546
449
|
// Read the newline
|
|
547
450
|
this.read();
|
|
548
|
-
|
|
549
451
|
// Read until we encounter a closing back tick.
|
|
550
452
|
let code = '';
|
|
551
453
|
while (this.more() && !this.nextIs('`')) {
|
|
@@ -558,172 +460,142 @@ export default class Parser {
|
|
|
558
460
|
}
|
|
559
461
|
code = code + next;
|
|
560
462
|
}
|
|
561
|
-
|
|
562
463
|
// Trim the code.
|
|
563
464
|
code = code.trim();
|
|
564
|
-
|
|
565
465
|
// Read the backtick.
|
|
566
|
-
if (this.nextIs('`'))
|
|
567
|
-
|
|
466
|
+
if (this.nextIs('`'))
|
|
467
|
+
this.read();
|
|
568
468
|
let position = this.parsePosition();
|
|
569
|
-
|
|
570
469
|
// Read the caption. Note that parsing inline content stops at a newline,
|
|
571
470
|
// so if there's a line break after the last row, there won't be a caption.
|
|
572
471
|
const caption = this.parseFormat();
|
|
573
|
-
|
|
574
472
|
return new CodeNode(new TextNode(code), language, position, caption);
|
|
575
473
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
let position: Position = '|';
|
|
474
|
+
parsePosition() {
|
|
475
|
+
let position = '|';
|
|
579
476
|
// Is there a position indicator?
|
|
580
477
|
if (this.nextIs('<')) {
|
|
581
478
|
position = '<';
|
|
582
479
|
this.read();
|
|
583
|
-
}
|
|
480
|
+
}
|
|
481
|
+
else if (this.nextIs('>')) {
|
|
584
482
|
position = '>';
|
|
585
483
|
this.read();
|
|
586
484
|
}
|
|
587
|
-
|
|
588
485
|
return position;
|
|
589
486
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
const blocks: BlockNode[] = [];
|
|
593
|
-
|
|
487
|
+
parseQuote() {
|
|
488
|
+
const blocks = [];
|
|
594
489
|
// Parse the ", then any whitespace, then the newline
|
|
595
490
|
this.read();
|
|
596
|
-
|
|
597
491
|
// Then read any whitespace after the quote
|
|
598
492
|
this.readWhitespace();
|
|
599
|
-
|
|
600
493
|
// Then read the newline.
|
|
601
494
|
this.read();
|
|
602
|
-
|
|
603
495
|
while (this.more() && !this.nextIs('"')) {
|
|
604
496
|
// Read a block
|
|
605
497
|
const block = this.parseBlock();
|
|
606
498
|
// Add it to the list if we parsed something.
|
|
607
|
-
if (block !== null)
|
|
499
|
+
if (block !== null)
|
|
500
|
+
blocks.push(block);
|
|
608
501
|
// Read whitespace until we find the next thing.
|
|
609
|
-
while (this.nextIsWhitespace())
|
|
502
|
+
while (this.nextIsWhitespace())
|
|
503
|
+
this.read();
|
|
610
504
|
}
|
|
611
|
-
|
|
612
505
|
// Read the closing " and the whitespace that follows.
|
|
613
506
|
this.read();
|
|
614
|
-
|
|
615
507
|
// Is there a position indicator?
|
|
616
508
|
const position = this.parsePosition();
|
|
617
|
-
|
|
618
509
|
// Read any whitespace after the position indicator.
|
|
619
510
|
this.readWhitespace();
|
|
620
|
-
|
|
621
511
|
// Read the credit.
|
|
622
512
|
const credit = this.nextIs('\n') ? undefined : this.parseFormat();
|
|
623
|
-
|
|
624
513
|
return new QuoteNode(blocks, credit, position);
|
|
625
514
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
const blocks: BlockNode[] = [];
|
|
629
|
-
|
|
515
|
+
parseCallout() {
|
|
516
|
+
const blocks = [];
|
|
630
517
|
// Parse the = ...
|
|
631
518
|
this.read();
|
|
632
|
-
|
|
633
519
|
// ...then any whitespace
|
|
634
520
|
this.readWhitespace();
|
|
635
|
-
|
|
636
521
|
// ...then read the newline.
|
|
637
522
|
this.read();
|
|
638
|
-
|
|
639
523
|
// Then, read until we find a closing _
|
|
640
524
|
while (this.more() && !this.nextIs('=')) {
|
|
641
525
|
// Read a block
|
|
642
526
|
const block = this.parseBlock();
|
|
643
527
|
// Add it to the list if we parsed something.
|
|
644
|
-
if (block !== null)
|
|
528
|
+
if (block !== null)
|
|
529
|
+
blocks.push(block);
|
|
645
530
|
// Read whitespace until we find the next thing.
|
|
646
|
-
while (
|
|
647
|
-
this.peek() === ' ' ||
|
|
531
|
+
while (this.peek() === ' ' ||
|
|
648
532
|
this.peek() === '\t' ||
|
|
649
|
-
this.peek() === '\n'
|
|
650
|
-
)
|
|
533
|
+
this.peek() === '\n')
|
|
651
534
|
this.read();
|
|
652
535
|
}
|
|
653
|
-
|
|
654
536
|
// Read the closing =
|
|
655
537
|
this.read();
|
|
656
|
-
|
|
657
538
|
// Is there a position indicator?
|
|
658
539
|
const position = this.parsePosition();
|
|
659
|
-
|
|
660
540
|
// Read whitespace that follows.
|
|
661
541
|
this.readWhitespace();
|
|
662
|
-
|
|
663
542
|
return new CalloutNode(blocks, position);
|
|
664
543
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const rows: FormatNode[][] = [];
|
|
668
|
-
|
|
544
|
+
parseTable() {
|
|
545
|
+
const rows = [];
|
|
669
546
|
// Parse rows until the lines stop starting with ,
|
|
670
547
|
while (this.more() && this.nextIs(',')) {
|
|
671
548
|
let row = [];
|
|
672
|
-
|
|
673
549
|
while (this.more() && !this.nextIs('\n')) {
|
|
674
550
|
// Read the starting , or next |
|
|
675
551
|
this.read();
|
|
676
|
-
|
|
677
552
|
// Read whitespace that follows.
|
|
678
553
|
this.readWhitespace();
|
|
679
|
-
|
|
680
554
|
// Read content until reaching another | or the end of the line.
|
|
681
555
|
row.push(this.parseFormat('|'));
|
|
682
556
|
}
|
|
683
|
-
|
|
684
557
|
// Add the row.
|
|
685
558
|
rows.push(row);
|
|
686
|
-
|
|
687
559
|
// Read the newline
|
|
688
560
|
this.read();
|
|
689
561
|
}
|
|
690
|
-
|
|
691
562
|
// Read the position indicator if there is one.
|
|
692
563
|
const position = this.parsePosition();
|
|
693
|
-
|
|
694
564
|
// Read the caption. Note that parsing inline content stops at a newline,
|
|
695
565
|
// so if there's a line break after the last row, there won't be a caption.
|
|
696
566
|
const caption = this.parseFormat();
|
|
697
|
-
|
|
698
567
|
// Return the new table.
|
|
699
568
|
return new TableNode(rows, position, caption);
|
|
700
569
|
}
|
|
701
|
-
|
|
702
570
|
// The "awaiting" argument keeps track of upstream formatting. We don't need a stack here
|
|
703
571
|
// because we don't allow infinite nesting of the same formatting type.
|
|
704
|
-
parseFormat(awaiting
|
|
705
|
-
const segments
|
|
706
|
-
|
|
572
|
+
parseFormat(awaiting) {
|
|
573
|
+
const segments = [];
|
|
707
574
|
// Read until hitting a delimiter.
|
|
708
575
|
while (this.more() && !this.nextIs('\n')) {
|
|
709
576
|
const next = this.peek();
|
|
710
577
|
const charAfterNext = this.charAfterNext();
|
|
711
|
-
|
|
712
578
|
// Parse some bold, italic, subscript, superscript
|
|
713
579
|
if (next === '_' || next === '*' || next === '^')
|
|
714
580
|
segments.push(this.parseStyle(next));
|
|
715
581
|
// Parse unformatted text
|
|
716
|
-
else if (this.nextIs('`'))
|
|
582
|
+
else if (this.nextIs('`'))
|
|
583
|
+
segments.push(this.parseInlineCode());
|
|
717
584
|
// Parse a citation list
|
|
718
|
-
else if (this.nextIs('<'))
|
|
585
|
+
else if (this.nextIs('<'))
|
|
586
|
+
segments.push(this.parseCitations());
|
|
719
587
|
// Parse a footnote
|
|
720
|
-
else if (this.nextIs('{'))
|
|
588
|
+
else if (this.nextIs('{'))
|
|
589
|
+
segments.push(this.parseFootnote());
|
|
721
590
|
// Parse a definition
|
|
722
|
-
else if (this.nextIs('~'))
|
|
591
|
+
else if (this.nextIs('~'))
|
|
592
|
+
segments.push(this.parseDefinition());
|
|
723
593
|
// Parse an escaped character
|
|
724
|
-
else if (this.nextIs('\\'))
|
|
594
|
+
else if (this.nextIs('\\'))
|
|
595
|
+
segments.push(this.parseEscaped());
|
|
725
596
|
// Parse a link
|
|
726
|
-
else if (this.nextIs('['))
|
|
597
|
+
else if (this.nextIs('['))
|
|
598
|
+
segments.push(this.parseLink());
|
|
727
599
|
// Parse inline comments
|
|
728
600
|
else if (this.charBeforeNext() === ' ' && this.nextIs('%'))
|
|
729
601
|
segments.push(this.parseComment());
|
|
@@ -738,70 +610,53 @@ export default class Parser {
|
|
|
738
610
|
symbol = symbol + this.read();
|
|
739
611
|
next = this.peek();
|
|
740
612
|
}
|
|
741
|
-
segments.push(
|
|
742
|
-
new ErrorNode(undefined, "Couldn't find symbol @" + symbol)
|
|
743
|
-
);
|
|
613
|
+
segments.push(new ErrorNode(undefined, "Couldn't find symbol @" + symbol));
|
|
744
614
|
}
|
|
745
615
|
// Parse a label
|
|
746
|
-
else if (
|
|
747
|
-
next === ':' &&
|
|
616
|
+
else if (next === ':' &&
|
|
748
617
|
charAfterNext !== null &&
|
|
749
|
-
charAfterNext.match(/[a-z]/i)
|
|
750
|
-
) {
|
|
618
|
+
charAfterNext.match(/[a-z]/i)) {
|
|
751
619
|
segments.push(this.parseLabel());
|
|
752
620
|
}
|
|
753
621
|
// Keep reading text until finding a delimiter.
|
|
754
622
|
else {
|
|
755
623
|
let text = '';
|
|
756
|
-
while (
|
|
757
|
-
this.more() &&
|
|
624
|
+
while (this.more() &&
|
|
758
625
|
(!awaiting || !this.nextIs(awaiting)) &&
|
|
759
626
|
!this.nextIsContentDelimiter() &&
|
|
760
|
-
!this.nextIs('\n')
|
|
761
|
-
)
|
|
627
|
+
!this.nextIs('\n'))
|
|
762
628
|
text = text + this.read();
|
|
763
629
|
segments.push(new TextNode(text));
|
|
764
630
|
}
|
|
765
|
-
|
|
766
631
|
// If we've reached a delimiter we're waiting for, then stop parsing, so it can handle it. Otherwise, we'll keep reading.
|
|
767
|
-
if (this.peek() === awaiting)
|
|
632
|
+
if (this.peek() === awaiting)
|
|
633
|
+
break;
|
|
768
634
|
}
|
|
769
|
-
|
|
770
635
|
return new FormatNode('', segments);
|
|
771
636
|
}
|
|
772
|
-
|
|
773
|
-
parseEmbed(): EmbedNode {
|
|
637
|
+
parseEmbed() {
|
|
774
638
|
// Read |
|
|
775
639
|
this.read();
|
|
776
|
-
|
|
777
640
|
// Read the URL
|
|
778
641
|
const url = this.readUntilNewlineOr('|');
|
|
779
|
-
|
|
780
642
|
let description;
|
|
781
643
|
let caption;
|
|
782
644
|
let credit;
|
|
783
|
-
|
|
784
645
|
if (this.peek() === '|') {
|
|
785
646
|
// Read a |
|
|
786
647
|
this.read();
|
|
787
|
-
|
|
788
648
|
// Read the description
|
|
789
649
|
description = this.readUntilNewlineOr('|');
|
|
790
|
-
|
|
791
650
|
if (this.peek() === '|') {
|
|
792
651
|
// Read a |
|
|
793
652
|
this.read();
|
|
794
|
-
|
|
795
653
|
// Parse the caption
|
|
796
654
|
caption = this.parseFormat('|');
|
|
797
|
-
|
|
798
655
|
if (this.peek() === '|') {
|
|
799
656
|
// Read a |
|
|
800
657
|
this.read();
|
|
801
|
-
|
|
802
658
|
// Parse the credit
|
|
803
659
|
credit = this.parseFormat('|');
|
|
804
|
-
|
|
805
660
|
// Check for the closing delimeter
|
|
806
661
|
if (this.peek() === '|')
|
|
807
662
|
// Read a |
|
|
@@ -809,30 +664,23 @@ export default class Parser {
|
|
|
809
664
|
}
|
|
810
665
|
}
|
|
811
666
|
}
|
|
812
|
-
|
|
813
667
|
// Is there a position indicator?
|
|
814
668
|
const position = this.parsePosition();
|
|
815
|
-
|
|
816
669
|
return new EmbedNode(url, description ?? '', caption, credit, position);
|
|
817
670
|
}
|
|
818
|
-
|
|
819
|
-
parseComment(): CommentNode {
|
|
671
|
+
parseComment() {
|
|
820
672
|
// Consume the opening %
|
|
821
673
|
this.read();
|
|
822
|
-
|
|
823
674
|
// Consume everything until the next %.
|
|
824
675
|
const comment = this.parseFormat('%');
|
|
825
|
-
|
|
826
676
|
// Consume the closing %, if we didn't reach the end of input or a newline.
|
|
827
|
-
if (this.peek() === '%')
|
|
828
|
-
|
|
677
|
+
if (this.peek() === '%')
|
|
678
|
+
this.read();
|
|
829
679
|
return new CommentNode(comment);
|
|
830
680
|
}
|
|
831
|
-
|
|
832
|
-
parseLabel(): LabelNode | ErrorNode {
|
|
681
|
+
parseLabel() {
|
|
833
682
|
// Consume the :
|
|
834
683
|
this.read();
|
|
835
|
-
|
|
836
684
|
// Consume everything until it's not a letter.
|
|
837
685
|
let id = '';
|
|
838
686
|
let next = this.peek();
|
|
@@ -840,36 +688,29 @@ export default class Parser {
|
|
|
840
688
|
id = id + this.read();
|
|
841
689
|
next = this.peek();
|
|
842
690
|
}
|
|
843
|
-
|
|
844
691
|
return new LabelNode(id);
|
|
845
692
|
}
|
|
846
|
-
|
|
847
|
-
parseStyle(awaiting: string): FormatNode | ErrorNode {
|
|
693
|
+
parseStyle(awaiting) {
|
|
848
694
|
// Remember what we're matching.
|
|
849
695
|
const delimeter = this.read();
|
|
850
696
|
let subscript = false;
|
|
851
|
-
const segments
|
|
697
|
+
const segments = [];
|
|
852
698
|
let text = '';
|
|
853
|
-
|
|
854
699
|
// Special case subscript, which has an extra delimeter.
|
|
855
700
|
if (delimeter === '^' && this.peek() === 'v') {
|
|
856
701
|
this.read();
|
|
857
702
|
subscript = true;
|
|
858
703
|
}
|
|
859
|
-
|
|
860
704
|
if (delimeter === null)
|
|
861
|
-
return new ErrorNode(
|
|
862
|
-
undefined,
|
|
863
|
-
'Somehow parsing formatted text at end of file.'
|
|
864
|
-
);
|
|
865
|
-
|
|
705
|
+
return new ErrorNode(undefined, 'Somehow parsing formatted text at end of file.');
|
|
866
706
|
// Read some content until reaching the delimiter or the end of the line
|
|
867
707
|
while (this.more() && this.peek() !== delimeter && !this.nextIs('\n')) {
|
|
868
708
|
// If this is more formatted text, make a text node with whatever we've accumulated so far,
|
|
869
709
|
// then parse the formatted text, then reset the accumulator.
|
|
870
710
|
if (this.nextIsContentDelimiter()) {
|
|
871
711
|
// If the text is a non-empty string, make a text node with what we've accumulated.
|
|
872
|
-
if (text !== '')
|
|
712
|
+
if (text !== '')
|
|
713
|
+
segments.push(new TextNode(text));
|
|
873
714
|
// Parse the formatted content.
|
|
874
715
|
segments.push(this.parseFormat(awaiting));
|
|
875
716
|
// Reset the accumulator.
|
|
@@ -880,25 +721,20 @@ export default class Parser {
|
|
|
880
721
|
text = text + this.read();
|
|
881
722
|
}
|
|
882
723
|
}
|
|
883
|
-
|
|
884
724
|
// If there's more text, save it!
|
|
885
|
-
if (text !== '')
|
|
886
|
-
|
|
725
|
+
if (text !== '')
|
|
726
|
+
segments.push(new TextNode(text));
|
|
887
727
|
// Read the closing delimeter
|
|
888
|
-
if (this.nextIs(delimeter))
|
|
728
|
+
if (this.nextIs(delimeter))
|
|
729
|
+
this.read();
|
|
889
730
|
// If it wasn't closed, add an error
|
|
890
|
-
else
|
|
891
|
-
|
|
892
|
-
return new FormatNode(
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
parseInlineCode(): InlineCodeNode {
|
|
731
|
+
else
|
|
732
|
+
segments.push(new ErrorNode(undefined, 'Unclosed ' + delimeter));
|
|
733
|
+
return new FormatNode(subscript ? 'v' : delimeter, segments);
|
|
734
|
+
}
|
|
735
|
+
parseInlineCode() {
|
|
899
736
|
// Parse the back tick
|
|
900
737
|
this.read();
|
|
901
|
-
|
|
902
738
|
// Read until we encounter a closing back tick.
|
|
903
739
|
let code = '';
|
|
904
740
|
while (this.more() && !this.nextIs('`')) {
|
|
@@ -911,10 +747,9 @@ export default class Parser {
|
|
|
911
747
|
}
|
|
912
748
|
code = code + next;
|
|
913
749
|
}
|
|
914
|
-
|
|
915
750
|
// Read the backtick.
|
|
916
|
-
if (this.nextIs('`'))
|
|
917
|
-
|
|
751
|
+
if (this.nextIs('`'))
|
|
752
|
+
this.read();
|
|
918
753
|
// If there's a letter immediately after a backtick, it's a language for an inline code name
|
|
919
754
|
let language = '';
|
|
920
755
|
let next = this.peek();
|
|
@@ -923,52 +758,42 @@ export default class Parser {
|
|
|
923
758
|
language = language + this.read();
|
|
924
759
|
next = this.peek();
|
|
925
760
|
} while (next !== null && /^[a-z]$/.test(next));
|
|
926
|
-
}
|
|
927
|
-
|
|
761
|
+
}
|
|
762
|
+
else
|
|
763
|
+
language = 'plaintext';
|
|
928
764
|
return new InlineCodeNode(new TextNode(code), language);
|
|
929
765
|
}
|
|
930
|
-
|
|
931
|
-
parseCitations(): CitationsNode {
|
|
766
|
+
parseCitations() {
|
|
932
767
|
let citations = '';
|
|
933
|
-
|
|
934
768
|
// Read the <
|
|
935
769
|
this.read();
|
|
936
770
|
// Read the citations.
|
|
937
771
|
citations = this.readUntilNewlineOr('>');
|
|
938
|
-
if (this.peek() === '>')
|
|
939
|
-
|
|
772
|
+
if (this.peek() === '>')
|
|
773
|
+
this.read();
|
|
940
774
|
// Trim any whitespace, then split by commas, then remove any empty IDs.
|
|
941
775
|
const citationList = citations
|
|
942
776
|
.split(',')
|
|
943
777
|
.map((citation) => citation.trim())
|
|
944
778
|
.filter((citationID) => citationID.length > 0);
|
|
945
|
-
|
|
946
779
|
return new CitationsNode(citationList);
|
|
947
780
|
}
|
|
948
|
-
|
|
949
|
-
parseFootnote(): FootnoteNode {
|
|
781
|
+
parseFootnote() {
|
|
950
782
|
// Read the {
|
|
951
783
|
this.read();
|
|
952
|
-
|
|
953
784
|
// Read the footnote content.
|
|
954
785
|
const footnote = this.parseFormat('}');
|
|
955
|
-
|
|
956
786
|
// Read the closing }
|
|
957
787
|
this.read();
|
|
958
|
-
|
|
959
788
|
return new FootnoteNode(footnote);
|
|
960
789
|
}
|
|
961
|
-
|
|
962
|
-
parseDefinition(): DefinitionNode {
|
|
790
|
+
parseDefinition() {
|
|
963
791
|
// Read the ~
|
|
964
792
|
this.read();
|
|
965
|
-
|
|
966
793
|
// Read the phrase
|
|
967
794
|
const text = this.readUntilNewlineOr('~');
|
|
968
|
-
|
|
969
795
|
// Read the closing ~
|
|
970
796
|
this.read();
|
|
971
|
-
|
|
972
797
|
// Read the glossary entry ID
|
|
973
798
|
let glossaryID = '';
|
|
974
799
|
// Stop at the end of the name or file.
|
|
@@ -977,47 +802,37 @@ export default class Parser {
|
|
|
977
802
|
glossaryID = glossaryID + this.read();
|
|
978
803
|
next = this.peek();
|
|
979
804
|
}
|
|
980
|
-
|
|
981
805
|
return new DefinitionNode(new TextNode(text), glossaryID);
|
|
982
806
|
}
|
|
983
|
-
|
|
984
|
-
parseEscaped(): TextNode | ErrorNode {
|
|
807
|
+
parseEscaped() {
|
|
985
808
|
// Skip the scape and just add the next character.
|
|
986
809
|
this.read();
|
|
987
810
|
const char = this.read();
|
|
988
|
-
if (char)
|
|
989
|
-
|
|
811
|
+
if (char)
|
|
812
|
+
return new TextNode(char);
|
|
990
813
|
return new ErrorNode(undefined, 'Unterminated escape.');
|
|
991
814
|
}
|
|
992
|
-
|
|
993
|
-
parseLink(): LinkNode | ErrorNode {
|
|
815
|
+
parseLink() {
|
|
994
816
|
// Read the [
|
|
995
817
|
this.read();
|
|
996
|
-
|
|
997
818
|
// Read pure text until funding |
|
|
998
819
|
const text = this.readUntilNewlineOr('|');
|
|
999
|
-
|
|
1000
820
|
// Catch missing bars
|
|
1001
821
|
if (this.peek() !== '|') {
|
|
1002
822
|
this.readUntilNewLine();
|
|
1003
823
|
return new ErrorNode(undefined, "Missing '|' in link");
|
|
1004
824
|
}
|
|
1005
|
-
|
|
1006
825
|
// Read the |
|
|
1007
826
|
this.read();
|
|
1008
|
-
|
|
1009
827
|
// Read the link
|
|
1010
828
|
let url = this.readUntilNewlineOr(']');
|
|
1011
|
-
|
|
1012
829
|
// Catch missing closing
|
|
1013
830
|
if (this.peek() !== ']') {
|
|
1014
831
|
this.readUntilNewLine();
|
|
1015
832
|
return new ErrorNode(undefined, 'Missing ] in link');
|
|
1016
833
|
}
|
|
1017
|
-
|
|
1018
834
|
// Read the ]
|
|
1019
835
|
this.read();
|
|
1020
|
-
|
|
1021
836
|
return new LinkNode(new TextNode(text), url);
|
|
1022
837
|
}
|
|
1023
838
|
}
|