├── .editorconfig ├── .github └── workflows │ ├── bb.yml │ └── main.yml ├── .gitignore ├── .npmrc ├── .prettierignore ├── .remarkignore ├── dev ├── index.d.ts ├── index.js └── lib │ ├── index.js │ ├── types.d.ts │ └── types.js ├── license ├── package.json ├── readme.md ├── test ├── fixtures │ ├── attention.json │ ├── attention.md │ ├── autolink.json │ ├── autolink.md │ ├── blockquote.json │ ├── blockquote.md │ ├── character-escape.json │ ├── character-escape.md │ ├── character-reference.json │ ├── character-reference.md │ ├── character-references-everywhere.json │ ├── character-references-everywhere.md │ ├── code-fenced.json │ ├── code-fenced.md │ ├── code-indented.json │ ├── code-indented.md │ ├── code-text.json │ ├── code-text.md │ ├── definition.json │ ├── definition.md │ ├── empty.json │ ├── empty.md │ ├── hard-break-escape.json │ ├── hard-break-escape.md │ ├── hard-break-prefix.json │ ├── hard-break-prefix.md │ ├── heading-atx.json │ ├── heading-atx.md │ ├── heading-setext.json │ ├── heading-setext.md │ ├── html-flow.json │ ├── html-flow.md │ ├── html-text.json │ ├── html-text.md │ ├── image-reference.json │ ├── image-reference.md │ ├── image-resource-eol.json │ ├── image-resource-eol.md │ ├── image-resource.json │ ├── image-resource.md │ ├── link-reference-with-phrasing.json │ ├── link-reference-with-phrasing.md │ ├── link-reference.json │ ├── link-reference.md │ ├── link-resource-eol.json │ ├── link-resource-eol.md │ ├── link-resource.json │ ├── link-resource.md │ ├── list.json │ ├── list.md │ ├── paragraph.json │ ├── paragraph.md │ ├── thematic-break.json │ └── thematic-break.md └── index.js └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.github/workflows/bb.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | main: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: unifiedjs/beep-boop-beta@main 6 | with: 7 | repo-token: ${{secrets.GITHUB_TOKEN}} 8 | name: bb 9 | on: 10 | issues: 11 | types: [closed, edited, labeled, opened, reopened, unlabeled] 12 | pull_request_target: 13 | types: [closed, edited, labeled, opened, reopened, unlabeled] 14 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | main: 3 | name: ${{matrix.node}} 4 | runs-on: ubuntu-latest 5 | steps: 6 | - uses: actions/checkout@v4 7 | - uses: actions/setup-node@v4 8 | with: 9 | node-version: ${{matrix.node}} 10 | - run: npm install 11 | - run: npm test 12 | - uses: codecov/codecov-action@v5 13 | strategy: 14 | matrix: 15 | node: 16 | - lts/hydrogen 17 | - node 18 | name: main 19 | on: 20 | - pull_request 21 | - push 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.d.ts 2 | *.log 3 | *.map 4 | *.tsbuildinfo 5 | .DS_Store 6 | /index.js 7 | /lib/ 8 | coverage/ 9 | node_modules/ 10 | yarn.lock 11 | !/dev/lib/types.d.ts 12 | !/dev/index.d.ts 13 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | ignore-scripts=true 2 | package-lock=false 3 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | coverage/ 2 | *.md 3 | -------------------------------------------------------------------------------- /.remarkignore: -------------------------------------------------------------------------------- 1 | micromark/ 2 | test/ 3 | -------------------------------------------------------------------------------- /dev/index.d.ts: -------------------------------------------------------------------------------- 1 | export type {Encoding, Token, Value} from 'micromark-util-types' 2 | export type { 3 | CompileContext, 4 | CompileData, 5 | Extension, 6 | Handles, 7 | Handle, 8 | OnEnterError, 9 | OnExitError, 10 | Options, 11 | Transform 12 | } from './lib/types.js' 13 | export {fromMarkdown} from './lib/index.js' 14 | 15 | declare module 'micromark-util-types' { 16 | interface TokenTypeMap { 17 | listItem: 'listItem' 18 | } 19 | 20 | interface Token { 21 | _spread?: boolean 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /dev/index.js: -------------------------------------------------------------------------------- 1 | // Note: types exported from `index.d.ts`. 2 | export {fromMarkdown} from './lib/index.js' 3 | -------------------------------------------------------------------------------- /dev/lib/types.d.ts: -------------------------------------------------------------------------------- 1 | import type {Nodes, Parent, PhrasingContent, Root} from 'mdast' 2 | import type {ParseOptions, Token} from 'micromark-util-types' 3 | 4 | /** 5 | * Compiler context. 6 | */ 7 | export interface CompileContext { 8 | /** 9 | * Configuration. 10 | */ 11 | config: Config 12 | /** 13 | * Info passed around; 14 | * key/value store. 15 | */ 16 | data: CompileData 17 | /** 18 | * Stack of nodes. 19 | */ 20 | stack: Array 21 | /** 22 | * Stack of tokens. 23 | */ 24 | tokenStack: Array 25 | 26 | /** 27 | * Capture some of the output data. 28 | * 29 | * @param this 30 | * Context. 31 | * @returns 32 | * Nothing. 33 | */ 34 | buffer(this: CompileContext): undefined 35 | 36 | /** 37 | * Enter a node. 38 | * 39 | * @param this 40 | * Context. 41 | * @param node 42 | * Node. 43 | * @param token 44 | * Token. 45 | * @param onError 46 | * Error handler. 47 | * @returns 48 | * Nothing. 49 | */ 50 | enter( 51 | this: CompileContext, 52 | node: Nodes, 53 | token: Token, 54 | onError?: OnEnterError | null | undefined 55 | ): undefined 56 | 57 | /** 58 | * Exit a node. 59 | * 60 | * @param this 61 | * Context. 62 | * @param token 63 | * Token. 64 | * @param onError 65 | * Error handler. 66 | * @returns 67 | * Nothing. 68 | */ 69 | exit( 70 | this: CompileContext, 71 | token: Token, 72 | onError?: OnExitError | null | undefined 73 | ): undefined 74 | 75 | /** 76 | * Stop capturing and access the output data. 77 | * 78 | * @param this 79 | * Context. 80 | * @returns 81 | * Nothing. 82 | */ 83 | resume(this: CompileContext): string 84 | 85 | /** 86 | * Get the source text that spans a token (or location). 87 | * 88 | * @param token 89 | * Start/end in stream. 90 | * @param expandTabs 91 | * Whether to expand tabs. 92 | * @returns 93 | * Serialized chunks. 94 | */ 95 | sliceSerialize( 96 | token: Pick, 97 | expandTabs?: boolean | undefined 98 | ): string 99 | } 100 | 101 | /** 102 | * Interface of tracked data. 103 | * 104 | * When working on extensions that use more data, extend the corresponding 105 | * interface to register their types: 106 | * 107 | * ```ts 108 | * declare module 'mdast-util-from-markdown' { 109 | * interface CompileData { 110 | * // Register a new field. 111 | * mathFlowInside?: boolean | undefined 112 | * } 113 | * } 114 | * ``` 115 | */ 116 | export interface CompileData { 117 | /** 118 | * Whether we’re inside a hard break. 119 | */ 120 | atHardBreak?: boolean | undefined 121 | 122 | /** 123 | * Current character reference type. 124 | */ 125 | characterReferenceType?: 126 | | 'characterReferenceMarkerHexadecimal' 127 | | 'characterReferenceMarkerNumeric' 128 | | undefined 129 | 130 | /** 131 | * Whether a first list item value (`1` in `1. a`) is expected. 132 | */ 133 | expectingFirstListItemValue?: boolean | undefined 134 | 135 | /** 136 | * Whether we’re in flow code. 137 | */ 138 | flowCodeInside?: boolean | undefined 139 | 140 | /** 141 | * Whether we’re in a reference. 142 | */ 143 | inReference?: boolean | undefined 144 | 145 | /** 146 | * Whether we’re expecting a line ending from a setext heading, which can be slurped. 147 | */ 148 | setextHeadingSlurpLineEnding?: boolean | undefined 149 | 150 | /** 151 | * Current reference. 152 | */ 153 | referenceType?: 'collapsed' | 'full' | undefined 154 | } 155 | 156 | /** 157 | * Configuration. 158 | * 159 | * We have our defaults, but extensions will add more. 160 | */ 161 | export interface Config { 162 | /** 163 | * Token types where line endings are used. 164 | */ 165 | canContainEols: Array 166 | /** 167 | * Opening handles. 168 | */ 169 | enter: Handles 170 | /** 171 | * Closing handles. 172 | */ 173 | exit: Handles 174 | /** 175 | * Tree transforms. 176 | */ 177 | transforms: Array 178 | } 179 | 180 | /** 181 | * Change how markdown tokens from micromark are turned into mdast. 182 | */ 183 | export interface Extension { 184 | /** 185 | * Token types where line endings are used. 186 | */ 187 | canContainEols?: Array | null | undefined 188 | /** 189 | * Opening handles. 190 | */ 191 | enter?: Handles | null | undefined 192 | /** 193 | * Closing handles. 194 | */ 195 | exit?: Handles | null | undefined 196 | /** 197 | * Tree transforms. 198 | */ 199 | transforms?: Array | null | undefined 200 | } 201 | 202 | /** 203 | * Internal fragment. 204 | */ 205 | export interface Fragment extends Parent { 206 | /** 207 | * Node type. 208 | */ 209 | type: 'fragment' 210 | /** 211 | * Children. 212 | */ 213 | children: Array 214 | } 215 | 216 | /** 217 | * Token types mapping to handles 218 | */ 219 | export type Handles = Record 220 | 221 | /** 222 | * Handle a token. 223 | * 224 | * @param this 225 | * Context. 226 | * @param token 227 | * Current token. 228 | * @returns 229 | * Nothing. 230 | */ 231 | export type Handle = (this: CompileContext, token: Token) => undefined | void 232 | 233 | /** 234 | * Handle the case where the `right` token is open, but it is closed (by the 235 | * `left` token) or because we reached the end of the document. 236 | * 237 | * @param this 238 | * Context. 239 | * @param left 240 | * Left token. 241 | * @param right 242 | * Right token. 243 | * @returns 244 | * Nothing. 245 | */ 246 | export type OnEnterError = ( 247 | this: Omit, 248 | left: Token | undefined, 249 | right: Token 250 | ) => undefined 251 | 252 | /** 253 | * Handle the case where the `right` token is open but it is closed by 254 | * exiting the `left` token. 255 | * 256 | * @param this 257 | * Context. 258 | * @param left 259 | * Left token. 260 | * @param right 261 | * Right token. 262 | * @returns 263 | * Nothing. 264 | */ 265 | export type OnExitError = ( 266 | this: Omit, 267 | left: Token, 268 | right: Token 269 | ) => undefined 270 | 271 | /** 272 | * Configuration. 273 | */ 274 | export interface Options extends ParseOptions { 275 | /** 276 | * Extensions for this utility to change how tokens are turned into a tree. 277 | */ 278 | mdastExtensions?: Array> | null | undefined 279 | } 280 | 281 | /** 282 | * Open token on the stack, 283 | * with an optional error handler for when that token isn’t closed properly. 284 | */ 285 | export type TokenTuple = [token: Token, onError: OnEnterError | undefined] 286 | 287 | /** 288 | * Extra transform, to change the AST afterwards. 289 | * 290 | * @param tree 291 | * Tree to transform. 292 | * @returns 293 | * New tree or nothing (in which case the current tree is used). 294 | */ 295 | export type Transform = (tree: Root) => Root | null | undefined | void 296 | -------------------------------------------------------------------------------- /dev/lib/types.js: -------------------------------------------------------------------------------- 1 | // Note: types exposed from `types.d.ts`. 2 | export {} 3 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) Titus Wormer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Titus Wormer (https://wooorm.com)", 3 | "bugs": "https://github.com/syntax-tree/mdast-util-from-markdown/issues", 4 | "contributors": [ 5 | "Titus Wormer (https://wooorm.com)" 6 | ], 7 | "dependencies": { 8 | "@types/mdast": "^4.0.0", 9 | "@types/unist": "^3.0.0", 10 | "decode-named-character-reference": "^1.0.0", 11 | "devlop": "^1.0.0", 12 | "mdast-util-to-string": "^4.0.0", 13 | "micromark": "^4.0.0", 14 | "micromark-util-decode-numeric-character-reference": "^2.0.0", 15 | "micromark-util-decode-string": "^2.0.0", 16 | "micromark-util-normalize-identifier": "^2.0.0", 17 | "micromark-util-symbol": "^2.0.0", 18 | "micromark-util-types": "^2.0.0", 19 | "unist-util-stringify-position": "^4.0.0" 20 | }, 21 | "description": "mdast utility to parse markdown", 22 | "devDependencies": { 23 | "@types/node": "^22.0.0", 24 | "c8": "^10.0.0", 25 | "commonmark.json": "^0.31.0", 26 | "esbuild": "^0.25.0", 27 | "gzip-size-cli": "^5.0.0", 28 | "hast-util-from-html": "^2.0.0", 29 | "hast-util-to-html": "^9.0.0", 30 | "mdast-util-to-hast": "^13.0.0", 31 | "micromark-build": "^2.0.0", 32 | "prettier": "^3.0.0", 33 | "remark-cli": "^12.0.0", 34 | "remark-preset-wooorm": "^11.0.0", 35 | "terser": "^5.0.0", 36 | "type-coverage": "^2.0.0", 37 | "typescript": "^5.0.0", 38 | "xo": "^0.60.0" 39 | }, 40 | "exports": { 41 | "development": "./dev/index.js", 42 | "default": "./index.js" 43 | }, 44 | "files": [ 45 | "dev/", 46 | "lib/", 47 | "index.d.ts", 48 | "index.js" 49 | ], 50 | "funding": { 51 | "type": "opencollective", 52 | "url": "https://opencollective.com/unified" 53 | }, 54 | "keywords": [ 55 | "ast", 56 | "markdown", 57 | "markup", 58 | "mdast-util", 59 | "mdast", 60 | "parse", 61 | "syntax", 62 | "tree", 63 | "unist", 64 | "utility", 65 | "util" 66 | ], 67 | "license": "MIT", 68 | "name": "mdast-util-from-markdown", 69 | "prettier": { 70 | "bracketSpacing": false, 71 | "semi": false, 72 | "singleQuote": true, 73 | "tabWidth": 2, 74 | "trailingComma": "none", 75 | "useTabs": false 76 | }, 77 | "remarkConfig": { 78 | "plugins": [ 79 | "remark-preset-wooorm" 80 | ] 81 | }, 82 | "repository": "syntax-tree/mdast-util-from-markdown", 83 | "scripts": { 84 | "build": "tsc --build --clean && tsc --build && type-coverage && micromark-build && esbuild . --bundle --minify | terser | gzip-size --raw", 85 | "format": "remark --frail --quiet --output -- . && prettier --log-level warn --write -- . && xo --fix", 86 | "test-api-dev": "node --conditions development test/index.js", 87 | "test-api-prod": "node --conditions production test/index.js", 88 | "test-api": "npm run test-api-dev && npm run test-api-prod", 89 | "test-coverage": "c8 --100 --reporter lcov -- npm run test-api", 90 | "test": "npm run build && npm run format && npm run test-coverage" 91 | }, 92 | "sideEffects": false, 93 | "typeCoverage": { 94 | "atLeast": 100, 95 | "strict": true 96 | }, 97 | "type": "module", 98 | "version": "2.0.2", 99 | "xo": { 100 | "overrides": [ 101 | { 102 | "files": [ 103 | "**/*.d.ts" 104 | ], 105 | "rules": { 106 | "@typescript-eslint/array-type": [ 107 | "error", 108 | { 109 | "default": "generic" 110 | } 111 | ], 112 | "@typescript-eslint/ban-types": [ 113 | "error", 114 | { 115 | "extendDefaults": true 116 | } 117 | ], 118 | "@typescript-eslint/consistent-type-definitions": [ 119 | "error", 120 | "interface" 121 | ] 122 | } 123 | }, 124 | { 125 | "files": "test/**/*.js", 126 | "rules": { 127 | "no-await-in-loop": "off" 128 | } 129 | } 130 | ], 131 | "prettier": true, 132 | "rules": { 133 | "complexity": "off", 134 | "max-depth": "off", 135 | "unicorn/prefer-at": "off", 136 | "unicorn/prefer-string-replace-all": "off" 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # mdast-util-from-markdown 2 | 3 | [![Build][badge-build-image]][badge-build-url] 4 | [![Coverage][badge-coverage-image]][badge-coverage-url] 5 | [![Downloads][badge-downloads-image]][badge-downloads-url] 6 | [![Size][badge-size-image]][badge-size-url] 7 | 8 | **[mdast][github-mdast]** utility that turns markdown into a syntax tree. 9 | 10 | ## Contents 11 | 12 | * [What is this?](#what-is-this) 13 | * [When should I use this?](#when-should-i-use-this) 14 | * [Install](#install) 15 | * [Use](#use) 16 | * [API](#api) 17 | * [`fromMarkdown(value[, encoding][, options])`](#frommarkdownvalue-encoding-options) 18 | * [`CompileContext`](#compilecontext) 19 | * [`CompileData`](#compiledata) 20 | * [`Encoding`](#encoding) 21 | * [`Extension`](#extension) 22 | * [`Handle`](#handle) 23 | * [`OnEnterError`](#onentererror) 24 | * [`OnExitError`](#onexiterror) 25 | * [`Options`](#options) 26 | * [`Token`](#token) 27 | * [`Transform`](#transform) 28 | * [`Value`](#value) 29 | * [List of extensions](#list-of-extensions) 30 | * [Syntax](#syntax) 31 | * [Syntax tree](#syntax-tree) 32 | * [Types](#types) 33 | * [Compatibility](#compatibility) 34 | * [Security](#security) 35 | * [Related](#related) 36 | * [Contribute](#contribute) 37 | * [License](#license) 38 | 39 | ## What is this? 40 | 41 | This package is a utility that takes markdown input and turns it into an 42 | [mdast][github-mdast] syntax tree. 43 | 44 | This utility uses [`micromark`][github-micromark], 45 | which turns markdown into tokens, 46 | and then turns those tokens into nodes. 47 | This package is used inside [`remark-parse`][github-remark-parse], 48 | which focusses on 49 | making it easier to transform content by abstracting these internals away. 50 | 51 | ## When should I use this? 52 | 53 | If you want to handle syntax trees manually, use this. 54 | When you *just* want to turn markdown into HTML, 55 | use [`micromark`][github-micromark] instead. 56 | For an easier time processing content, 57 | use the **[remark][github-remark]** ecosystem instead. 58 | 59 | You can combine this package with other packages to add syntax extensions to 60 | markdown. 61 | Notable examples that deeply integrate with this package are 62 | [`mdast-util-mdx`][github-mdast-util-mdx], 63 | [`mdast-util-gfm`][github-mdast-util-gfm], 64 | [`mdast-util-frontmatter`][github-mdast-util-frontmatter], 65 | [`mdast-util-math`][github-mdast-util-math], and 66 | [`mdast-util-directive`][github-mdast-util-directive]. 67 | 68 | ## Install 69 | 70 | This package is [ESM only][github-gist-esm]. 71 | In Node.js (version 16+), install with [npm][npmjs-install]: 72 | 73 | ```sh 74 | npm install mdast-util-from-markdown 75 | ``` 76 | 77 | In Deno with [`esm.sh`][esmsh]: 78 | 79 | ```js 80 | import {fromMarkdown} from 'https://esm.sh/mdast-util-from-markdown@2' 81 | ``` 82 | 83 | In browsers with [`esm.sh`][esmsh]: 84 | 85 | ```html 86 | 89 | ``` 90 | 91 | ## Use 92 | 93 | Say we have the following markdown file `example.md`: 94 | 95 | ```markdown 96 | ## Hello, *World*! 97 | ``` 98 | 99 | …and our module `example.js` looks as follows: 100 | 101 | ```js 102 | import fs from 'node:fs/promises' 103 | import {fromMarkdown} from 'mdast-util-from-markdown' 104 | 105 | const doc = await fs.readFile('example.md') 106 | const tree = fromMarkdown(doc) 107 | 108 | console.log(tree) 109 | ``` 110 | 111 | …now running `node example.js` yields (positional info removed for brevity): 112 | 113 | ```js 114 | { 115 | type: 'root', 116 | children: [ 117 | { 118 | type: 'heading', 119 | depth: 2, 120 | children: [ 121 | {type: 'text', value: 'Hello, '}, 122 | {type: 'emphasis', children: [{type: 'text', value: 'World'}]}, 123 | {type: 'text', value: '!'} 124 | ] 125 | } 126 | ] 127 | } 128 | ``` 129 | 130 | ## API 131 | 132 | This package exports the identifier [`fromMarkdown`][api-from-markdown]. 133 | There is no default export. 134 | 135 | The export map supports the [`development` condition][node-packages-conditions]. 136 | Run `node --conditions development example.js` to get instrumented dev code. 137 | Without this condition, production code is loaded. 138 | 139 | ### `fromMarkdown(value[, encoding][, options])` 140 | 141 | Turn markdown into a syntax tree. 142 | 143 | ###### Overloads 144 | 145 | * `(value: Value, encoding: Encoding, options?: Options) => Root` 146 | * `(value: Value, options?: Options) => Root` 147 | 148 | ###### Parameters 149 | 150 | * `value` ([`Value`][api-value]) 151 | — markdown to parse 152 | * `encoding` ([`Encoding`][api-encoding], default: `'utf8'`) 153 | — [character encoding][node-util-encoding] for when `value` is 154 | [`Uint8Array`][mozilla-uint8-array] 155 | * `options` ([`Options`][api-options], optional) 156 | — configuration 157 | 158 | ###### Returns 159 | 160 | mdast tree ([`Root`][github-mdast-root]). 161 | 162 | ### `CompileContext` 163 | 164 | mdast compiler context (TypeScript type). 165 | 166 | ###### Fields 167 | 168 | * `stack` ([`Array`][github-mdast-nodes]) 169 | — stack of nodes 170 | * `tokenStack` (`Array<[Token, OnEnterError | undefined]>`) 171 | — stack of tokens 172 | * `data` ([`CompileData`][api-compile-data]) 173 | — info passed around; key/value store 174 | * `buffer` (`() => undefined`) 175 | — capture some of the output data 176 | * `resume` (`() => string`) 177 | — stop capturing and access the output data 178 | * `enter` (`(node: Node, token: Token, onError?: OnEnterError) => undefined`) 179 | — enter a node 180 | * `exit` (`(token: Token, onError?: OnExitError) => undefined`) 181 | — exit a node 182 | * `sliceSerialize` (`(token: Token, expandTabs?: boolean) => string`) 183 | — get the string value of a token 184 | * `config` (`Required`) 185 | — configuration 186 | 187 | ### `CompileData` 188 | 189 | Interface of tracked data (TypeScript type). 190 | 191 | ###### Type 192 | 193 | ```ts 194 | interface CompileData { /* see code */ } 195 | ``` 196 | 197 | When working on extensions that use more data, extend the corresponding 198 | interface to register their types: 199 | 200 | ```ts 201 | declare module 'mdast-util-from-markdown' { 202 | interface CompileData { 203 | // Register a new field. 204 | mathFlowInside?: boolean | undefined 205 | } 206 | } 207 | ``` 208 | 209 | ### `Encoding` 210 | 211 | Encodings supported by the [`Uint8Array`][mozilla-uint8-array] class 212 | (TypeScript type). 213 | 214 | See [`micromark`][github-micromark-api] for more info. 215 | 216 | ###### Type 217 | 218 | ```ts 219 | type Encoding = 'utf8' | /* … */ 220 | ``` 221 | 222 | ### `Extension` 223 | 224 | Change how markdown tokens from micromark are turned into mdast (TypeScript 225 | type). 226 | 227 | ###### Properties 228 | 229 | * `canContainEols` (`Array`, optional) 230 | — token types where line endings are used 231 | * `enter` ([`Record`][api-handle], optional) 232 | — opening handles 233 | * `exit` ([`Record`][api-handle], optional) 234 | — closing handles 235 | * `transforms` ([`Array`][api-transform], optional) 236 | — tree transforms 237 | 238 | ### `Handle` 239 | 240 | Handle a token (TypeScript type). 241 | 242 | ###### Parameters 243 | 244 | * `this` ([`CompileContext`][api-compile-context]) 245 | — context 246 | * `token` ([`Token`][api-token]) 247 | — current token 248 | 249 | ###### Returns 250 | 251 | Nothing (`undefined`). 252 | 253 | ### `OnEnterError` 254 | 255 | Handle the case where the `right` token is open, but it is closed (by the 256 | `left` token) or because we reached the end of the document (TypeScript type). 257 | 258 | ###### Parameters 259 | 260 | * `this` ([`CompileContext`][api-compile-context]) 261 | — context 262 | * `left` ([`Token`][api-token] or `undefined`) 263 | — left token 264 | * `right` ([`Token`][api-token]) 265 | — right token 266 | 267 | ###### Returns 268 | 269 | Nothing (`undefined`). 270 | 271 | ### `OnExitError` 272 | 273 | Handle the case where the `right` token is open but it is closed by 274 | exiting the `left` token (TypeScript type). 275 | 276 | ###### Parameters 277 | 278 | * `this` ([`CompileContext`][api-compile-context]) 279 | — context 280 | * `left` ([`Token`][api-token]) 281 | — left token 282 | * `right` ([`Token`][api-token]) 283 | — right token 284 | 285 | ###### Returns 286 | 287 | Nothing (`undefined`). 288 | 289 | ### `Options` 290 | 291 | Configuration (TypeScript type). 292 | 293 | ###### Properties 294 | 295 | * `extensions` 296 | ([`Array`][github-micromark-extension], optional) 297 | — micromark extensions to change how markdown is parsed 298 | * `mdastExtensions` 299 | ([`Array>`][api-extension], 300 | optional) 301 | — extensions for this utility to change how tokens are turned into a tree 302 | 303 | ### `Token` 304 | 305 | Token from micromark (TypeScript type). 306 | 307 | ###### Type 308 | 309 | ```ts 310 | type Token = { /* … */ } 311 | ``` 312 | 313 | ### `Transform` 314 | 315 | Extra transform, to change the AST afterwards (TypeScript type). 316 | 317 | ###### Parameters 318 | 319 | * `tree` ([`Root`][github-mdast-root]) 320 | — tree to transform 321 | 322 | ###### Returns 323 | 324 | New tree ([`Root`][github-mdast-root]) or nothing 325 | (in which case the current tree is used). 326 | 327 | ### `Value` 328 | 329 | Contents of the file (TypeScript type). 330 | 331 | See [`micromark`][github-micromark-api] for more info. 332 | 333 | ###### Type 334 | 335 | ```ts 336 | type Value = Uint8Array | string 337 | ``` 338 | 339 | ## List of extensions 340 | 341 | * [`syntax-tree/mdast-util-directive`][github-mdast-util-directive] 342 | — directives 343 | * [`syntax-tree/mdast-util-frontmatter`][github-mdast-util-frontmatter] 344 | — frontmatter (YAML, TOML, more) 345 | * [`syntax-tree/mdast-util-gfm`][github-mdast-util-gfm] 346 | — GFM 347 | * [`syntax-tree/mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal) 348 | — GFM autolink literals 349 | * [`syntax-tree/mdast-util-gfm-footnote`](https://github.com/syntax-tree/mdast-util-gfm-footnote) 350 | — GFM footnotes 351 | * [`syntax-tree/mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough) 352 | — GFM strikethrough 353 | * [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table) 354 | — GFM tables 355 | * [`syntax-tree/mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item) 356 | — GFM task list items 357 | * [`syntax-tree/mdast-util-math`][github-mdast-util-math] 358 | — math 359 | * [`syntax-tree/mdast-util-mdx`][github-mdast-util-mdx] 360 | — MDX 361 | * [`syntax-tree/mdast-util-mdx-expression`](https://github.com/syntax-tree/mdast-util-mdx-expression) 362 | — MDX expressions 363 | * [`syntax-tree/mdast-util-mdx-jsx`](https://github.com/syntax-tree/mdast-util-mdx-jsx) 364 | — MDX JSX 365 | * [`syntax-tree/mdast-util-mdxjs-esm`](https://github.com/syntax-tree/mdast-util-mdxjs-esm) 366 | — MDX ESM 367 | 368 | ## Syntax 369 | 370 | Markdown is parsed according to CommonMark. 371 | Extensions can add support for other syntax. 372 | If you’re interested in extending markdown, 373 | [more information is available in micromark’s 374 | readme][github-micromark-extension]. 375 | 376 | ## Syntax tree 377 | 378 | The syntax tree is [mdast][github-mdast]. 379 | 380 | ## Types 381 | 382 | This package is fully typed with [TypeScript][]. 383 | It exports the additional types 384 | [`CompileContext`][api-compile-context], 385 | [`CompileData`][api-compile-data], 386 | [`Encoding`][api-encoding], 387 | [`Extension`][api-extension], 388 | [`Handle`][api-handle], 389 | [`OnEnterError`][api-on-enter-error], 390 | [`OnExitError`][api-on-exit-error], 391 | [`Options`][api-options], 392 | [`Token`][api-token], 393 | [`Transform`][api-transform], and 394 | [`Value`][api-value]. 395 | 396 | ## Compatibility 397 | 398 | Projects maintained by the unified collective are compatible with maintained 399 | versions of Node.js. 400 | 401 | When we cut a new major release, we drop support for unmaintained versions of 402 | Node. 403 | This means we try to keep the current release line, 404 | `mdast-util-from-markdown@^2`, compatible with Node.js 16. 405 | 406 | ## Security 407 | 408 | As markdown is sometimes used for HTML, and improper use of HTML can open you up 409 | to a [cross-site scripting (XSS)][wikipedia-xss] attack, use of `mdast-util-from-markdown` 410 | can also be unsafe. 411 | When going to HTML, use this utility in combination with 412 | [`hast-util-sanitize`][github-hast-util-sanitize] to make the tree safe. 413 | 414 | ## Related 415 | 416 | * [`syntax-tree/mdast-util-to-markdown`](https://github.com/syntax-tree/mdast-util-to-markdown) 417 | — serialize mdast as markdown 418 | * [`micromark/micromark`][github-micromark] 419 | — parse markdown 420 | * [`remarkjs/remark`][github-remark] 421 | — process markdown 422 | 423 | ## Contribute 424 | 425 | See [`contributing.md`][health-contributing] 426 | in 427 | [`syntax-tree/.github`][health] 428 | for ways to get started. 429 | See [`support.md`][health-support] for ways to get help. 430 | 431 | This project has a [code of conduct][health-coc]. 432 | By interacting with this repository, organization, or community you agree to 433 | abide by its terms. 434 | 435 | ## License 436 | 437 | [MIT][file-license] © [Titus Wormer][wooorm] 438 | 439 | 440 | 441 | [api-compile-context]: #compilecontext 442 | 443 | [api-compile-data]: #compiledata 444 | 445 | [api-encoding]: #encoding 446 | 447 | [api-extension]: #extension 448 | 449 | [api-from-markdown]: #frommarkdownvalue-encoding-options 450 | 451 | [api-handle]: #handle 452 | 453 | [api-on-enter-error]: #onentererror 454 | 455 | [api-on-exit-error]: #onexiterror 456 | 457 | [api-options]: #options 458 | 459 | [api-token]: #token 460 | 461 | [api-transform]: #transform 462 | 463 | [api-value]: #value 464 | 465 | [badge-build-image]: https://github.com/syntax-tree/mdast-util-from-markdown/workflows/main/badge.svg 466 | 467 | [badge-build-url]: https://github.com/syntax-tree/mdast-util-from-markdown/actions 468 | 469 | [badge-coverage-image]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-from-markdown.svg 470 | 471 | [badge-coverage-url]: https://codecov.io/github/syntax-tree/mdast-util-from-markdown 472 | 473 | [badge-downloads-image]: https://img.shields.io/npm/dm/mdast-util-from-markdown.svg 474 | 475 | [badge-downloads-url]: https://www.npmjs.com/package/mdast-util-from-markdown 476 | 477 | [badge-size-image]: https://img.shields.io/bundlejs/size/mdast-util-from-markdown 478 | 479 | [badge-size-url]: https://bundlejs.com/?q=mdast-util-from-markdown 480 | 481 | [esmsh]: https://esm.sh 482 | 483 | [file-license]: license 484 | 485 | [github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c 486 | 487 | [github-hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize 488 | 489 | [github-mdast]: https://github.com/syntax-tree/mdast 490 | 491 | [github-mdast-nodes]: https://github.com/syntax-tree/mdast#nodes 492 | 493 | [github-mdast-root]: https://github.com/syntax-tree/mdast#root 494 | 495 | [github-mdast-util-directive]: https://github.com/syntax-tree/mdast-util-directive 496 | 497 | [github-mdast-util-frontmatter]: https://github.com/syntax-tree/mdast-util-frontmatter 498 | 499 | [github-mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm 500 | 501 | [github-mdast-util-math]: https://github.com/syntax-tree/mdast-util-math 502 | 503 | [github-mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx 504 | 505 | [github-micromark]: https://github.com/micromark/micromark 506 | 507 | [github-micromark-api]: https://github.com/micromark/micromark/tree/main/packages/micromark#micromarkvalue-encoding-options 508 | 509 | [github-micromark-extension]: https://github.com/micromark/micromark#extensions 510 | 511 | [github-remark]: https://github.com/remarkjs/remark 512 | 513 | [github-remark-parse]: https://github.com/remarkjs/remark/tree/main/packages/remark-parse 514 | 515 | [health]: https://github.com/syntax-tree/.github 516 | 517 | [health-coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md 518 | 519 | [health-contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md 520 | 521 | [health-support]: https://github.com/syntax-tree/.github/blob/main/support.md 522 | 523 | [mozilla-uint8-array]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array 524 | 525 | [node-packages-conditions]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions 526 | 527 | [node-util-encoding]: https://nodejs.org/api/util.html#whatwg-supported-encodings 528 | 529 | [npmjs-install]: https://docs.npmjs.com/cli/install 530 | 531 | [typescript]: https://www.typescriptlang.org 532 | 533 | [wikipedia-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting 534 | 535 | [wooorm]: https://wooorm.com 536 | -------------------------------------------------------------------------------- /test/fixtures/attention.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "emphasis", 9 | "children": [ 10 | { 11 | "type": "text", 12 | "value": "a", 13 | "position": { 14 | "start": { 15 | "line": 1, 16 | "column": 2, 17 | "offset": 1 18 | }, 19 | "end": { 20 | "line": 1, 21 | "column": 3, 22 | "offset": 2 23 | } 24 | } 25 | } 26 | ], 27 | "position": { 28 | "start": { 29 | "line": 1, 30 | "column": 1, 31 | "offset": 0 32 | }, 33 | "end": { 34 | "line": 1, 35 | "column": 4, 36 | "offset": 3 37 | } 38 | } 39 | }, 40 | { 41 | "type": "text", 42 | "value": "\n", 43 | "position": { 44 | "start": { 45 | "line": 1, 46 | "column": 4, 47 | "offset": 3 48 | }, 49 | "end": { 50 | "line": 2, 51 | "column": 1, 52 | "offset": 4 53 | } 54 | } 55 | }, 56 | { 57 | "type": "strong", 58 | "children": [ 59 | { 60 | "type": "text", 61 | "value": "b", 62 | "position": { 63 | "start": { 64 | "line": 2, 65 | "column": 3, 66 | "offset": 6 67 | }, 68 | "end": { 69 | "line": 2, 70 | "column": 4, 71 | "offset": 7 72 | } 73 | } 74 | } 75 | ], 76 | "position": { 77 | "start": { 78 | "line": 2, 79 | "column": 1, 80 | "offset": 4 81 | }, 82 | "end": { 83 | "line": 2, 84 | "column": 6, 85 | "offset": 9 86 | } 87 | } 88 | }, 89 | { 90 | "type": "text", 91 | "value": "\n", 92 | "position": { 93 | "start": { 94 | "line": 2, 95 | "column": 6, 96 | "offset": 9 97 | }, 98 | "end": { 99 | "line": 3, 100 | "column": 1, 101 | "offset": 10 102 | } 103 | } 104 | }, 105 | { 106 | "type": "emphasis", 107 | "children": [ 108 | { 109 | "type": "strong", 110 | "children": [ 111 | { 112 | "type": "text", 113 | "value": "c", 114 | "position": { 115 | "start": { 116 | "line": 3, 117 | "column": 4, 118 | "offset": 13 119 | }, 120 | "end": { 121 | "line": 3, 122 | "column": 5, 123 | "offset": 14 124 | } 125 | } 126 | } 127 | ], 128 | "position": { 129 | "start": { 130 | "line": 3, 131 | "column": 2, 132 | "offset": 11 133 | }, 134 | "end": { 135 | "line": 3, 136 | "column": 7, 137 | "offset": 16 138 | } 139 | } 140 | } 141 | ], 142 | "position": { 143 | "start": { 144 | "line": 3, 145 | "column": 1, 146 | "offset": 10 147 | }, 148 | "end": { 149 | "line": 3, 150 | "column": 8, 151 | "offset": 17 152 | } 153 | } 154 | }, 155 | { 156 | "type": "text", 157 | "value": "\n", 158 | "position": { 159 | "start": { 160 | "line": 3, 161 | "column": 8, 162 | "offset": 17 163 | }, 164 | "end": { 165 | "line": 4, 166 | "column": 1, 167 | "offset": 18 168 | } 169 | } 170 | }, 171 | { 172 | "type": "strong", 173 | "children": [ 174 | { 175 | "type": "strong", 176 | "children": [ 177 | { 178 | "type": "text", 179 | "value": "d", 180 | "position": { 181 | "start": { 182 | "line": 4, 183 | "column": 5, 184 | "offset": 22 185 | }, 186 | "end": { 187 | "line": 4, 188 | "column": 6, 189 | "offset": 23 190 | } 191 | } 192 | } 193 | ], 194 | "position": { 195 | "start": { 196 | "line": 4, 197 | "column": 3, 198 | "offset": 20 199 | }, 200 | "end": { 201 | "line": 4, 202 | "column": 8, 203 | "offset": 25 204 | } 205 | } 206 | } 207 | ], 208 | "position": { 209 | "start": { 210 | "line": 4, 211 | "column": 1, 212 | "offset": 18 213 | }, 214 | "end": { 215 | "line": 4, 216 | "column": 10, 217 | "offset": 27 218 | } 219 | } 220 | } 221 | ], 222 | "position": { 223 | "start": { 224 | "line": 1, 225 | "column": 1, 226 | "offset": 0 227 | }, 228 | "end": { 229 | "line": 4, 230 | "column": 10, 231 | "offset": 27 232 | } 233 | } 234 | }, 235 | { 236 | "type": "paragraph", 237 | "children": [ 238 | { 239 | "type": "emphasis", 240 | "children": [ 241 | { 242 | "type": "emphasis", 243 | "children": [ 244 | { 245 | "type": "text", 246 | "value": "e", 247 | "position": { 248 | "start": { 249 | "line": 6, 250 | "column": 3, 251 | "offset": 31 252 | }, 253 | "end": { 254 | "line": 6, 255 | "column": 4, 256 | "offset": 32 257 | } 258 | } 259 | } 260 | ], 261 | "position": { 262 | "start": { 263 | "line": 6, 264 | "column": 2, 265 | "offset": 30 266 | }, 267 | "end": { 268 | "line": 6, 269 | "column": 5, 270 | "offset": 33 271 | } 272 | } 273 | }, 274 | { 275 | "type": "text", 276 | "value": "\n", 277 | "position": { 278 | "start": { 279 | "line": 6, 280 | "column": 5, 281 | "offset": 33 282 | }, 283 | "end": { 284 | "line": 7, 285 | "column": 1, 286 | "offset": 34 287 | } 288 | } 289 | }, 290 | { 291 | "type": "emphasis", 292 | "children": [ 293 | { 294 | "type": "text", 295 | "value": "f", 296 | "position": { 297 | "start": { 298 | "line": 7, 299 | "column": 2, 300 | "offset": 35 301 | }, 302 | "end": { 303 | "line": 7, 304 | "column": 3, 305 | "offset": 36 306 | } 307 | } 308 | } 309 | ], 310 | "position": { 311 | "start": { 312 | "line": 7, 313 | "column": 1, 314 | "offset": 34 315 | }, 316 | "end": { 317 | "line": 7, 318 | "column": 4, 319 | "offset": 37 320 | } 321 | } 322 | } 323 | ], 324 | "position": { 325 | "start": { 326 | "line": 6, 327 | "column": 1, 328 | "offset": 29 329 | }, 330 | "end": { 331 | "line": 7, 332 | "column": 5, 333 | "offset": 38 334 | } 335 | } 336 | } 337 | ], 338 | "position": { 339 | "start": { 340 | "line": 6, 341 | "column": 1, 342 | "offset": 29 343 | }, 344 | "end": { 345 | "line": 7, 346 | "column": 5, 347 | "offset": 38 348 | } 349 | } 350 | }, 351 | { 352 | "type": "paragraph", 353 | "children": [ 354 | { 355 | "type": "emphasis", 356 | "children": [ 357 | { 358 | "type": "text", 359 | "value": "g\nh", 360 | "position": { 361 | "start": { 362 | "line": 9, 363 | "column": 2, 364 | "offset": 41 365 | }, 366 | "end": { 367 | "line": 10, 368 | "column": 2, 369 | "offset": 44 370 | } 371 | } 372 | } 373 | ], 374 | "position": { 375 | "start": { 376 | "line": 9, 377 | "column": 1, 378 | "offset": 40 379 | }, 380 | "end": { 381 | "line": 10, 382 | "column": 3, 383 | "offset": 45 384 | } 385 | } 386 | } 387 | ], 388 | "position": { 389 | "start": { 390 | "line": 9, 391 | "column": 1, 392 | "offset": 40 393 | }, 394 | "end": { 395 | "line": 10, 396 | "column": 3, 397 | "offset": 45 398 | } 399 | } 400 | }, 401 | { 402 | "type": "paragraph", 403 | "children": [ 404 | { 405 | "type": "strong", 406 | "children": [ 407 | { 408 | "type": "text", 409 | "value": "i\nj", 410 | "position": { 411 | "start": { 412 | "line": 12, 413 | "column": 3, 414 | "offset": 49 415 | }, 416 | "end": { 417 | "line": 13, 418 | "column": 2, 419 | "offset": 52 420 | } 421 | } 422 | } 423 | ], 424 | "position": { 425 | "start": { 426 | "line": 12, 427 | "column": 1, 428 | "offset": 47 429 | }, 430 | "end": { 431 | "line": 13, 432 | "column": 4, 433 | "offset": 54 434 | } 435 | } 436 | } 437 | ], 438 | "position": { 439 | "start": { 440 | "line": 12, 441 | "column": 1, 442 | "offset": 47 443 | }, 444 | "end": { 445 | "line": 13, 446 | "column": 4, 447 | "offset": 54 448 | } 449 | } 450 | }, 451 | { 452 | "type": "paragraph", 453 | "children": [ 454 | { 455 | "type": "text", 456 | "value": "**", 457 | "position": { 458 | "start": { 459 | "line": 15, 460 | "column": 1, 461 | "offset": 56 462 | }, 463 | "end": { 464 | "line": 15, 465 | "column": 3, 466 | "offset": 58 467 | } 468 | } 469 | }, 470 | { 471 | "type": "emphasis", 472 | "children": [ 473 | { 474 | "type": "text", 475 | "value": "k", 476 | "position": { 477 | "start": { 478 | "line": 15, 479 | "column": 4, 480 | "offset": 59 481 | }, 482 | "end": { 483 | "line": 15, 484 | "column": 5, 485 | "offset": 60 486 | } 487 | } 488 | } 489 | ], 490 | "position": { 491 | "start": { 492 | "line": 15, 493 | "column": 3, 494 | "offset": 58 495 | }, 496 | "end": { 497 | "line": 15, 498 | "column": 6, 499 | "offset": 61 500 | } 501 | } 502 | } 503 | ], 504 | "position": { 505 | "start": { 506 | "line": 15, 507 | "column": 1, 508 | "offset": 56 509 | }, 510 | "end": { 511 | "line": 15, 512 | "column": 6, 513 | "offset": 61 514 | } 515 | } 516 | }, 517 | { 518 | "type": "paragraph", 519 | "children": [ 520 | { 521 | "type": "text", 522 | "value": "***", 523 | "position": { 524 | "start": { 525 | "line": 17, 526 | "column": 1, 527 | "offset": 63 528 | }, 529 | "end": { 530 | "line": 17, 531 | "column": 4, 532 | "offset": 66 533 | } 534 | } 535 | }, 536 | { 537 | "type": "emphasis", 538 | "children": [ 539 | { 540 | "type": "text", 541 | "value": "l", 542 | "position": { 543 | "start": { 544 | "line": 17, 545 | "column": 5, 546 | "offset": 67 547 | }, 548 | "end": { 549 | "line": 17, 550 | "column": 6, 551 | "offset": 68 552 | } 553 | } 554 | } 555 | ], 556 | "position": { 557 | "start": { 558 | "line": 17, 559 | "column": 4, 560 | "offset": 66 561 | }, 562 | "end": { 563 | "line": 17, 564 | "column": 7, 565 | "offset": 69 566 | } 567 | } 568 | } 569 | ], 570 | "position": { 571 | "start": { 572 | "line": 17, 573 | "column": 1, 574 | "offset": 63 575 | }, 576 | "end": { 577 | "line": 17, 578 | "column": 7, 579 | "offset": 69 580 | } 581 | } 582 | }, 583 | { 584 | "type": "paragraph", 585 | "children": [ 586 | { 587 | "type": "text", 588 | "value": "*", 589 | "position": { 590 | "start": { 591 | "line": 19, 592 | "column": 1, 593 | "offset": 71 594 | }, 595 | "end": { 596 | "line": 19, 597 | "column": 2, 598 | "offset": 72 599 | } 600 | } 601 | }, 602 | { 603 | "type": "strong", 604 | "children": [ 605 | { 606 | "type": "text", 607 | "value": "m", 608 | "position": { 609 | "start": { 610 | "line": 19, 611 | "column": 4, 612 | "offset": 74 613 | }, 614 | "end": { 615 | "line": 19, 616 | "column": 5, 617 | "offset": 75 618 | } 619 | } 620 | } 621 | ], 622 | "position": { 623 | "start": { 624 | "line": 19, 625 | "column": 2, 626 | "offset": 72 627 | }, 628 | "end": { 629 | "line": 19, 630 | "column": 7, 631 | "offset": 77 632 | } 633 | } 634 | } 635 | ], 636 | "position": { 637 | "start": { 638 | "line": 19, 639 | "column": 1, 640 | "offset": 71 641 | }, 642 | "end": { 643 | "line": 19, 644 | "column": 7, 645 | "offset": 77 646 | } 647 | } 648 | }, 649 | { 650 | "type": "paragraph", 651 | "children": [ 652 | { 653 | "type": "text", 654 | "value": "**", 655 | "position": { 656 | "start": { 657 | "line": 21, 658 | "column": 1, 659 | "offset": 79 660 | }, 661 | "end": { 662 | "line": 21, 663 | "column": 3, 664 | "offset": 81 665 | } 666 | } 667 | }, 668 | { 669 | "type": "strong", 670 | "children": [ 671 | { 672 | "type": "text", 673 | "value": "m", 674 | "position": { 675 | "start": { 676 | "line": 21, 677 | "column": 5, 678 | "offset": 83 679 | }, 680 | "end": { 681 | "line": 21, 682 | "column": 6, 683 | "offset": 84 684 | } 685 | } 686 | } 687 | ], 688 | "position": { 689 | "start": { 690 | "line": 21, 691 | "column": 3, 692 | "offset": 81 693 | }, 694 | "end": { 695 | "line": 21, 696 | "column": 8, 697 | "offset": 86 698 | } 699 | } 700 | } 701 | ], 702 | "position": { 703 | "start": { 704 | "line": 21, 705 | "column": 1, 706 | "offset": 79 707 | }, 708 | "end": { 709 | "line": 21, 710 | "column": 8, 711 | "offset": 86 712 | } 713 | } 714 | } 715 | ], 716 | "position": { 717 | "start": { 718 | "line": 1, 719 | "column": 1, 720 | "offset": 0 721 | }, 722 | "end": { 723 | "line": 22, 724 | "column": 1, 725 | "offset": 87 726 | } 727 | } 728 | } 729 | -------------------------------------------------------------------------------- /test/fixtures/attention.md: -------------------------------------------------------------------------------- 1 | *a* 2 | **b** 3 | ***c*** 4 | ****d**** 5 | 6 | **e* 7 | *f** 8 | 9 | *g 10 | h* 11 | 12 | **i 13 | j** 14 | 15 | ***k* 16 | 17 | ****l* 18 | 19 | ***m** 20 | 21 | ****m** 22 | -------------------------------------------------------------------------------- /test/fixtures/autolink.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "An autolink ", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 13, 19 | "offset": 12 20 | } 21 | } 22 | }, 23 | { 24 | "type": "link", 25 | "title": null, 26 | "url": "http://example.com", 27 | "children": [ 28 | { 29 | "type": "text", 30 | "value": "http://example.com", 31 | "position": { 32 | "start": { 33 | "line": 1, 34 | "column": 14, 35 | "offset": 13 36 | }, 37 | "end": { 38 | "line": 1, 39 | "column": 32, 40 | "offset": 31 41 | } 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 13, 49 | "offset": 12 50 | }, 51 | "end": { 52 | "line": 1, 53 | "column": 33, 54 | "offset": 32 55 | } 56 | } 57 | }, 58 | { 59 | "type": "text", 60 | "value": ".", 61 | "position": { 62 | "start": { 63 | "line": 1, 64 | "column": 33, 65 | "offset": 32 66 | }, 67 | "end": { 68 | "line": 1, 69 | "column": 34, 70 | "offset": 33 71 | } 72 | } 73 | } 74 | ], 75 | "position": { 76 | "start": { 77 | "line": 1, 78 | "column": 1, 79 | "offset": 0 80 | }, 81 | "end": { 82 | "line": 1, 83 | "column": 34, 84 | "offset": 33 85 | } 86 | } 87 | }, 88 | { 89 | "type": "paragraph", 90 | "children": [ 91 | { 92 | "type": "text", 93 | "value": "Another autolink ", 94 | "position": { 95 | "start": { 96 | "line": 3, 97 | "column": 1, 98 | "offset": 35 99 | }, 100 | "end": { 101 | "line": 3, 102 | "column": 18, 103 | "offset": 52 104 | } 105 | } 106 | }, 107 | { 108 | "type": "link", 109 | "title": null, 110 | "url": "mailto:alpha@bravo.charlie", 111 | "children": [ 112 | { 113 | "type": "text", 114 | "value": "alpha@bravo.charlie", 115 | "position": { 116 | "start": { 117 | "line": 3, 118 | "column": 19, 119 | "offset": 53 120 | }, 121 | "end": { 122 | "line": 3, 123 | "column": 38, 124 | "offset": 72 125 | } 126 | } 127 | } 128 | ], 129 | "position": { 130 | "start": { 131 | "line": 3, 132 | "column": 18, 133 | "offset": 52 134 | }, 135 | "end": { 136 | "line": 3, 137 | "column": 39, 138 | "offset": 73 139 | } 140 | } 141 | }, 142 | { 143 | "type": "text", 144 | "value": ".", 145 | "position": { 146 | "start": { 147 | "line": 3, 148 | "column": 39, 149 | "offset": 73 150 | }, 151 | "end": { 152 | "line": 3, 153 | "column": 40, 154 | "offset": 74 155 | } 156 | } 157 | } 158 | ], 159 | "position": { 160 | "start": { 161 | "line": 3, 162 | "column": 1, 163 | "offset": 35 164 | }, 165 | "end": { 166 | "line": 3, 167 | "column": 40, 168 | "offset": 74 169 | } 170 | } 171 | }, 172 | { 173 | "type": "paragraph", 174 | "children": [ 175 | { 176 | "type": "text", 177 | "value": "Not an autolink .", 178 | "position": { 179 | "start": { 180 | "line": 5, 181 | "column": 1, 182 | "offset": 76 183 | }, 184 | "end": { 185 | "line": 5, 186 | "column": 39, 187 | "offset": 114 188 | } 189 | } 190 | } 191 | ], 192 | "position": { 193 | "start": { 194 | "line": 5, 195 | "column": 1, 196 | "offset": 76 197 | }, 198 | "end": { 199 | "line": 5, 200 | "column": 39, 201 | "offset": 114 202 | } 203 | } 204 | } 205 | ], 206 | "position": { 207 | "start": { 208 | "line": 1, 209 | "column": 1, 210 | "offset": 0 211 | }, 212 | "end": { 213 | "line": 6, 214 | "column": 1, 215 | "offset": 115 216 | } 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /test/fixtures/autolink.md: -------------------------------------------------------------------------------- 1 | An autolink . 2 | 3 | Another autolink . 4 | 5 | Not an autolink . 6 | -------------------------------------------------------------------------------- /test/fixtures/blockquote.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "blockquote", 6 | "children": [ 7 | { 8 | "type": "paragraph", 9 | "children": [ 10 | { 11 | "type": "text", 12 | "value": "a block quote", 13 | "position": { 14 | "start": { 15 | "line": 1, 16 | "column": 3, 17 | "offset": 2 18 | }, 19 | "end": { 20 | "line": 1, 21 | "column": 16, 22 | "offset": 15 23 | } 24 | } 25 | } 26 | ], 27 | "position": { 28 | "start": { 29 | "line": 1, 30 | "column": 3, 31 | "offset": 2 32 | }, 33 | "end": { 34 | "line": 1, 35 | "column": 16, 36 | "offset": 15 37 | } 38 | } 39 | } 40 | ], 41 | "position": { 42 | "start": { 43 | "line": 1, 44 | "column": 1, 45 | "offset": 0 46 | }, 47 | "end": { 48 | "line": 1, 49 | "column": 16, 50 | "offset": 15 51 | } 52 | } 53 | }, 54 | { 55 | "type": "blockquote", 56 | "children": [ 57 | { 58 | "type": "paragraph", 59 | "children": [ 60 | { 61 | "type": "text", 62 | "value": "Another block quote\nwith two lazy\nlines.", 63 | "position": { 64 | "start": { 65 | "line": 3, 66 | "column": 3, 67 | "offset": 19 68 | }, 69 | "end": { 70 | "line": 5, 71 | "column": 7, 72 | "offset": 59 73 | } 74 | } 75 | } 76 | ], 77 | "position": { 78 | "start": { 79 | "line": 3, 80 | "column": 3, 81 | "offset": 19 82 | }, 83 | "end": { 84 | "line": 5, 85 | "column": 7, 86 | "offset": 59 87 | } 88 | } 89 | } 90 | ], 91 | "position": { 92 | "start": { 93 | "line": 3, 94 | "column": 1, 95 | "offset": 17 96 | }, 97 | "end": { 98 | "line": 5, 99 | "column": 7, 100 | "offset": 59 101 | } 102 | } 103 | }, 104 | { 105 | "type": "blockquote", 106 | "children": [ 107 | { 108 | "type": "paragraph", 109 | "children": [ 110 | { 111 | "type": "text", 112 | "value": "Block quote", 113 | "position": { 114 | "start": { 115 | "line": 7, 116 | "column": 3, 117 | "offset": 63 118 | }, 119 | "end": { 120 | "line": 7, 121 | "column": 14, 122 | "offset": 74 123 | } 124 | } 125 | } 126 | ], 127 | "position": { 128 | "start": { 129 | "line": 7, 130 | "column": 3, 131 | "offset": 63 132 | }, 133 | "end": { 134 | "line": 7, 135 | "column": 14, 136 | "offset": 74 137 | } 138 | } 139 | }, 140 | { 141 | "type": "heading", 142 | "depth": 1, 143 | "children": [ 144 | { 145 | "type": "text", 146 | "value": "with a heading", 147 | "position": { 148 | "start": { 149 | "line": 8, 150 | "column": 5, 151 | "offset": 79 152 | }, 153 | "end": { 154 | "line": 8, 155 | "column": 19, 156 | "offset": 93 157 | } 158 | } 159 | } 160 | ], 161 | "position": { 162 | "start": { 163 | "line": 8, 164 | "column": 3, 165 | "offset": 77 166 | }, 167 | "end": { 168 | "line": 8, 169 | "column": 19, 170 | "offset": 93 171 | } 172 | } 173 | } 174 | ], 175 | "position": { 176 | "start": { 177 | "line": 7, 178 | "column": 1, 179 | "offset": 61 180 | }, 181 | "end": { 182 | "line": 8, 183 | "column": 19, 184 | "offset": 93 185 | } 186 | } 187 | }, 188 | { 189 | "type": "blockquote", 190 | "children": [ 191 | { 192 | "type": "paragraph", 193 | "children": [ 194 | { 195 | "type": "text", 196 | "value": "Block quote", 197 | "position": { 198 | "start": { 199 | "line": 10, 200 | "column": 3, 201 | "offset": 97 202 | }, 203 | "end": { 204 | "line": 10, 205 | "column": 14, 206 | "offset": 108 207 | } 208 | } 209 | } 210 | ], 211 | "position": { 212 | "start": { 213 | "line": 10, 214 | "column": 3, 215 | "offset": 97 216 | }, 217 | "end": { 218 | "line": 10, 219 | "column": 14, 220 | "offset": 108 221 | } 222 | } 223 | }, 224 | { 225 | "type": "code", 226 | "lang": null, 227 | "meta": null, 228 | "value": "with unclosed fenced code.", 229 | "position": { 230 | "start": { 231 | "line": 11, 232 | "column": 3, 233 | "offset": 111 234 | }, 235 | "end": { 236 | "line": 12, 237 | "column": 29, 238 | "offset": 143 239 | } 240 | } 241 | } 242 | ], 243 | "position": { 244 | "start": { 245 | "line": 10, 246 | "column": 1, 247 | "offset": 95 248 | }, 249 | "end": { 250 | "line": 12, 251 | "column": 29, 252 | "offset": 143 253 | } 254 | } 255 | }, 256 | { 257 | "type": "blockquote", 258 | "children": [ 259 | { 260 | "type": "paragraph", 261 | "children": [ 262 | { 263 | "type": "text", 264 | "value": "Block\nquote\nwith and without\nspace.", 265 | "position": { 266 | "start": { 267 | "line": 14, 268 | "column": 2, 269 | "offset": 146 270 | }, 271 | "end": { 272 | "line": 17, 273 | "column": 7, 274 | "offset": 184 275 | } 276 | } 277 | } 278 | ], 279 | "position": { 280 | "start": { 281 | "line": 14, 282 | "column": 2, 283 | "offset": 146 284 | }, 285 | "end": { 286 | "line": 17, 287 | "column": 7, 288 | "offset": 184 289 | } 290 | } 291 | } 292 | ], 293 | "position": { 294 | "start": { 295 | "line": 14, 296 | "column": 1, 297 | "offset": 145 298 | }, 299 | "end": { 300 | "line": 17, 301 | "column": 7, 302 | "offset": 184 303 | } 304 | } 305 | } 306 | ], 307 | "position": { 308 | "start": { 309 | "line": 1, 310 | "column": 1, 311 | "offset": 0 312 | }, 313 | "end": { 314 | "line": 18, 315 | "column": 1, 316 | "offset": 185 317 | } 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /test/fixtures/blockquote.md: -------------------------------------------------------------------------------- 1 | > a block quote 2 | 3 | > Another block quote 4 | with two lazy 5 | lines. 6 | 7 | > Block quote 8 | > # with a heading 9 | 10 | > Block quote 11 | > ``` 12 | > with unclosed fenced code. 13 | 14 | >Block 15 | > quote 16 | >with and without 17 | space. 18 | -------------------------------------------------------------------------------- /test/fixtures/character-escape.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Character escapes, such as: *not emphasis*.", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 45, 19 | "offset": 44 20 | } 21 | } 22 | } 23 | ], 24 | "position": { 25 | "start": { 26 | "line": 1, 27 | "column": 1, 28 | "offset": 0 29 | }, 30 | "end": { 31 | "line": 1, 32 | "column": 45, 33 | "offset": 44 34 | } 35 | } 36 | }, 37 | { 38 | "type": "paragraph", 39 | "children": [ 40 | { 41 | "type": "text", 42 | "value": "- not a list.", 43 | "position": { 44 | "start": { 45 | "line": 3, 46 | "column": 1, 47 | "offset": 46 48 | }, 49 | "end": { 50 | "line": 3, 51 | "column": 15, 52 | "offset": 60 53 | } 54 | } 55 | } 56 | ], 57 | "position": { 58 | "start": { 59 | "line": 3, 60 | "column": 1, 61 | "offset": 46 62 | }, 63 | "end": { 64 | "line": 3, 65 | "column": 15, 66 | "offset": 60 67 | } 68 | } 69 | }, 70 | { 71 | "type": "paragraph", 72 | "children": [ 73 | { 74 | "type": "text", 75 | "value": "Escaping non-punctuation doesn’t work: \\1", 76 | "position": { 77 | "start": { 78 | "line": 5, 79 | "column": 1, 80 | "offset": 62 81 | }, 82 | "end": { 83 | "line": 5, 84 | "column": 42, 85 | "offset": 103 86 | } 87 | } 88 | } 89 | ], 90 | "position": { 91 | "start": { 92 | "line": 5, 93 | "column": 1, 94 | "offset": 62 95 | }, 96 | "end": { 97 | "line": 5, 98 | "column": 42, 99 | "offset": 103 100 | } 101 | } 102 | } 103 | ], 104 | "position": { 105 | "start": { 106 | "line": 1, 107 | "column": 1, 108 | "offset": 0 109 | }, 110 | "end": { 111 | "line": 6, 112 | "column": 1, 113 | "offset": 104 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /test/fixtures/character-escape.md: -------------------------------------------------------------------------------- 1 | Character escapes, such as: \*not emphasis*. 2 | 3 | \- not a list. 4 | 5 | Escaping non-punctuation doesn’t work: \1 6 | -------------------------------------------------------------------------------- /test/fixtures/character-reference.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Character references, such as named: &,\ndecimal: #, Ӓ, Ϡ, �,\nand hexadecimal: \", ആ, ಫ.", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 3, 18 | "column": 43, 19 | "offset": 125 20 | } 21 | } 22 | } 23 | ], 24 | "position": { 25 | "start": { 26 | "line": 1, 27 | "column": 1, 28 | "offset": 0 29 | }, 30 | "end": { 31 | "line": 3, 32 | "column": 43, 33 | "offset": 125 34 | } 35 | } 36 | } 37 | ], 38 | "position": { 39 | "start": { 40 | "line": 1, 41 | "column": 1, 42 | "offset": 0 43 | }, 44 | "end": { 45 | "line": 4, 46 | "column": 1, 47 | "offset": 126 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/fixtures/character-reference.md: -------------------------------------------------------------------------------- 1 | Character references, such as named: &, 2 | decimal: #, Ӓ, Ϡ, �, 3 | and hexadecimal: ", ആ, ಫ. 4 | -------------------------------------------------------------------------------- /test/fixtures/character-references-everywhere.md: -------------------------------------------------------------------------------- 1 | > However, &MadeUpEntities; are kept in the document. 2 | 3 | > Entities even work in the language flag of fenced code blocks: 4 | 5 | > ```some©language 6 | > alert('Hello'); 7 | > ``` 8 | 9 | > And in an auto-link: 10 | 11 | > Foo and bar and http://example©xample.com and baz. 12 | 13 | > Or in [l©nks]( 14 | > ~/some©file "in some pl©ce") 15 | 16 | > Or in [l©lnks]( 17 | > <~/some©file> 18 | > "in some pl©ce") 19 | 20 | > Or in ![ 21 | > l©nks 22 | > ]( 23 | > ~/some©file "in some pl©ce") 24 | 25 | *** 26 | 27 | > Or in ![l©lnks]( 28 | > <~/some©file> 29 | > "in some pl©ce") 30 | 31 | > Or in ![ 32 | > l©nks 33 | > ][12] 34 | 35 | > [1]: http://example©xample.com "in some 36 | > pl©ce" 37 | 38 | > [ 39 | > 1 40 | > ]: http://example©xample.com "in some 41 | > pl©ce" 42 | 43 | *** 44 | 45 | > But, entities are not interpreted in `inline cöde`, or in 46 | > code blocks: 47 | 48 | > CÖDE block. 49 | -------------------------------------------------------------------------------- /test/fixtures/code-fenced.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "code", 6 | "lang": null, 7 | "meta": null, 8 | "value": "fenced code", 9 | "position": { 10 | "start": { 11 | "line": 1, 12 | "column": 1, 13 | "offset": 0 14 | }, 15 | "end": { 16 | "line": 3, 17 | "column": 4, 18 | "offset": 19 19 | } 20 | } 21 | }, 22 | { 23 | "type": "code", 24 | "lang": "js", 25 | "meta": null, 26 | "value": "fenced code with a language", 27 | "position": { 28 | "start": { 29 | "line": 5, 30 | "column": 1, 31 | "offset": 21 32 | }, 33 | "end": { 34 | "line": 7, 35 | "column": 4, 36 | "offset": 58 37 | } 38 | } 39 | }, 40 | { 41 | "type": "code", 42 | "lang": "js", 43 | "meta": "line=1", 44 | "value": "fenced code with meta", 45 | "position": { 46 | "start": { 47 | "line": 9, 48 | "column": 1, 49 | "offset": 60 50 | }, 51 | "end": { 52 | "line": 11, 53 | "column": 4, 54 | "offset": 98 55 | } 56 | } 57 | }, 58 | { 59 | "type": "code", 60 | "lang": null, 61 | "meta": null, 62 | "value": "fenced code with tildes", 63 | "position": { 64 | "start": { 65 | "line": 13, 66 | "column": 1, 67 | "offset": 100 68 | }, 69 | "end": { 70 | "line": 15, 71 | "column": 4, 72 | "offset": 131 73 | } 74 | } 75 | }, 76 | { 77 | "type": "paragraph", 78 | "children": [ 79 | { 80 | "type": "inlineCode", 81 | "value": "not fenced code", 82 | "position": { 83 | "start": { 84 | "line": 17, 85 | "column": 1, 86 | "offset": 133 87 | }, 88 | "end": { 89 | "line": 17, 90 | "column": 22, 91 | "offset": 154 92 | } 93 | } 94 | } 95 | ], 96 | "position": { 97 | "start": { 98 | "line": 17, 99 | "column": 1, 100 | "offset": 133 101 | }, 102 | "end": { 103 | "line": 17, 104 | "column": 22, 105 | "offset": 154 106 | } 107 | } 108 | }, 109 | { 110 | "type": "code", 111 | "lang": "fenced", 112 | "meta": "code~~~", 113 | "value": "asd", 114 | "position": { 115 | "start": { 116 | "line": 19, 117 | "column": 1, 118 | "offset": 156 119 | }, 120 | "end": { 121 | "line": 21, 122 | "column": 4, 123 | "offset": 181 124 | } 125 | } 126 | }, 127 | { 128 | "type": "code", 129 | "lang": null, 130 | "meta": null, 131 | "value": "\nasd", 132 | "position": { 133 | "start": { 134 | "line": 23, 135 | "column": 1, 136 | "offset": 183 137 | }, 138 | "end": { 139 | "line": 26, 140 | "column": 4, 141 | "offset": 195 142 | } 143 | } 144 | }, 145 | { 146 | "type": "code", 147 | "lang": null, 148 | "meta": null, 149 | "value": "asd\n", 150 | "position": { 151 | "start": { 152 | "line": 28, 153 | "column": 1, 154 | "offset": 197 155 | }, 156 | "end": { 157 | "line": 31, 158 | "column": 4, 159 | "offset": 209 160 | } 161 | } 162 | } 163 | ], 164 | "position": { 165 | "start": { 166 | "line": 1, 167 | "column": 1, 168 | "offset": 0 169 | }, 170 | "end": { 171 | "line": 32, 172 | "column": 1, 173 | "offset": 210 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /test/fixtures/code-fenced.md: -------------------------------------------------------------------------------- 1 | ``` 2 | fenced code 3 | ``` 4 | 5 | ```js 6 | fenced code with a language 7 | ``` 8 | 9 | ```js line=1 10 | fenced code with meta 11 | ``` 12 | 13 | ~~~ 14 | fenced code with tildes 15 | ~~~ 16 | 17 | ```not fenced code``` 18 | 19 | ~~~fenced code~~~ 20 | asd 21 | ~~~ 22 | 23 | ``` 24 | 25 | asd 26 | ``` 27 | 28 | ``` 29 | asd 30 | 31 | ``` 32 | -------------------------------------------------------------------------------- /test/fixtures/code-indented.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "code", 6 | "lang": null, 7 | "meta": null, 8 | "value": "indented code\n\n\nmore indented code", 9 | "position": { 10 | "start": { 11 | "line": 1, 12 | "column": 1, 13 | "offset": 0 14 | }, 15 | "end": { 16 | "line": 4, 17 | "column": 23, 18 | "offset": 42 19 | } 20 | } 21 | }, 22 | { 23 | "type": "paragraph", 24 | "children": [ 25 | { 26 | "type": "text", 27 | "value": "Not indented code", 28 | "position": { 29 | "start": { 30 | "line": 5, 31 | "column": 1, 32 | "offset": 43 33 | }, 34 | "end": { 35 | "line": 5, 36 | "column": 18, 37 | "offset": 60 38 | } 39 | } 40 | } 41 | ], 42 | "position": { 43 | "start": { 44 | "line": 5, 45 | "column": 1, 46 | "offset": 43 47 | }, 48 | "end": { 49 | "line": 5, 50 | "column": 18, 51 | "offset": 60 52 | } 53 | } 54 | }, 55 | { 56 | "type": "code", 57 | "lang": null, 58 | "meta": null, 59 | "value": " more\n indent", 60 | "position": { 61 | "start": { 62 | "line": 7, 63 | "column": 1, 64 | "offset": 62 65 | }, 66 | "end": { 67 | "line": 8, 68 | "column": 14, 69 | "offset": 86 70 | } 71 | } 72 | }, 73 | { 74 | "type": "paragraph", 75 | "children": [ 76 | { 77 | "type": "text", 78 | "value": "Not code.", 79 | "position": { 80 | "start": { 81 | "line": 10, 82 | "column": 1, 83 | "offset": 88 84 | }, 85 | "end": { 86 | "line": 10, 87 | "column": 10, 88 | "offset": 97 89 | } 90 | } 91 | } 92 | ], 93 | "position": { 94 | "start": { 95 | "line": 10, 96 | "column": 1, 97 | "offset": 88 98 | }, 99 | "end": { 100 | "line": 10, 101 | "column": 10, 102 | "offset": 97 103 | } 104 | } 105 | }, 106 | { 107 | "type": "code", 108 | "lang": null, 109 | "meta": null, 110 | "value": "tabs\nand mixed with spaces\n extra spaces", 111 | "position": { 112 | "start": { 113 | "line": 12, 114 | "column": 1, 115 | "offset": 99 116 | }, 117 | "end": { 118 | "line": 14, 119 | "column": 16, 120 | "offset": 145 121 | } 122 | } 123 | }, 124 | { 125 | "type": "paragraph", 126 | "children": [ 127 | { 128 | "type": "text", 129 | "value": "Not code.", 130 | "position": { 131 | "start": { 132 | "line": 16, 133 | "column": 1, 134 | "offset": 147 135 | }, 136 | "end": { 137 | "line": 16, 138 | "column": 10, 139 | "offset": 156 140 | } 141 | } 142 | } 143 | ], 144 | "position": { 145 | "start": { 146 | "line": 16, 147 | "column": 1, 148 | "offset": 147 149 | }, 150 | "end": { 151 | "line": 16, 152 | "column": 10, 153 | "offset": 156 154 | } 155 | } 156 | }, 157 | { 158 | "type": "code", 159 | "lang": null, 160 | "meta": null, 161 | "value": "a tab", 162 | "position": { 163 | "start": { 164 | "line": 18, 165 | "column": 1, 166 | "offset": 158 167 | }, 168 | "end": { 169 | "line": 18, 170 | "column": 7, 171 | "offset": 164 172 | } 173 | } 174 | } 175 | ], 176 | "position": { 177 | "start": { 178 | "line": 1, 179 | "column": 1, 180 | "offset": 0 181 | }, 182 | "end": { 183 | "line": 19, 184 | "column": 1, 185 | "offset": 165 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /test/fixtures/code-indented.md: -------------------------------------------------------------------------------- 1 | indented code 2 | 3 | 4 | more indented code 5 | Not indented code 6 | 7 | more 8 | indent 9 | 10 | Not code. 11 | 12 | tabs 13 | and mixed with spaces 14 | extra spaces 15 | 16 | Not code. 17 | 18 | a tab 19 | -------------------------------------------------------------------------------- /test/fixtures/code-text.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "A couple of code examples: ", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 28, 19 | "offset": 27 20 | } 21 | } 22 | }, 23 | { 24 | "type": "inlineCode", 25 | "value": "a", 26 | "position": { 27 | "start": { 28 | "line": 1, 29 | "column": 28, 30 | "offset": 27 31 | }, 32 | "end": { 33 | "line": 1, 34 | "column": 31, 35 | "offset": 30 36 | } 37 | } 38 | }, 39 | { 40 | "type": "text", 41 | "value": ", ", 42 | "position": { 43 | "start": { 44 | "line": 1, 45 | "column": 31, 46 | "offset": 30 47 | }, 48 | "end": { 49 | "line": 1, 50 | "column": 33, 51 | "offset": 32 52 | } 53 | } 54 | }, 55 | { 56 | "type": "inlineCode", 57 | "value": " b", 58 | "position": { 59 | "start": { 60 | "line": 1, 61 | "column": 33, 62 | "offset": 32 63 | }, 64 | "end": { 65 | "line": 1, 66 | "column": 37, 67 | "offset": 36 68 | } 69 | } 70 | }, 71 | { 72 | "type": "text", 73 | "value": ", ", 74 | "position": { 75 | "start": { 76 | "line": 1, 77 | "column": 37, 78 | "offset": 36 79 | }, 80 | "end": { 81 | "line": 1, 82 | "column": 39, 83 | "offset": 38 84 | } 85 | } 86 | }, 87 | { 88 | "type": "inlineCode", 89 | "value": "c ", 90 | "position": { 91 | "start": { 92 | "line": 1, 93 | "column": 39, 94 | "offset": 38 95 | }, 96 | "end": { 97 | "line": 1, 98 | "column": 43, 99 | "offset": 42 100 | } 101 | } 102 | }, 103 | { 104 | "type": "text", 105 | "value": ", ", 106 | "position": { 107 | "start": { 108 | "line": 1, 109 | "column": 43, 110 | "offset": 42 111 | }, 112 | "end": { 113 | "line": 1, 114 | "column": 45, 115 | "offset": 44 116 | } 117 | } 118 | }, 119 | { 120 | "type": "inlineCode", 121 | "value": "d", 122 | "position": { 123 | "start": { 124 | "line": 1, 125 | "column": 45, 126 | "offset": 44 127 | }, 128 | "end": { 129 | "line": 1, 130 | "column": 50, 131 | "offset": 49 132 | } 133 | } 134 | }, 135 | { 136 | "type": "text", 137 | "value": ", ", 138 | "position": { 139 | "start": { 140 | "line": 1, 141 | "column": 50, 142 | "offset": 49 143 | }, 144 | "end": { 145 | "line": 1, 146 | "column": 52, 147 | "offset": 51 148 | } 149 | } 150 | }, 151 | { 152 | "type": "inlineCode", 153 | "value": "e", 154 | "position": { 155 | "start": { 156 | "line": 1, 157 | "column": 52, 158 | "offset": 51 159 | }, 160 | "end": { 161 | "line": 2, 162 | "column": 2, 163 | "offset": 56 164 | } 165 | } 166 | }, 167 | { 168 | "type": "text", 169 | "value": ", ", 170 | "position": { 171 | "start": { 172 | "line": 2, 173 | "column": 2, 174 | "offset": 56 175 | }, 176 | "end": { 177 | "line": 2, 178 | "column": 4, 179 | "offset": 58 180 | } 181 | } 182 | }, 183 | { 184 | "type": "inlineCode", 185 | "value": "f", 186 | "position": { 187 | "start": { 188 | "line": 2, 189 | "column": 4, 190 | "offset": 58 191 | }, 192 | "end": { 193 | "line": 3, 194 | "column": 2, 195 | "offset": 63 196 | } 197 | } 198 | }, 199 | { 200 | "type": "text", 201 | "value": ", ", 202 | "position": { 203 | "start": { 204 | "line": 3, 205 | "column": 2, 206 | "offset": 63 207 | }, 208 | "end": { 209 | "line": 3, 210 | "column": 4, 211 | "offset": 65 212 | } 213 | } 214 | }, 215 | { 216 | "type": "inlineCode", 217 | "value": "g\n", 218 | "position": { 219 | "start": { 220 | "line": 3, 221 | "column": 4, 222 | "offset": 65 223 | }, 224 | "end": { 225 | "line": 4, 226 | "column": 2, 227 | "offset": 69 228 | } 229 | } 230 | }, 231 | { 232 | "type": "text", 233 | "value": ", ", 234 | "position": { 235 | "start": { 236 | "line": 4, 237 | "column": 2, 238 | "offset": 69 239 | }, 240 | "end": { 241 | "line": 4, 242 | "column": 4, 243 | "offset": 71 244 | } 245 | } 246 | }, 247 | { 248 | "type": "inlineCode", 249 | "value": "\nh", 250 | "position": { 251 | "start": { 252 | "line": 4, 253 | "column": 4, 254 | "offset": 71 255 | }, 256 | "end": { 257 | "line": 5, 258 | "column": 3, 259 | "offset": 75 260 | } 261 | } 262 | }, 263 | { 264 | "type": "text", 265 | "value": ".", 266 | "position": { 267 | "start": { 268 | "line": 5, 269 | "column": 3, 270 | "offset": 75 271 | }, 272 | "end": { 273 | "line": 5, 274 | "column": 4, 275 | "offset": 76 276 | } 277 | } 278 | } 279 | ], 280 | "position": { 281 | "start": { 282 | "line": 1, 283 | "column": 1, 284 | "offset": 0 285 | }, 286 | "end": { 287 | "line": 5, 288 | "column": 4, 289 | "offset": 76 290 | } 291 | } 292 | }, 293 | { 294 | "type": "paragraph", 295 | "children": [ 296 | { 297 | "type": "text", 298 | "value": "And: ", 299 | "position": { 300 | "start": { 301 | "line": 7, 302 | "column": 1, 303 | "offset": 78 304 | }, 305 | "end": { 306 | "line": 7, 307 | "column": 6, 308 | "offset": 83 309 | } 310 | } 311 | }, 312 | { 313 | "type": "inlineCode", 314 | "value": "alpha bravo charlie\n\tdelta echo", 315 | "position": { 316 | "start": { 317 | "line": 7, 318 | "column": 6, 319 | "offset": 83 320 | }, 321 | "end": { 322 | "line": 8, 323 | "column": 13, 324 | "offset": 116 325 | } 326 | } 327 | }, 328 | { 329 | "type": "text", 330 | "value": ".", 331 | "position": { 332 | "start": { 333 | "line": 8, 334 | "column": 13, 335 | "offset": 116 336 | }, 337 | "end": { 338 | "line": 8, 339 | "column": 14, 340 | "offset": 117 341 | } 342 | } 343 | } 344 | ], 345 | "position": { 346 | "start": { 347 | "line": 7, 348 | "column": 1, 349 | "offset": 78 350 | }, 351 | "end": { 352 | "line": 8, 353 | "column": 14, 354 | "offset": 117 355 | } 356 | } 357 | } 358 | ], 359 | "position": { 360 | "start": { 361 | "line": 1, 362 | "column": 1, 363 | "offset": 0 364 | }, 365 | "end": { 366 | "line": 9, 367 | "column": 1, 368 | "offset": 118 369 | } 370 | } 371 | } 372 | -------------------------------------------------------------------------------- /test/fixtures/code-text.md: -------------------------------------------------------------------------------- 1 | A couple of code examples: `a`, ` b`, `c `, ` d `, ` e 2 | `, ` f 3 | `, `g 4 | `, ` 5 | h`. 6 | 7 | And: `alpha bravo charlie 8 | delta echo`. 9 | -------------------------------------------------------------------------------- /test/fixtures/definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "definition", 6 | "identifier": "a", 7 | "label": "a", 8 | "title": null, 9 | "url": "", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 8, 19 | "offset": 7 20 | } 21 | } 22 | }, 23 | { 24 | "type": "definition", 25 | "identifier": "a", 26 | "label": "a", 27 | "title": null, 28 | "url": "b", 29 | "position": { 30 | "start": { 31 | "line": 2, 32 | "column": 1, 33 | "offset": 8 34 | }, 35 | "end": { 36 | "line": 2, 37 | "column": 7, 38 | "offset": 14 39 | } 40 | } 41 | }, 42 | { 43 | "type": "definition", 44 | "identifier": "a", 45 | "label": "a", 46 | "title": "c", 47 | "url": "b", 48 | "position": { 49 | "start": { 50 | "line": 3, 51 | "column": 1, 52 | "offset": 15 53 | }, 54 | "end": { 55 | "line": 3, 56 | "column": 11, 57 | "offset": 25 58 | } 59 | } 60 | }, 61 | { 62 | "type": "definition", 63 | "identifier": "a", 64 | "label": "a", 65 | "title": "c", 66 | "url": "b", 67 | "position": { 68 | "start": { 69 | "line": 4, 70 | "column": 1, 71 | "offset": 26 72 | }, 73 | "end": { 74 | "line": 4, 75 | "column": 11, 76 | "offset": 36 77 | } 78 | } 79 | }, 80 | { 81 | "type": "definition", 82 | "identifier": "a", 83 | "label": "a", 84 | "title": "c", 85 | "url": "b", 86 | "position": { 87 | "start": { 88 | "line": 5, 89 | "column": 1, 90 | "offset": 37 91 | }, 92 | "end": { 93 | "line": 5, 94 | "column": 11, 95 | "offset": 47 96 | } 97 | } 98 | }, 99 | { 100 | "type": "definition", 101 | "identifier": "a", 102 | "label": "a", 103 | "title": null, 104 | "url": "b", 105 | "position": { 106 | "start": { 107 | "line": 6, 108 | "column": 1, 109 | "offset": 48 110 | }, 111 | "end": { 112 | "line": 6, 113 | "column": 9, 114 | "offset": 56 115 | } 116 | } 117 | }, 118 | { 119 | "type": "definition", 120 | "identifier": "a", 121 | "label": "a", 122 | "title": "\nc d\ne", 123 | "url": "b", 124 | "position": { 125 | "start": { 126 | "line": 7, 127 | "column": 1, 128 | "offset": 57 129 | }, 130 | "end": { 131 | "line": 9, 132 | "column": 4, 133 | "offset": 75 134 | } 135 | } 136 | } 137 | ], 138 | "position": { 139 | "start": { 140 | "line": 1, 141 | "column": 1, 142 | "offset": 0 143 | }, 144 | "end": { 145 | "line": 10, 146 | "column": 1, 147 | "offset": 76 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /test/fixtures/definition.md: -------------------------------------------------------------------------------- 1 | [a]: <> 2 | [a]: b 3 | [a]: b "c" 4 | [a]: b 'c' 5 | [a]: b (c) 6 | [a]: 7 | [a]: ' 8 | c d 9 | e' 10 | -------------------------------------------------------------------------------- /test/fixtures/empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [], 4 | "position": { 5 | "start": { 6 | "line": 1, 7 | "column": 1, 8 | "offset": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 1, 13 | "offset": 0 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/empty.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syntax-tree/mdast-util-from-markdown/553a0e324554b29cade83f4911c97482d86ee8ff/test/fixtures/empty.md -------------------------------------------------------------------------------- /test/fixtures/hard-break-escape.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "a", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 2, 19 | "offset": 1 20 | } 21 | } 22 | }, 23 | { 24 | "type": "break", 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 2, 29 | "offset": 1 30 | }, 31 | "end": { 32 | "line": 2, 33 | "column": 1, 34 | "offset": 3 35 | } 36 | } 37 | }, 38 | { 39 | "type": "text", 40 | "value": "b", 41 | "position": { 42 | "start": { 43 | "line": 2, 44 | "column": 1, 45 | "offset": 3 46 | }, 47 | "end": { 48 | "line": 2, 49 | "column": 2, 50 | "offset": 4 51 | } 52 | } 53 | } 54 | ], 55 | "position": { 56 | "start": { 57 | "line": 1, 58 | "column": 1, 59 | "offset": 0 60 | }, 61 | "end": { 62 | "line": 2, 63 | "column": 2, 64 | "offset": 4 65 | } 66 | } 67 | }, 68 | { 69 | "type": "paragraph", 70 | "children": [ 71 | { 72 | "type": "text", 73 | "value": "c", 74 | "position": { 75 | "start": { 76 | "line": 4, 77 | "column": 1, 78 | "offset": 6 79 | }, 80 | "end": { 81 | "line": 4, 82 | "column": 2, 83 | "offset": 7 84 | } 85 | } 86 | }, 87 | { 88 | "type": "break", 89 | "position": { 90 | "start": { 91 | "line": 4, 92 | "column": 2, 93 | "offset": 7 94 | }, 95 | "end": { 96 | "line": 5, 97 | "column": 1, 98 | "offset": 9 99 | } 100 | } 101 | }, 102 | { 103 | "type": "text", 104 | "value": "d", 105 | "position": { 106 | "start": { 107 | "line": 5, 108 | "column": 3, 109 | "offset": 11 110 | }, 111 | "end": { 112 | "line": 5, 113 | "column": 4, 114 | "offset": 12 115 | } 116 | } 117 | } 118 | ], 119 | "position": { 120 | "start": { 121 | "line": 4, 122 | "column": 1, 123 | "offset": 6 124 | }, 125 | "end": { 126 | "line": 5, 127 | "column": 4, 128 | "offset": 12 129 | } 130 | } 131 | }, 132 | { 133 | "type": "paragraph", 134 | "children": [ 135 | { 136 | "type": "text", 137 | "value": "e ", 138 | "position": { 139 | "start": { 140 | "line": 7, 141 | "column": 1, 142 | "offset": 14 143 | }, 144 | "end": { 145 | "line": 7, 146 | "column": 4, 147 | "offset": 17 148 | } 149 | } 150 | }, 151 | { 152 | "type": "break", 153 | "position": { 154 | "start": { 155 | "line": 7, 156 | "column": 4, 157 | "offset": 17 158 | }, 159 | "end": { 160 | "line": 8, 161 | "column": 1, 162 | "offset": 19 163 | } 164 | } 165 | }, 166 | { 167 | "type": "text", 168 | "value": "f", 169 | "position": { 170 | "start": { 171 | "line": 8, 172 | "column": 1, 173 | "offset": 19 174 | }, 175 | "end": { 176 | "line": 8, 177 | "column": 2, 178 | "offset": 20 179 | } 180 | } 181 | } 182 | ], 183 | "position": { 184 | "start": { 185 | "line": 7, 186 | "column": 1, 187 | "offset": 14 188 | }, 189 | "end": { 190 | "line": 8, 191 | "column": 2, 192 | "offset": 20 193 | } 194 | } 195 | } 196 | ], 197 | "position": { 198 | "start": { 199 | "line": 1, 200 | "column": 1, 201 | "offset": 0 202 | }, 203 | "end": { 204 | "line": 9, 205 | "column": 1, 206 | "offset": 21 207 | } 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /test/fixtures/hard-break-escape.md: -------------------------------------------------------------------------------- 1 | a\ 2 | b 3 | 4 | c\ 5 | d 6 | 7 | e \ 8 | f 9 | -------------------------------------------------------------------------------- /test/fixtures/hard-break-prefix.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "a", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 2, 19 | "offset": 1 20 | } 21 | } 22 | }, 23 | { 24 | "type": "break", 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 2, 29 | "offset": 1 30 | }, 31 | "end": { 32 | "line": 2, 33 | "column": 1, 34 | "offset": 4 35 | } 36 | } 37 | }, 38 | { 39 | "type": "text", 40 | "value": "b", 41 | "position": { 42 | "start": { 43 | "line": 2, 44 | "column": 1, 45 | "offset": 4 46 | }, 47 | "end": { 48 | "line": 2, 49 | "column": 2, 50 | "offset": 5 51 | } 52 | } 53 | } 54 | ], 55 | "position": { 56 | "start": { 57 | "line": 1, 58 | "column": 1, 59 | "offset": 0 60 | }, 61 | "end": { 62 | "line": 2, 63 | "column": 2, 64 | "offset": 5 65 | } 66 | } 67 | }, 68 | { 69 | "type": "paragraph", 70 | "children": [ 71 | { 72 | "type": "text", 73 | "value": "c", 74 | "position": { 75 | "start": { 76 | "line": 4, 77 | "column": 1, 78 | "offset": 7 79 | }, 80 | "end": { 81 | "line": 4, 82 | "column": 2, 83 | "offset": 8 84 | } 85 | } 86 | }, 87 | { 88 | "type": "break", 89 | "position": { 90 | "start": { 91 | "line": 4, 92 | "column": 2, 93 | "offset": 8 94 | }, 95 | "end": { 96 | "line": 5, 97 | "column": 1, 98 | "offset": 11 99 | } 100 | } 101 | }, 102 | { 103 | "type": "text", 104 | "value": "d", 105 | "position": { 106 | "start": { 107 | "line": 5, 108 | "column": 3, 109 | "offset": 13 110 | }, 111 | "end": { 112 | "line": 5, 113 | "column": 4, 114 | "offset": 14 115 | } 116 | } 117 | } 118 | ], 119 | "position": { 120 | "start": { 121 | "line": 4, 122 | "column": 1, 123 | "offset": 7 124 | }, 125 | "end": { 126 | "line": 5, 127 | "column": 4, 128 | "offset": 14 129 | } 130 | } 131 | }, 132 | { 133 | "type": "paragraph", 134 | "children": [ 135 | { 136 | "type": "text", 137 | "value": "e", 138 | "position": { 139 | "start": { 140 | "line": 7, 141 | "column": 1, 142 | "offset": 16 143 | }, 144 | "end": { 145 | "line": 7, 146 | "column": 2, 147 | "offset": 17 148 | } 149 | } 150 | }, 151 | { 152 | "type": "break", 153 | "position": { 154 | "start": { 155 | "line": 7, 156 | "column": 2, 157 | "offset": 17 158 | }, 159 | "end": { 160 | "line": 8, 161 | "column": 1, 162 | "offset": 22 163 | } 164 | } 165 | }, 166 | { 167 | "type": "text", 168 | "value": "f", 169 | "position": { 170 | "start": { 171 | "line": 8, 172 | "column": 1, 173 | "offset": 22 174 | }, 175 | "end": { 176 | "line": 8, 177 | "column": 2, 178 | "offset": 23 179 | } 180 | } 181 | } 182 | ], 183 | "position": { 184 | "start": { 185 | "line": 7, 186 | "column": 1, 187 | "offset": 16 188 | }, 189 | "end": { 190 | "line": 8, 191 | "column": 2, 192 | "offset": 23 193 | } 194 | } 195 | }, 196 | { 197 | "type": "paragraph", 198 | "children": [ 199 | { 200 | "type": "text", 201 | "value": "g\nh", 202 | "position": { 203 | "start": { 204 | "line": 10, 205 | "column": 1, 206 | "offset": 25 207 | }, 208 | "end": { 209 | "line": 11, 210 | "column": 2, 211 | "offset": 29 212 | } 213 | } 214 | } 215 | ], 216 | "position": { 217 | "start": { 218 | "line": 10, 219 | "column": 1, 220 | "offset": 25 221 | }, 222 | "end": { 223 | "line": 11, 224 | "column": 2, 225 | "offset": 29 226 | } 227 | } 228 | } 229 | ], 230 | "position": { 231 | "start": { 232 | "line": 1, 233 | "column": 1, 234 | "offset": 0 235 | }, 236 | "end": { 237 | "line": 11, 238 | "column": 2, 239 | "offset": 29 240 | } 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /test/fixtures/hard-break-prefix.md: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | 4 | c 5 | d 6 | 7 | e 8 | f 9 | 10 | g 11 | h -------------------------------------------------------------------------------- /test/fixtures/heading-atx.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "heading", 6 | "depth": 1, 7 | "children": [ 8 | { 9 | "type": "text", 10 | "value": "Heading 1", 11 | "position": { 12 | "start": { 13 | "line": 1, 14 | "column": 3, 15 | "offset": 2 16 | }, 17 | "end": { 18 | "line": 1, 19 | "column": 12, 20 | "offset": 11 21 | } 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 1, 33 | "column": 12, 34 | "offset": 11 35 | } 36 | } 37 | }, 38 | { 39 | "type": "heading", 40 | "depth": 2, 41 | "children": [ 42 | { 43 | "type": "text", 44 | "value": "Heading 2", 45 | "position": { 46 | "start": { 47 | "line": 2, 48 | "column": 4, 49 | "offset": 15 50 | }, 51 | "end": { 52 | "line": 2, 53 | "column": 13, 54 | "offset": 24 55 | } 56 | } 57 | } 58 | ], 59 | "position": { 60 | "start": { 61 | "line": 2, 62 | "column": 1, 63 | "offset": 12 64 | }, 65 | "end": { 66 | "line": 2, 67 | "column": 13, 68 | "offset": 24 69 | } 70 | } 71 | }, 72 | { 73 | "type": "heading", 74 | "depth": 3, 75 | "children": [ 76 | { 77 | "type": "text", 78 | "value": "Heading 3", 79 | "position": { 80 | "start": { 81 | "line": 3, 82 | "column": 5, 83 | "offset": 29 84 | }, 85 | "end": { 86 | "line": 3, 87 | "column": 14, 88 | "offset": 38 89 | } 90 | } 91 | } 92 | ], 93 | "position": { 94 | "start": { 95 | "line": 3, 96 | "column": 1, 97 | "offset": 25 98 | }, 99 | "end": { 100 | "line": 3, 101 | "column": 14, 102 | "offset": 38 103 | } 104 | } 105 | }, 106 | { 107 | "type": "heading", 108 | "depth": 4, 109 | "children": [ 110 | { 111 | "type": "text", 112 | "value": "Heading 4", 113 | "position": { 114 | "start": { 115 | "line": 4, 116 | "column": 6, 117 | "offset": 44 118 | }, 119 | "end": { 120 | "line": 4, 121 | "column": 15, 122 | "offset": 53 123 | } 124 | } 125 | } 126 | ], 127 | "position": { 128 | "start": { 129 | "line": 4, 130 | "column": 1, 131 | "offset": 39 132 | }, 133 | "end": { 134 | "line": 4, 135 | "column": 15, 136 | "offset": 53 137 | } 138 | } 139 | }, 140 | { 141 | "type": "heading", 142 | "depth": 5, 143 | "children": [ 144 | { 145 | "type": "text", 146 | "value": "Heading 5", 147 | "position": { 148 | "start": { 149 | "line": 5, 150 | "column": 7, 151 | "offset": 60 152 | }, 153 | "end": { 154 | "line": 5, 155 | "column": 16, 156 | "offset": 69 157 | } 158 | } 159 | } 160 | ], 161 | "position": { 162 | "start": { 163 | "line": 5, 164 | "column": 1, 165 | "offset": 54 166 | }, 167 | "end": { 168 | "line": 5, 169 | "column": 16, 170 | "offset": 69 171 | } 172 | } 173 | }, 174 | { 175 | "type": "heading", 176 | "depth": 6, 177 | "children": [ 178 | { 179 | "type": "text", 180 | "value": "Heading 6", 181 | "position": { 182 | "start": { 183 | "line": 6, 184 | "column": 8, 185 | "offset": 77 186 | }, 187 | "end": { 188 | "line": 6, 189 | "column": 17, 190 | "offset": 86 191 | } 192 | } 193 | } 194 | ], 195 | "position": { 196 | "start": { 197 | "line": 6, 198 | "column": 1, 199 | "offset": 70 200 | }, 201 | "end": { 202 | "line": 6, 203 | "column": 17, 204 | "offset": 86 205 | } 206 | } 207 | }, 208 | { 209 | "type": "paragraph", 210 | "children": [ 211 | { 212 | "type": "text", 213 | "value": "####### Paragraph 7", 214 | "position": { 215 | "start": { 216 | "line": 7, 217 | "column": 1, 218 | "offset": 87 219 | }, 220 | "end": { 221 | "line": 7, 222 | "column": 20, 223 | "offset": 106 224 | } 225 | } 226 | } 227 | ], 228 | "position": { 229 | "start": { 230 | "line": 7, 231 | "column": 1, 232 | "offset": 87 233 | }, 234 | "end": { 235 | "line": 7, 236 | "column": 20, 237 | "offset": 106 238 | } 239 | } 240 | }, 241 | { 242 | "type": "heading", 243 | "depth": 1, 244 | "children": [ 245 | { 246 | "type": "text", 247 | "value": "Heading w/ a closing sequence", 248 | "position": { 249 | "start": { 250 | "line": 9, 251 | "column": 3, 252 | "offset": 110 253 | }, 254 | "end": { 255 | "line": 9, 256 | "column": 32, 257 | "offset": 139 258 | } 259 | } 260 | } 261 | ], 262 | "position": { 263 | "start": { 264 | "line": 9, 265 | "column": 1, 266 | "offset": 108 267 | }, 268 | "end": { 269 | "line": 9, 270 | "column": 35, 271 | "offset": 142 272 | } 273 | } 274 | }, 275 | { 276 | "type": "paragraph", 277 | "children": [ 278 | { 279 | "type": "text", 280 | "value": "An empty heading:", 281 | "position": { 282 | "start": { 283 | "line": 11, 284 | "column": 1, 285 | "offset": 144 286 | }, 287 | "end": { 288 | "line": 11, 289 | "column": 18, 290 | "offset": 161 291 | } 292 | } 293 | } 294 | ], 295 | "position": { 296 | "start": { 297 | "line": 11, 298 | "column": 1, 299 | "offset": 144 300 | }, 301 | "end": { 302 | "line": 11, 303 | "column": 18, 304 | "offset": 161 305 | } 306 | } 307 | }, 308 | { 309 | "type": "heading", 310 | "depth": 1, 311 | "children": [], 312 | "position": { 313 | "start": { 314 | "line": 13, 315 | "column": 1, 316 | "offset": 163 317 | }, 318 | "end": { 319 | "line": 13, 320 | "column": 2, 321 | "offset": 164 322 | } 323 | } 324 | }, 325 | { 326 | "type": "heading", 327 | "depth": 2, 328 | "children": [ 329 | { 330 | "type": "text", 331 | "value": "Heading w/ ## hashes ## inside#", 332 | "position": { 333 | "start": { 334 | "line": 15, 335 | "column": 4, 336 | "offset": 169 337 | }, 338 | "end": { 339 | "line": 15, 340 | "column": 35, 341 | "offset": 200 342 | } 343 | } 344 | } 345 | ], 346 | "position": { 347 | "start": { 348 | "line": 15, 349 | "column": 1, 350 | "offset": 166 351 | }, 352 | "end": { 353 | "line": 15, 354 | "column": 35, 355 | "offset": 200 356 | } 357 | } 358 | } 359 | ], 360 | "position": { 361 | "start": { 362 | "line": 1, 363 | "column": 1, 364 | "offset": 0 365 | }, 366 | "end": { 367 | "line": 16, 368 | "column": 1, 369 | "offset": 201 370 | } 371 | } 372 | } 373 | -------------------------------------------------------------------------------- /test/fixtures/heading-atx.md: -------------------------------------------------------------------------------- 1 | # Heading 1 2 | ## Heading 2 3 | ### Heading 3 4 | #### Heading 4 5 | ##### Heading 5 6 | ###### Heading 6 7 | ####### Paragraph 7 8 | 9 | # Heading w/ a closing sequence ## 10 | 11 | An empty heading: 12 | 13 | # 14 | 15 | ## Heading w/ ## hashes ## inside# 16 | -------------------------------------------------------------------------------- /test/fixtures/heading-setext.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "heading", 6 | "depth": 1, 7 | "children": [ 8 | { 9 | "type": "text", 10 | "value": "a", 11 | "position": { 12 | "start": { 13 | "line": 1, 14 | "column": 1, 15 | "offset": 0 16 | }, 17 | "end": { 18 | "line": 1, 19 | "column": 2, 20 | "offset": 1 21 | } 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 2, 33 | "column": 2, 34 | "offset": 3 35 | } 36 | } 37 | }, 38 | { 39 | "type": "heading", 40 | "depth": 2, 41 | "children": [ 42 | { 43 | "type": "text", 44 | "value": "b", 45 | "position": { 46 | "start": { 47 | "line": 4, 48 | "column": 1, 49 | "offset": 5 50 | }, 51 | "end": { 52 | "line": 4, 53 | "column": 2, 54 | "offset": 6 55 | } 56 | } 57 | } 58 | ], 59 | "position": { 60 | "start": { 61 | "line": 4, 62 | "column": 1, 63 | "offset": 5 64 | }, 65 | "end": { 66 | "line": 5, 67 | "column": 2, 68 | "offset": 8 69 | } 70 | } 71 | }, 72 | { 73 | "type": "heading", 74 | "depth": 1, 75 | "children": [ 76 | { 77 | "type": "text", 78 | "value": "c", 79 | "position": { 80 | "start": { 81 | "line": 7, 82 | "column": 1, 83 | "offset": 10 84 | }, 85 | "end": { 86 | "line": 7, 87 | "column": 2, 88 | "offset": 11 89 | } 90 | } 91 | } 92 | ], 93 | "position": { 94 | "start": { 95 | "line": 7, 96 | "column": 1, 97 | "offset": 10 98 | }, 99 | "end": { 100 | "line": 8, 101 | "column": 10, 102 | "offset": 21 103 | } 104 | } 105 | }, 106 | { 107 | "type": "heading", 108 | "depth": 2, 109 | "children": [ 110 | { 111 | "type": "text", 112 | "value": "d", 113 | "position": { 114 | "start": { 115 | "line": 10, 116 | "column": 3, 117 | "offset": 25 118 | }, 119 | "end": { 120 | "line": 10, 121 | "column": 4, 122 | "offset": 26 123 | } 124 | } 125 | } 126 | ], 127 | "position": { 128 | "start": { 129 | "line": 10, 130 | "column": 3, 131 | "offset": 25 132 | }, 133 | "end": { 134 | "line": 11, 135 | "column": 6, 136 | "offset": 32 137 | } 138 | } 139 | }, 140 | { 141 | "type": "heading", 142 | "depth": 1, 143 | "children": [ 144 | { 145 | "type": "text", 146 | "value": "e\nf", 147 | "position": { 148 | "start": { 149 | "line": 13, 150 | "column": 1, 151 | "offset": 34 152 | }, 153 | "end": { 154 | "line": 14, 155 | "column": 2, 156 | "offset": 37 157 | } 158 | } 159 | } 160 | ], 161 | "position": { 162 | "start": { 163 | "line": 13, 164 | "column": 1, 165 | "offset": 34 166 | }, 167 | "end": { 168 | "line": 15, 169 | "column": 2, 170 | "offset": 39 171 | } 172 | } 173 | } 174 | ], 175 | "position": { 176 | "start": { 177 | "line": 1, 178 | "column": 1, 179 | "offset": 0 180 | }, 181 | "end": { 182 | "line": 16, 183 | "column": 1, 184 | "offset": 40 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /test/fixtures/heading-setext.md: -------------------------------------------------------------------------------- 1 | a 2 | = 3 | 4 | b 5 | - 6 | 7 | c 8 | ========= 9 | 10 | d 11 | --- 12 | 13 | e 14 | f 15 | = 16 | -------------------------------------------------------------------------------- /test/fixtures/html-flow.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "html", 6 | "value": "", 7 | "position": { 8 | "start": { 9 | "line": 1, 10 | "column": 1, 11 | "offset": 0 12 | }, 13 | "end": { 14 | "line": 3, 15 | "column": 10, 16 | "offset": 20 17 | } 18 | } 19 | }, 20 | { 21 | "type": "html", 22 | "value": "", 23 | "position": { 24 | "start": { 25 | "line": 5, 26 | "column": 1, 27 | "offset": 22 28 | }, 29 | "end": { 30 | "line": 5, 31 | "column": 9, 32 | "offset": 30 33 | } 34 | } 35 | }, 36 | { 37 | "type": "html", 38 | "value": "", 39 | "position": { 40 | "start": { 41 | "line": 7, 42 | "column": 1, 43 | "offset": 32 44 | }, 45 | "end": { 46 | "line": 7, 47 | "column": 6, 48 | "offset": 37 49 | } 50 | } 51 | }, 52 | { 53 | "type": "html", 54 | "value": "", 55 | "position": { 56 | "start": { 57 | "line": 9, 58 | "column": 1, 59 | "offset": 39 60 | }, 61 | "end": { 62 | "line": 9, 63 | "column": 5, 64 | "offset": 43 65 | } 66 | } 67 | }, 68 | { 69 | "type": "html", 70 | "value": "", 71 | "position": { 72 | "start": { 73 | "line": 11, 74 | "column": 1, 75 | "offset": 45 76 | }, 77 | "end": { 78 | "line": 11, 79 | "column": 14, 80 | "offset": 58 81 | } 82 | } 83 | }, 84 | { 85 | "type": "html", 86 | "value": "", 103 | "position": { 104 | "start": { 105 | "line": 16, 106 | "column": 1, 107 | "offset": 68 108 | }, 109 | "end": { 110 | "line": 16, 111 | "column": 4, 112 | "offset": 71 113 | } 114 | } 115 | } 116 | ], 117 | "position": { 118 | "start": { 119 | "line": 1, 120 | "column": 1, 121 | "offset": 0 122 | }, 123 | "end": { 124 | "line": 17, 125 | "column": 1, 126 | "offset": 72 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /test/fixtures/html-flow.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 | -------------------------------------------------------------------------------- /test/fixtures/html-text.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "a ", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 3, 19 | "offset": 2 20 | } 21 | } 22 | }, 23 | { 24 | "type": "html", 25 | "value": "", 26 | "position": { 27 | "start": { 28 | "line": 1, 29 | "column": 3, 30 | "offset": 2 31 | }, 32 | "end": { 33 | "line": 1, 34 | "column": 6, 35 | "offset": 5 36 | } 37 | } 38 | }, 39 | { 40 | "type": "text", 41 | "value": "c", 42 | "position": { 43 | "start": { 44 | "line": 1, 45 | "column": 6, 46 | "offset": 5 47 | }, 48 | "end": { 49 | "line": 1, 50 | "column": 7, 51 | "offset": 6 52 | } 53 | } 54 | }, 55 | { 56 | "type": "html", 57 | "value": "", 58 | "position": { 59 | "start": { 60 | "line": 1, 61 | "column": 7, 62 | "offset": 6 63 | }, 64 | "end": { 65 | "line": 1, 66 | "column": 11, 67 | "offset": 10 68 | } 69 | } 70 | }, 71 | { 72 | "type": "text", 73 | "value": " d", 74 | "position": { 75 | "start": { 76 | "line": 1, 77 | "column": 11, 78 | "offset": 10 79 | }, 80 | "end": { 81 | "line": 1, 82 | "column": 13, 83 | "offset": 12 84 | } 85 | } 86 | } 87 | ], 88 | "position": { 89 | "start": { 90 | "line": 1, 91 | "column": 1, 92 | "offset": 0 93 | }, 94 | "end": { 95 | "line": 1, 96 | "column": 13, 97 | "offset": 12 98 | } 99 | } 100 | }, 101 | { 102 | "type": "paragraph", 103 | "children": [ 104 | { 105 | "type": "text", 106 | "value": "e ", 107 | "position": { 108 | "start": { 109 | "line": 3, 110 | "column": 1, 111 | "offset": 14 112 | }, 113 | "end": { 114 | "line": 3, 115 | "column": 3, 116 | "offset": 16 117 | } 118 | } 119 | }, 120 | { 121 | "type": "html", 122 | "value": "", 123 | "position": { 124 | "start": { 125 | "line": 3, 126 | "column": 3, 127 | "offset": 16 128 | }, 129 | "end": { 130 | "line": 3, 131 | "column": 11, 132 | "offset": 24 133 | } 134 | } 135 | } 136 | ], 137 | "position": { 138 | "start": { 139 | "line": 3, 140 | "column": 1, 141 | "offset": 14 142 | }, 143 | "end": { 144 | "line": 3, 145 | "column": 11, 146 | "offset": 24 147 | } 148 | } 149 | }, 150 | { 151 | "type": "paragraph", 152 | "children": [ 153 | { 154 | "type": "text", 155 | "value": "g ", 156 | "position": { 157 | "start": { 158 | "line": 5, 159 | "column": 1, 160 | "offset": 26 161 | }, 162 | "end": { 163 | "line": 5, 164 | "column": 3, 165 | "offset": 28 166 | } 167 | } 168 | }, 169 | { 170 | "type": "html", 171 | "value": "", 172 | "position": { 173 | "start": { 174 | "line": 5, 175 | "column": 3, 176 | "offset": 28 177 | }, 178 | "end": { 179 | "line": 5, 180 | "column": 8, 181 | "offset": 33 182 | } 183 | } 184 | } 185 | ], 186 | "position": { 187 | "start": { 188 | "line": 5, 189 | "column": 1, 190 | "offset": 26 191 | }, 192 | "end": { 193 | "line": 5, 194 | "column": 8, 195 | "offset": 33 196 | } 197 | } 198 | }, 199 | { 200 | "type": "paragraph", 201 | "children": [ 202 | { 203 | "type": "text", 204 | "value": "i ", 205 | "position": { 206 | "start": { 207 | "line": 7, 208 | "column": 1, 209 | "offset": 35 210 | }, 211 | "end": { 212 | "line": 7, 213 | "column": 3, 214 | "offset": 37 215 | } 216 | } 217 | }, 218 | { 219 | "type": "html", 220 | "value": "", 221 | "position": { 222 | "start": { 223 | "line": 7, 224 | "column": 3, 225 | "offset": 37 226 | }, 227 | "end": { 228 | "line": 7, 229 | "column": 7, 230 | "offset": 41 231 | } 232 | } 233 | } 234 | ], 235 | "position": { 236 | "start": { 237 | "line": 7, 238 | "column": 1, 239 | "offset": 35 240 | }, 241 | "end": { 242 | "line": 7, 243 | "column": 7, 244 | "offset": 41 245 | } 246 | } 247 | }, 248 | { 249 | "type": "paragraph", 250 | "children": [ 251 | { 252 | "type": "text", 253 | "value": "k ", 254 | "position": { 255 | "start": { 256 | "line": 9, 257 | "column": 1, 258 | "offset": 43 259 | }, 260 | "end": { 261 | "line": 9, 262 | "column": 3, 263 | "offset": 45 264 | } 265 | } 266 | }, 267 | { 268 | "type": "html", 269 | "value": "", 270 | "position": { 271 | "start": { 272 | "line": 9, 273 | "column": 3, 274 | "offset": 45 275 | }, 276 | "end": { 277 | "line": 9, 278 | "column": 16, 279 | "offset": 58 280 | } 281 | } 282 | } 283 | ], 284 | "position": { 285 | "start": { 286 | "line": 9, 287 | "column": 1, 288 | "offset": 43 289 | }, 290 | "end": { 291 | "line": 9, 292 | "column": 16, 293 | "offset": 58 294 | } 295 | } 296 | }, 297 | { 298 | "type": "paragraph", 299 | "children": [ 300 | { 301 | "type": "text", 302 | "value": "m ", 303 | "position": { 304 | "start": { 305 | "line": 11, 306 | "column": 1, 307 | "offset": 60 308 | }, 309 | "end": { 310 | "line": 11, 311 | "column": 3, 312 | "offset": 62 313 | } 314 | } 315 | }, 316 | { 317 | "type": "html", 318 | "value": "
", 319 | "position": { 320 | "start": { 321 | "line": 11, 322 | "column": 3, 323 | "offset": 62 324 | }, 325 | "end": { 326 | "line": 11, 327 | "column": 8, 328 | "offset": 67 329 | } 330 | } 331 | }, 332 | { 333 | "type": "text", 334 | "value": " n", 335 | "position": { 336 | "start": { 337 | "line": 11, 338 | "column": 8, 339 | "offset": 67 340 | }, 341 | "end": { 342 | "line": 11, 343 | "column": 10, 344 | "offset": 69 345 | } 346 | } 347 | } 348 | ], 349 | "position": { 350 | "start": { 351 | "line": 11, 352 | "column": 1, 353 | "offset": 60 354 | }, 355 | "end": { 356 | "line": 11, 357 | "column": 10, 358 | "offset": 69 359 | } 360 | } 361 | } 362 | ], 363 | "position": { 364 | "start": { 365 | "line": 1, 366 | "column": 1, 367 | "offset": 0 368 | }, 369 | "end": { 370 | "line": 12, 371 | "column": 1, 372 | "offset": 70 373 | } 374 | } 375 | } 376 | -------------------------------------------------------------------------------- /test/fixtures/html-text.md: -------------------------------------------------------------------------------- 1 | a c d 2 | 3 | e 4 | 5 | g 6 | 7 | i 8 | 9 | k 10 | 11 | m
n 12 | -------------------------------------------------------------------------------- /test/fixtures/image-reference.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Not references, as they’re not defined ![a], ![b][], ![c][d].", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 62, 19 | "offset": 61 20 | } 21 | } 22 | } 23 | ], 24 | "position": { 25 | "start": { 26 | "line": 1, 27 | "column": 1, 28 | "offset": 0 29 | }, 30 | "end": { 31 | "line": 1, 32 | "column": 62, 33 | "offset": 61 34 | } 35 | } 36 | }, 37 | { 38 | "type": "paragraph", 39 | "children": [ 40 | { 41 | "type": "text", 42 | "value": "References! ", 43 | "position": { 44 | "start": { 45 | "line": 3, 46 | "column": 1, 47 | "offset": 63 48 | }, 49 | "end": { 50 | "line": 3, 51 | "column": 13, 52 | "offset": 75 53 | } 54 | } 55 | }, 56 | { 57 | "type": "imageReference", 58 | "alt": "e", 59 | "position": { 60 | "start": { 61 | "line": 3, 62 | "column": 13, 63 | "offset": 75 64 | }, 65 | "end": { 66 | "line": 3, 67 | "column": 17, 68 | "offset": 79 69 | } 70 | }, 71 | "label": "e", 72 | "identifier": "e", 73 | "referenceType": "shortcut" 74 | }, 75 | { 76 | "type": "text", 77 | "value": ", ", 78 | "position": { 79 | "start": { 80 | "line": 3, 81 | "column": 17, 82 | "offset": 79 83 | }, 84 | "end": { 85 | "line": 3, 86 | "column": 19, 87 | "offset": 81 88 | } 89 | } 90 | }, 91 | { 92 | "type": "imageReference", 93 | "alt": "f", 94 | "position": { 95 | "start": { 96 | "line": 3, 97 | "column": 19, 98 | "offset": 81 99 | }, 100 | "end": { 101 | "line": 3, 102 | "column": 25, 103 | "offset": 87 104 | } 105 | }, 106 | "label": "f", 107 | "identifier": "f", 108 | "referenceType": "collapsed" 109 | }, 110 | { 111 | "type": "text", 112 | "value": ", ", 113 | "position": { 114 | "start": { 115 | "line": 3, 116 | "column": 25, 117 | "offset": 87 118 | }, 119 | "end": { 120 | "line": 3, 121 | "column": 27, 122 | "offset": 89 123 | } 124 | } 125 | }, 126 | { 127 | "type": "imageReference", 128 | "alt": "g", 129 | "position": { 130 | "start": { 131 | "line": 3, 132 | "column": 27, 133 | "offset": 89 134 | }, 135 | "end": { 136 | "line": 3, 137 | "column": 34, 138 | "offset": 96 139 | } 140 | }, 141 | "label": "h", 142 | "identifier": "h", 143 | "referenceType": "full" 144 | } 145 | ], 146 | "position": { 147 | "start": { 148 | "line": 3, 149 | "column": 1, 150 | "offset": 63 151 | }, 152 | "end": { 153 | "line": 3, 154 | "column": 34, 155 | "offset": 96 156 | } 157 | } 158 | }, 159 | { 160 | "type": "definition", 161 | "identifier": "e", 162 | "label": "e", 163 | "title": null, 164 | "url": "x", 165 | "position": { 166 | "start": { 167 | "line": 5, 168 | "column": 1, 169 | "offset": 98 170 | }, 171 | "end": { 172 | "line": 5, 173 | "column": 7, 174 | "offset": 104 175 | } 176 | } 177 | }, 178 | { 179 | "type": "definition", 180 | "identifier": "f", 181 | "label": "f", 182 | "title": null, 183 | "url": "y", 184 | "position": { 185 | "start": { 186 | "line": 6, 187 | "column": 1, 188 | "offset": 105 189 | }, 190 | "end": { 191 | "line": 6, 192 | "column": 7, 193 | "offset": 111 194 | } 195 | } 196 | }, 197 | { 198 | "type": "definition", 199 | "identifier": "h", 200 | "label": "h", 201 | "title": null, 202 | "url": "z", 203 | "position": { 204 | "start": { 205 | "line": 7, 206 | "column": 1, 207 | "offset": 112 208 | }, 209 | "end": { 210 | "line": 7, 211 | "column": 7, 212 | "offset": 118 213 | } 214 | } 215 | } 216 | ], 217 | "position": { 218 | "start": { 219 | "line": 1, 220 | "column": 1, 221 | "offset": 0 222 | }, 223 | "end": { 224 | "line": 8, 225 | "column": 1, 226 | "offset": 119 227 | } 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /test/fixtures/image-reference.md: -------------------------------------------------------------------------------- 1 | Not references, as they’re not defined ![a], ![b][], ![c][d]. 2 | 3 | References! ![e], ![f][], ![g][h] 4 | 5 | [e]: x 6 | [f]: y 7 | [h]: z 8 | -------------------------------------------------------------------------------- /test/fixtures/image-resource-eol.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "a ", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 3, 19 | "offset": 2 20 | } 21 | } 22 | }, 23 | { 24 | "type": "image", 25 | "title": null, 26 | "url": "c", 27 | "alt": "\nb", 28 | "position": { 29 | "start": { 30 | "line": 1, 31 | "column": 3, 32 | "offset": 2 33 | }, 34 | "end": { 35 | "line": 2, 36 | "column": 6, 37 | "offset": 10 38 | } 39 | } 40 | }, 41 | { 42 | "type": "text", 43 | "value": " d", 44 | "position": { 45 | "start": { 46 | "line": 2, 47 | "column": 6, 48 | "offset": 10 49 | }, 50 | "end": { 51 | "line": 2, 52 | "column": 8, 53 | "offset": 12 54 | } 55 | } 56 | } 57 | ], 58 | "position": { 59 | "start": { 60 | "line": 1, 61 | "column": 1, 62 | "offset": 0 63 | }, 64 | "end": { 65 | "line": 2, 66 | "column": 8, 67 | "offset": 12 68 | } 69 | } 70 | }, 71 | { 72 | "type": "paragraph", 73 | "children": [ 74 | { 75 | "type": "text", 76 | "value": "a ", 77 | "position": { 78 | "start": { 79 | "line": 4, 80 | "column": 1, 81 | "offset": 14 82 | }, 83 | "end": { 84 | "line": 4, 85 | "column": 3, 86 | "offset": 16 87 | } 88 | } 89 | }, 90 | { 91 | "type": "image", 92 | "title": null, 93 | "url": "c", 94 | "alt": "b\n", 95 | "position": { 96 | "start": { 97 | "line": 4, 98 | "column": 3, 99 | "offset": 16 100 | }, 101 | "end": { 102 | "line": 5, 103 | "column": 5, 104 | "offset": 24 105 | } 106 | } 107 | }, 108 | { 109 | "type": "text", 110 | "value": " d", 111 | "position": { 112 | "start": { 113 | "line": 5, 114 | "column": 5, 115 | "offset": 24 116 | }, 117 | "end": { 118 | "line": 5, 119 | "column": 7, 120 | "offset": 26 121 | } 122 | } 123 | } 124 | ], 125 | "position": { 126 | "start": { 127 | "line": 4, 128 | "column": 1, 129 | "offset": 14 130 | }, 131 | "end": { 132 | "line": 5, 133 | "column": 7, 134 | "offset": 26 135 | } 136 | } 137 | }, 138 | { 139 | "type": "paragraph", 140 | "children": [ 141 | { 142 | "type": "text", 143 | "value": "a ", 144 | "position": { 145 | "start": { 146 | "line": 7, 147 | "column": 1, 148 | "offset": 28 149 | }, 150 | "end": { 151 | "line": 7, 152 | "column": 3, 153 | "offset": 30 154 | } 155 | } 156 | }, 157 | { 158 | "type": "image", 159 | "title": null, 160 | "url": "d", 161 | "alt": "b\nc", 162 | "position": { 163 | "start": { 164 | "line": 7, 165 | "column": 3, 166 | "offset": 30 167 | }, 168 | "end": { 169 | "line": 8, 170 | "column": 6, 171 | "offset": 39 172 | } 173 | } 174 | }, 175 | { 176 | "type": "text", 177 | "value": " e", 178 | "position": { 179 | "start": { 180 | "line": 8, 181 | "column": 6, 182 | "offset": 39 183 | }, 184 | "end": { 185 | "line": 8, 186 | "column": 8, 187 | "offset": 41 188 | } 189 | } 190 | } 191 | ], 192 | "position": { 193 | "start": { 194 | "line": 7, 195 | "column": 1, 196 | "offset": 28 197 | }, 198 | "end": { 199 | "line": 8, 200 | "column": 8, 201 | "offset": 41 202 | } 203 | } 204 | }, 205 | { 206 | "type": "paragraph", 207 | "children": [ 208 | { 209 | "type": "text", 210 | "value": "a ", 211 | "position": { 212 | "start": { 213 | "line": 10, 214 | "column": 1, 215 | "offset": 43 216 | }, 217 | "end": { 218 | "line": 10, 219 | "column": 3, 220 | "offset": 45 221 | } 222 | } 223 | }, 224 | { 225 | "type": "image", 226 | "title": null, 227 | "url": "c", 228 | "alt": "b", 229 | "position": { 230 | "start": { 231 | "line": 10, 232 | "column": 3, 233 | "offset": 45 234 | }, 235 | "end": { 236 | "line": 11, 237 | "column": 3, 238 | "offset": 53 239 | } 240 | } 241 | }, 242 | { 243 | "type": "text", 244 | "value": " d", 245 | "position": { 246 | "start": { 247 | "line": 11, 248 | "column": 3, 249 | "offset": 53 250 | }, 251 | "end": { 252 | "line": 11, 253 | "column": 5, 254 | "offset": 55 255 | } 256 | } 257 | } 258 | ], 259 | "position": { 260 | "start": { 261 | "line": 10, 262 | "column": 1, 263 | "offset": 43 264 | }, 265 | "end": { 266 | "line": 11, 267 | "column": 5, 268 | "offset": 55 269 | } 270 | } 271 | }, 272 | { 273 | "type": "paragraph", 274 | "children": [ 275 | { 276 | "type": "text", 277 | "value": "a ", 278 | "position": { 279 | "start": { 280 | "line": 13, 281 | "column": 1, 282 | "offset": 57 283 | }, 284 | "end": { 285 | "line": 13, 286 | "column": 3, 287 | "offset": 59 288 | } 289 | } 290 | }, 291 | { 292 | "type": "image", 293 | "title": null, 294 | "url": "c", 295 | "alt": "b", 296 | "position": { 297 | "start": { 298 | "line": 13, 299 | "column": 3, 300 | "offset": 59 301 | }, 302 | "end": { 303 | "line": 14, 304 | "column": 2, 305 | "offset": 67 306 | } 307 | } 308 | }, 309 | { 310 | "type": "text", 311 | "value": " d", 312 | "position": { 313 | "start": { 314 | "line": 14, 315 | "column": 2, 316 | "offset": 67 317 | }, 318 | "end": { 319 | "line": 14, 320 | "column": 4, 321 | "offset": 69 322 | } 323 | } 324 | } 325 | ], 326 | "position": { 327 | "start": { 328 | "line": 13, 329 | "column": 1, 330 | "offset": 57 331 | }, 332 | "end": { 333 | "line": 14, 334 | "column": 4, 335 | "offset": 69 336 | } 337 | } 338 | }, 339 | { 340 | "type": "paragraph", 341 | "children": [ 342 | { 343 | "type": "text", 344 | "value": "a ", 345 | "position": { 346 | "start": { 347 | "line": 16, 348 | "column": 1, 349 | "offset": 71 350 | }, 351 | "end": { 352 | "line": 16, 353 | "column": 3, 354 | "offset": 73 355 | } 356 | } 357 | }, 358 | { 359 | "type": "image", 360 | "title": "d", 361 | "url": "c", 362 | "alt": "b", 363 | "position": { 364 | "start": { 365 | "line": 16, 366 | "column": 3, 367 | "offset": 73 368 | }, 369 | "end": { 370 | "line": 17, 371 | "column": 5, 372 | "offset": 84 373 | } 374 | } 375 | }, 376 | { 377 | "type": "text", 378 | "value": " e", 379 | "position": { 380 | "start": { 381 | "line": 17, 382 | "column": 5, 383 | "offset": 84 384 | }, 385 | "end": { 386 | "line": 17, 387 | "column": 7, 388 | "offset": 86 389 | } 390 | } 391 | } 392 | ], 393 | "position": { 394 | "start": { 395 | "line": 16, 396 | "column": 1, 397 | "offset": 71 398 | }, 399 | "end": { 400 | "line": 17, 401 | "column": 7, 402 | "offset": 86 403 | } 404 | } 405 | }, 406 | { 407 | "type": "paragraph", 408 | "children": [ 409 | { 410 | "type": "text", 411 | "value": "a ", 412 | "position": { 413 | "start": { 414 | "line": 19, 415 | "column": 1, 416 | "offset": 88 417 | }, 418 | "end": { 419 | "line": 19, 420 | "column": 3, 421 | "offset": 90 422 | } 423 | } 424 | }, 425 | { 426 | "type": "image", 427 | "title": "d\ne", 428 | "url": "c", 429 | "alt": "b", 430 | "position": { 431 | "start": { 432 | "line": 19, 433 | "column": 3, 434 | "offset": 90 435 | }, 436 | "end": { 437 | "line": 20, 438 | "column": 4, 439 | "offset": 103 440 | } 441 | } 442 | }, 443 | { 444 | "type": "text", 445 | "value": " f", 446 | "position": { 447 | "start": { 448 | "line": 20, 449 | "column": 4, 450 | "offset": 103 451 | }, 452 | "end": { 453 | "line": 20, 454 | "column": 6, 455 | "offset": 105 456 | } 457 | } 458 | } 459 | ], 460 | "position": { 461 | "start": { 462 | "line": 19, 463 | "column": 1, 464 | "offset": 88 465 | }, 466 | "end": { 467 | "line": 20, 468 | "column": 6, 469 | "offset": 105 470 | } 471 | } 472 | }, 473 | { 474 | "type": "paragraph", 475 | "children": [ 476 | { 477 | "type": "text", 478 | "value": "a ", 479 | "position": { 480 | "start": { 481 | "line": 22, 482 | "column": 1, 483 | "offset": 107 484 | }, 485 | "end": { 486 | "line": 22, 487 | "column": 3, 488 | "offset": 109 489 | } 490 | } 491 | }, 492 | { 493 | "type": "image", 494 | "title": "d\ne\nf", 495 | "url": "c", 496 | "alt": "b", 497 | "position": { 498 | "start": { 499 | "line": 22, 500 | "column": 3, 501 | "offset": 109 502 | }, 503 | "end": { 504 | "line": 24, 505 | "column": 4, 506 | "offset": 124 507 | } 508 | } 509 | }, 510 | { 511 | "type": "text", 512 | "value": " g", 513 | "position": { 514 | "start": { 515 | "line": 24, 516 | "column": 4, 517 | "offset": 124 518 | }, 519 | "end": { 520 | "line": 24, 521 | "column": 6, 522 | "offset": 126 523 | } 524 | } 525 | } 526 | ], 527 | "position": { 528 | "start": { 529 | "line": 22, 530 | "column": 1, 531 | "offset": 107 532 | }, 533 | "end": { 534 | "line": 24, 535 | "column": 6, 536 | "offset": 126 537 | } 538 | } 539 | } 540 | ], 541 | "position": { 542 | "start": { 543 | "line": 1, 544 | "column": 1, 545 | "offset": 0 546 | }, 547 | "end": { 548 | "line": 25, 549 | "column": 1, 550 | "offset": 127 551 | } 552 | } 553 | } 554 | -------------------------------------------------------------------------------- /test/fixtures/image-resource-eol.md: -------------------------------------------------------------------------------- 1 | a ![ 2 | b](c) d 3 | 4 | a ![b 5 | ](c) d 6 | 7 | a ![b 8 | c](d) e 9 | 10 | a ![b]( 11 | c) d 12 | 13 | a ![b](c 14 | ) d 15 | 16 | a ![b](c 17 | "d") e 18 | 19 | a ![b](c "d 20 | e") f 21 | 22 | a ![b](c "d 23 | e 24 | f") g 25 | -------------------------------------------------------------------------------- /test/fixtures/image-resource.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Resources: ", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 12, 19 | "offset": 11 20 | } 21 | } 22 | }, 23 | { 24 | "type": "image", 25 | "title": null, 26 | "url": "b", 27 | "alt": "a", 28 | "position": { 29 | "start": { 30 | "line": 1, 31 | "column": 12, 32 | "offset": 11 33 | }, 34 | "end": { 35 | "line": 1, 36 | "column": 19, 37 | "offset": 18 38 | } 39 | } 40 | }, 41 | { 42 | "type": "text", 43 | "value": ", ", 44 | "position": { 45 | "start": { 46 | "line": 1, 47 | "column": 19, 48 | "offset": 18 49 | }, 50 | "end": { 51 | "line": 1, 52 | "column": 21, 53 | "offset": 20 54 | } 55 | } 56 | }, 57 | { 58 | "type": "image", 59 | "title": "e", 60 | "url": "d", 61 | "alt": "c", 62 | "position": { 63 | "start": { 64 | "line": 1, 65 | "column": 21, 66 | "offset": 20 67 | }, 68 | "end": { 69 | "line": 1, 70 | "column": 32, 71 | "offset": 31 72 | } 73 | } 74 | }, 75 | { 76 | "type": "text", 77 | "value": ", ", 78 | "position": { 79 | "start": { 80 | "line": 1, 81 | "column": 32, 82 | "offset": 31 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 34, 87 | "offset": 33 88 | } 89 | } 90 | }, 91 | { 92 | "type": "image", 93 | "title": "h", 94 | "url": "g", 95 | "alt": "f", 96 | "position": { 97 | "start": { 98 | "line": 1, 99 | "column": 34, 100 | "offset": 33 101 | }, 102 | "end": { 103 | "line": 1, 104 | "column": 45, 105 | "offset": 44 106 | } 107 | } 108 | }, 109 | { 110 | "type": "text", 111 | "value": ", ", 112 | "position": { 113 | "start": { 114 | "line": 1, 115 | "column": 45, 116 | "offset": 44 117 | }, 118 | "end": { 119 | "line": 1, 120 | "column": 47, 121 | "offset": 46 122 | } 123 | } 124 | }, 125 | { 126 | "type": "image", 127 | "title": "k", 128 | "url": "j", 129 | "alt": "i", 130 | "position": { 131 | "start": { 132 | "line": 1, 133 | "column": 47, 134 | "offset": 46 135 | }, 136 | "end": { 137 | "line": 1, 138 | "column": 58, 139 | "offset": 57 140 | } 141 | } 142 | }, 143 | { 144 | "type": "text", 145 | "value": ", ", 146 | "position": { 147 | "start": { 148 | "line": 1, 149 | "column": 58, 150 | "offset": 57 151 | }, 152 | "end": { 153 | "line": 1, 154 | "column": 60, 155 | "offset": 59 156 | } 157 | } 158 | }, 159 | { 160 | "type": "image", 161 | "title": null, 162 | "url": "m", 163 | "alt": "l", 164 | "position": { 165 | "start": { 166 | "line": 1, 167 | "column": 60, 168 | "offset": 59 169 | }, 170 | "end": { 171 | "line": 1, 172 | "column": 69, 173 | "offset": 68 174 | } 175 | } 176 | }, 177 | { 178 | "type": "text", 179 | "value": ".", 180 | "position": { 181 | "start": { 182 | "line": 1, 183 | "column": 69, 184 | "offset": 68 185 | }, 186 | "end": { 187 | "line": 1, 188 | "column": 70, 189 | "offset": 69 190 | } 191 | } 192 | } 193 | ], 194 | "position": { 195 | "start": { 196 | "line": 1, 197 | "column": 1, 198 | "offset": 0 199 | }, 200 | "end": { 201 | "line": 1, 202 | "column": 70, 203 | "offset": 69 204 | } 205 | } 206 | }, 207 | { 208 | "type": "paragraph", 209 | "children": [ 210 | { 211 | "type": "text", 212 | "value": "“Content” in images: ", 213 | "position": { 214 | "start": { 215 | "line": 3, 216 | "column": 1, 217 | "offset": 71 218 | }, 219 | "end": { 220 | "line": 3, 221 | "column": 22, 222 | "offset": 92 223 | } 224 | } 225 | }, 226 | { 227 | "type": "image", 228 | "title": null, 229 | "url": "d", 230 | "alt": "a b c", 231 | "position": { 232 | "start": { 233 | "line": 3, 234 | "column": 22, 235 | "offset": 92 236 | }, 237 | "end": { 238 | "line": 3, 239 | "column": 37, 240 | "offset": 107 241 | } 242 | } 243 | }, 244 | { 245 | "type": "text", 246 | "value": ".", 247 | "position": { 248 | "start": { 249 | "line": 3, 250 | "column": 37, 251 | "offset": 107 252 | }, 253 | "end": { 254 | "line": 3, 255 | "column": 38, 256 | "offset": 108 257 | } 258 | } 259 | } 260 | ], 261 | "position": { 262 | "start": { 263 | "line": 3, 264 | "column": 1, 265 | "offset": 71 266 | }, 267 | "end": { 268 | "line": 3, 269 | "column": 38, 270 | "offset": 108 271 | } 272 | } 273 | }, 274 | { 275 | "type": "paragraph", 276 | "children": [ 277 | { 278 | "type": "text", 279 | "value": "Empty: ", 280 | "position": { 281 | "start": { 282 | "line": 5, 283 | "column": 1, 284 | "offset": 110 285 | }, 286 | "end": { 287 | "line": 5, 288 | "column": 8, 289 | "offset": 117 290 | } 291 | } 292 | }, 293 | { 294 | "type": "image", 295 | "title": null, 296 | "url": "", 297 | "alt": "", 298 | "position": { 299 | "start": { 300 | "line": 5, 301 | "column": 8, 302 | "offset": 117 303 | }, 304 | "end": { 305 | "line": 5, 306 | "column": 13, 307 | "offset": 122 308 | } 309 | } 310 | }, 311 | { 312 | "type": "text", 313 | "value": ".", 314 | "position": { 315 | "start": { 316 | "line": 5, 317 | "column": 13, 318 | "offset": 122 319 | }, 320 | "end": { 321 | "line": 5, 322 | "column": 14, 323 | "offset": 123 324 | } 325 | } 326 | } 327 | ], 328 | "position": { 329 | "start": { 330 | "line": 5, 331 | "column": 1, 332 | "offset": 110 333 | }, 334 | "end": { 335 | "line": 5, 336 | "column": 14, 337 | "offset": 123 338 | } 339 | } 340 | }, 341 | { 342 | "type": "paragraph", 343 | "children": [ 344 | { 345 | "type": "text", 346 | "value": "Character references and escapes:\n", 347 | "position": { 348 | "start": { 349 | "line": 7, 350 | "column": 1, 351 | "offset": 125 352 | }, 353 | "end": { 354 | "line": 8, 355 | "column": 1, 356 | "offset": 159 357 | } 358 | } 359 | }, 360 | { 361 | "type": "image", 362 | "title": "i*j\tk&l", 363 | "url": "e*f\tg&h", 364 | "alt": "a*b\tc&d", 365 | "position": { 366 | "start": { 367 | "line": 8, 368 | "column": 1, 369 | "offset": 159 370 | }, 371 | "end": { 372 | "line": 8, 373 | "column": 54, 374 | "offset": 212 375 | } 376 | } 377 | } 378 | ], 379 | "position": { 380 | "start": { 381 | "line": 7, 382 | "column": 1, 383 | "offset": 125 384 | }, 385 | "end": { 386 | "line": 8, 387 | "column": 54, 388 | "offset": 212 389 | } 390 | } 391 | } 392 | ], 393 | "position": { 394 | "start": { 395 | "line": 1, 396 | "column": 1, 397 | "offset": 0 398 | }, 399 | "end": { 400 | "line": 8, 401 | "column": 54, 402 | "offset": 212 403 | } 404 | } 405 | } 406 | -------------------------------------------------------------------------------- /test/fixtures/image-resource.md: -------------------------------------------------------------------------------- 1 | Resources: ![a](b), ![c](d "e"), ![f](g 'h'), ![i](j (k)), ![l](). 2 | 3 | “Content” in images: ![a *b* `c`](d). 4 | 5 | Empty: ![](). 6 | 7 | Character references and escapes: 8 | ![a\*b c&d](e\*f g&h "i\*j k&l") -------------------------------------------------------------------------------- /test/fixtures/link-reference-with-phrasing.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "linkReference", 9 | "children": [ 10 | { 11 | "type": "inlineCode", 12 | "value": "f", 13 | "position": { 14 | "start": { 15 | "line": 1, 16 | "column": 2, 17 | "offset": 1 18 | }, 19 | "end": { 20 | "line": 1, 21 | "column": 5, 22 | "offset": 4 23 | } 24 | } 25 | } 26 | ], 27 | "position": { 28 | "start": { 29 | "line": 1, 30 | "column": 1, 31 | "offset": 0 32 | }, 33 | "end": { 34 | "line": 1, 35 | "column": 8, 36 | "offset": 7 37 | } 38 | }, 39 | "label": "`f`", 40 | "identifier": "`f`", 41 | "referenceType": "collapsed" 42 | }, 43 | { 44 | "type": "text", 45 | "value": "\n", 46 | "position": { 47 | "start": { 48 | "line": 1, 49 | "column": 8, 50 | "offset": 7 51 | }, 52 | "end": { 53 | "line": 2, 54 | "column": 1, 55 | "offset": 8 56 | } 57 | } 58 | }, 59 | { 60 | "type": "linkReference", 61 | "children": [ 62 | { 63 | "type": "text", 64 | "value": ";", 65 | "position": { 66 | "start": { 67 | "line": 2, 68 | "column": 2, 69 | "offset": 9 70 | }, 71 | "end": { 72 | "line": 2, 73 | "column": 8, 74 | "offset": 15 75 | } 76 | } 77 | } 78 | ], 79 | "position": { 80 | "start": { 81 | "line": 2, 82 | "column": 1, 83 | "offset": 8 84 | }, 85 | "end": { 86 | "line": 2, 87 | "column": 11, 88 | "offset": 18 89 | } 90 | }, 91 | "label": ";", 92 | "identifier": ";", 93 | "referenceType": "collapsed" 94 | }, 95 | { 96 | "type": "text", 97 | "value": "\n", 98 | "position": { 99 | "start": { 100 | "line": 2, 101 | "column": 11, 102 | "offset": 18 103 | }, 104 | "end": { 105 | "line": 3, 106 | "column": 1, 107 | "offset": 19 108 | } 109 | } 110 | }, 111 | { 112 | "type": "linkReference", 113 | "children": [ 114 | { 115 | "type": "text", 116 | "value": ";", 117 | "position": { 118 | "start": { 119 | "line": 3, 120 | "column": 2, 121 | "offset": 20 122 | }, 123 | "end": { 124 | "line": 3, 125 | "column": 4, 126 | "offset": 22 127 | } 128 | } 129 | } 130 | ], 131 | "position": { 132 | "start": { 133 | "line": 3, 134 | "column": 1, 135 | "offset": 19 136 | }, 137 | "end": { 138 | "line": 3, 139 | "column": 7, 140 | "offset": 25 141 | } 142 | }, 143 | "label": ";", 144 | "identifier": "\\;", 145 | "referenceType": "collapsed" 146 | }, 147 | { 148 | "type": "text", 149 | "value": "\n", 150 | "position": { 151 | "start": { 152 | "line": 3, 153 | "column": 7, 154 | "offset": 25 155 | }, 156 | "end": { 157 | "line": 4, 158 | "column": 1, 159 | "offset": 26 160 | } 161 | } 162 | }, 163 | { 164 | "type": "linkReference", 165 | "children": [ 166 | { 167 | "type": "text", 168 | "value": ";", 169 | "position": { 170 | "start": { 171 | "line": 4, 172 | "column": 2, 173 | "offset": 27 174 | }, 175 | "end": { 176 | "line": 4, 177 | "column": 3, 178 | "offset": 28 179 | } 180 | } 181 | } 182 | ], 183 | "position": { 184 | "start": { 185 | "line": 4, 186 | "column": 1, 187 | "offset": 26 188 | }, 189 | "end": { 190 | "line": 4, 191 | "column": 6, 192 | "offset": 31 193 | } 194 | }, 195 | "label": ";", 196 | "identifier": ";", 197 | "referenceType": "collapsed" 198 | }, 199 | { 200 | "type": "text", 201 | "value": "\n", 202 | "position": { 203 | "start": { 204 | "line": 4, 205 | "column": 6, 206 | "offset": 31 207 | }, 208 | "end": { 209 | "line": 5, 210 | "column": 1, 211 | "offset": 32 212 | } 213 | } 214 | }, 215 | { 216 | "type": "linkReference", 217 | "children": [ 218 | { 219 | "type": "inlineCode", 220 | "value": "f", 221 | "position": { 222 | "start": { 223 | "line": 5, 224 | "column": 2, 225 | "offset": 33 226 | }, 227 | "end": { 228 | "line": 5, 229 | "column": 5, 230 | "offset": 36 231 | } 232 | } 233 | }, 234 | { 235 | "type": "text", 236 | "value": ";", 237 | "position": { 238 | "start": { 239 | "line": 5, 240 | "column": 5, 241 | "offset": 36 242 | }, 243 | "end": { 244 | "line": 5, 245 | "column": 11, 246 | "offset": 42 247 | } 248 | } 249 | } 250 | ], 251 | "position": { 252 | "start": { 253 | "line": 5, 254 | "column": 1, 255 | "offset": 32 256 | }, 257 | "end": { 258 | "line": 5, 259 | "column": 14, 260 | "offset": 45 261 | } 262 | }, 263 | "label": "`f`;", 264 | "identifier": "`f`;", 265 | "referenceType": "collapsed" 266 | }, 267 | { 268 | "type": "text", 269 | "value": "\n", 270 | "position": { 271 | "start": { 272 | "line": 5, 273 | "column": 14, 274 | "offset": 45 275 | }, 276 | "end": { 277 | "line": 6, 278 | "column": 1, 279 | "offset": 46 280 | } 281 | } 282 | }, 283 | { 284 | "type": "linkReference", 285 | "children": [ 286 | { 287 | "type": "inlineCode", 288 | "value": "f", 289 | "position": { 290 | "start": { 291 | "line": 6, 292 | "column": 2, 293 | "offset": 47 294 | }, 295 | "end": { 296 | "line": 6, 297 | "column": 5, 298 | "offset": 50 299 | } 300 | } 301 | }, 302 | { 303 | "type": "text", 304 | "value": ";", 305 | "position": { 306 | "start": { 307 | "line": 6, 308 | "column": 5, 309 | "offset": 50 310 | }, 311 | "end": { 312 | "line": 6, 313 | "column": 7, 314 | "offset": 52 315 | } 316 | } 317 | } 318 | ], 319 | "position": { 320 | "start": { 321 | "line": 6, 322 | "column": 1, 323 | "offset": 46 324 | }, 325 | "end": { 326 | "line": 6, 327 | "column": 10, 328 | "offset": 55 329 | } 330 | }, 331 | "label": "`f`;", 332 | "identifier": "`f`\\;", 333 | "referenceType": "collapsed" 334 | }, 335 | { 336 | "type": "text", 337 | "value": "\n", 338 | "position": { 339 | "start": { 340 | "line": 6, 341 | "column": 10, 342 | "offset": 55 343 | }, 344 | "end": { 345 | "line": 7, 346 | "column": 1, 347 | "offset": 56 348 | } 349 | } 350 | }, 351 | { 352 | "type": "linkReference", 353 | "children": [ 354 | { 355 | "type": "inlineCode", 356 | "value": "f", 357 | "position": { 358 | "start": { 359 | "line": 7, 360 | "column": 2, 361 | "offset": 57 362 | }, 363 | "end": { 364 | "line": 7, 365 | "column": 5, 366 | "offset": 60 367 | } 368 | } 369 | }, 370 | { 371 | "type": "text", 372 | "value": ";", 373 | "position": { 374 | "start": { 375 | "line": 7, 376 | "column": 5, 377 | "offset": 60 378 | }, 379 | "end": { 380 | "line": 7, 381 | "column": 6, 382 | "offset": 61 383 | } 384 | } 385 | } 386 | ], 387 | "position": { 388 | "start": { 389 | "line": 7, 390 | "column": 1, 391 | "offset": 56 392 | }, 393 | "end": { 394 | "line": 7, 395 | "column": 9, 396 | "offset": 64 397 | } 398 | }, 399 | "label": "`f`;", 400 | "identifier": "`f`;", 401 | "referenceType": "collapsed" 402 | } 403 | ], 404 | "position": { 405 | "start": { 406 | "line": 1, 407 | "column": 1, 408 | "offset": 0 409 | }, 410 | "end": { 411 | "line": 7, 412 | "column": 9, 413 | "offset": 64 414 | } 415 | } 416 | }, 417 | { 418 | "type": "definition", 419 | "identifier": "`f`", 420 | "label": "`f`", 421 | "title": null, 422 | "url": "alpha", 423 | "position": { 424 | "start": { 425 | "line": 9, 426 | "column": 1, 427 | "offset": 66 428 | }, 429 | "end": { 430 | "line": 9, 431 | "column": 13, 432 | "offset": 78 433 | } 434 | } 435 | }, 436 | { 437 | "type": "definition", 438 | "identifier": ";", 439 | "label": ";", 440 | "title": null, 441 | "url": "bravo", 442 | "position": { 443 | "start": { 444 | "line": 10, 445 | "column": 1, 446 | "offset": 79 447 | }, 448 | "end": { 449 | "line": 10, 450 | "column": 16, 451 | "offset": 94 452 | } 453 | } 454 | }, 455 | { 456 | "type": "definition", 457 | "identifier": "\\;", 458 | "label": ";", 459 | "title": null, 460 | "url": "charlie", 461 | "position": { 462 | "start": { 463 | "line": 11, 464 | "column": 1, 465 | "offset": 95 466 | }, 467 | "end": { 468 | "line": 11, 469 | "column": 14, 470 | "offset": 108 471 | } 472 | } 473 | }, 474 | { 475 | "type": "definition", 476 | "identifier": ";", 477 | "label": ";", 478 | "title": null, 479 | "url": "delta", 480 | "position": { 481 | "start": { 482 | "line": 12, 483 | "column": 1, 484 | "offset": 109 485 | }, 486 | "end": { 487 | "line": 12, 488 | "column": 11, 489 | "offset": 119 490 | } 491 | } 492 | }, 493 | { 494 | "type": "definition", 495 | "identifier": "`f`;", 496 | "label": "`f`;", 497 | "title": null, 498 | "url": "echo", 499 | "position": { 500 | "start": { 501 | "line": 13, 502 | "column": 1, 503 | "offset": 120 504 | }, 505 | "end": { 506 | "line": 13, 507 | "column": 18, 508 | "offset": 137 509 | } 510 | } 511 | }, 512 | { 513 | "type": "definition", 514 | "identifier": "`f`\\;", 515 | "label": "`f`;", 516 | "title": null, 517 | "url": "foxtrot", 518 | "position": { 519 | "start": { 520 | "line": 14, 521 | "column": 1, 522 | "offset": 138 523 | }, 524 | "end": { 525 | "line": 14, 526 | "column": 17, 527 | "offset": 154 528 | } 529 | } 530 | }, 531 | { 532 | "type": "definition", 533 | "identifier": "`f`;", 534 | "label": "`f`;", 535 | "title": null, 536 | "url": "golf", 537 | "position": { 538 | "start": { 539 | "line": 15, 540 | "column": 1, 541 | "offset": 155 542 | }, 543 | "end": { 544 | "line": 15, 545 | "column": 13, 546 | "offset": 167 547 | } 548 | } 549 | } 550 | ], 551 | "position": { 552 | "start": { 553 | "line": 1, 554 | "column": 1, 555 | "offset": 0 556 | }, 557 | "end": { 558 | "line": 16, 559 | "column": 1, 560 | "offset": 168 561 | } 562 | } 563 | } 564 | -------------------------------------------------------------------------------- /test/fixtures/link-reference-with-phrasing.md: -------------------------------------------------------------------------------- 1 | [`f`][] 2 | [;][] 3 | [\;][] 4 | [;][] 5 | [`f`;][] 6 | [`f`\;][] 7 | [`f`;][] 8 | 9 | [`f`]: alpha 10 | [;]: bravo 11 | [\;]: charlie 12 | [;]: delta 13 | [`f`;]: echo 14 | [`f`\;]: foxtrot 15 | [`f`;]: golf 16 | -------------------------------------------------------------------------------- /test/fixtures/link-reference.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Not references, as they’re not defined [a], [b][], [c][d].", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 59, 19 | "offset": 58 20 | } 21 | } 22 | } 23 | ], 24 | "position": { 25 | "start": { 26 | "line": 1, 27 | "column": 1, 28 | "offset": 0 29 | }, 30 | "end": { 31 | "line": 1, 32 | "column": 59, 33 | "offset": 58 34 | } 35 | } 36 | }, 37 | { 38 | "type": "paragraph", 39 | "children": [ 40 | { 41 | "type": "text", 42 | "value": "References! ", 43 | "position": { 44 | "start": { 45 | "line": 3, 46 | "column": 1, 47 | "offset": 60 48 | }, 49 | "end": { 50 | "line": 3, 51 | "column": 13, 52 | "offset": 72 53 | } 54 | } 55 | }, 56 | { 57 | "type": "linkReference", 58 | "children": [ 59 | { 60 | "type": "text", 61 | "value": "e", 62 | "position": { 63 | "start": { 64 | "line": 3, 65 | "column": 14, 66 | "offset": 73 67 | }, 68 | "end": { 69 | "line": 3, 70 | "column": 15, 71 | "offset": 74 72 | } 73 | } 74 | } 75 | ], 76 | "position": { 77 | "start": { 78 | "line": 3, 79 | "column": 13, 80 | "offset": 72 81 | }, 82 | "end": { 83 | "line": 3, 84 | "column": 16, 85 | "offset": 75 86 | } 87 | }, 88 | "label": "e", 89 | "identifier": "e", 90 | "referenceType": "shortcut" 91 | }, 92 | { 93 | "type": "text", 94 | "value": ", ", 95 | "position": { 96 | "start": { 97 | "line": 3, 98 | "column": 16, 99 | "offset": 75 100 | }, 101 | "end": { 102 | "line": 3, 103 | "column": 18, 104 | "offset": 77 105 | } 106 | } 107 | }, 108 | { 109 | "type": "linkReference", 110 | "children": [ 111 | { 112 | "type": "text", 113 | "value": "f", 114 | "position": { 115 | "start": { 116 | "line": 3, 117 | "column": 19, 118 | "offset": 78 119 | }, 120 | "end": { 121 | "line": 3, 122 | "column": 20, 123 | "offset": 79 124 | } 125 | } 126 | } 127 | ], 128 | "position": { 129 | "start": { 130 | "line": 3, 131 | "column": 18, 132 | "offset": 77 133 | }, 134 | "end": { 135 | "line": 3, 136 | "column": 23, 137 | "offset": 82 138 | } 139 | }, 140 | "label": "f", 141 | "identifier": "f", 142 | "referenceType": "collapsed" 143 | }, 144 | { 145 | "type": "text", 146 | "value": ", ", 147 | "position": { 148 | "start": { 149 | "line": 3, 150 | "column": 23, 151 | "offset": 82 152 | }, 153 | "end": { 154 | "line": 3, 155 | "column": 25, 156 | "offset": 84 157 | } 158 | } 159 | }, 160 | { 161 | "type": "linkReference", 162 | "children": [ 163 | { 164 | "type": "text", 165 | "value": "g", 166 | "position": { 167 | "start": { 168 | "line": 3, 169 | "column": 26, 170 | "offset": 85 171 | }, 172 | "end": { 173 | "line": 3, 174 | "column": 27, 175 | "offset": 86 176 | } 177 | } 178 | } 179 | ], 180 | "position": { 181 | "start": { 182 | "line": 3, 183 | "column": 25, 184 | "offset": 84 185 | }, 186 | "end": { 187 | "line": 3, 188 | "column": 31, 189 | "offset": 90 190 | } 191 | }, 192 | "label": "h", 193 | "identifier": "h", 194 | "referenceType": "full" 195 | } 196 | ], 197 | "position": { 198 | "start": { 199 | "line": 3, 200 | "column": 1, 201 | "offset": 60 202 | }, 203 | "end": { 204 | "line": 3, 205 | "column": 31, 206 | "offset": 90 207 | } 208 | } 209 | }, 210 | { 211 | "type": "definition", 212 | "identifier": "e", 213 | "label": "e", 214 | "title": null, 215 | "url": "x", 216 | "position": { 217 | "start": { 218 | "line": 5, 219 | "column": 1, 220 | "offset": 92 221 | }, 222 | "end": { 223 | "line": 5, 224 | "column": 7, 225 | "offset": 98 226 | } 227 | } 228 | }, 229 | { 230 | "type": "definition", 231 | "identifier": "f", 232 | "label": "f", 233 | "title": null, 234 | "url": "y", 235 | "position": { 236 | "start": { 237 | "line": 6, 238 | "column": 1, 239 | "offset": 99 240 | }, 241 | "end": { 242 | "line": 6, 243 | "column": 7, 244 | "offset": 105 245 | } 246 | } 247 | }, 248 | { 249 | "type": "definition", 250 | "identifier": "h", 251 | "label": "h", 252 | "title": null, 253 | "url": "z", 254 | "position": { 255 | "start": { 256 | "line": 7, 257 | "column": 1, 258 | "offset": 106 259 | }, 260 | "end": { 261 | "line": 7, 262 | "column": 7, 263 | "offset": 112 264 | } 265 | } 266 | } 267 | ], 268 | "position": { 269 | "start": { 270 | "line": 1, 271 | "column": 1, 272 | "offset": 0 273 | }, 274 | "end": { 275 | "line": 8, 276 | "column": 1, 277 | "offset": 113 278 | } 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /test/fixtures/link-reference.md: -------------------------------------------------------------------------------- 1 | Not references, as they’re not defined [a], [b][], [c][d]. 2 | 3 | References! [e], [f][], [g][h] 4 | 5 | [e]: x 6 | [f]: y 7 | [h]: z 8 | -------------------------------------------------------------------------------- /test/fixtures/link-resource-eol.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "a ", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 3, 19 | "offset": 2 20 | } 21 | } 22 | }, 23 | { 24 | "type": "link", 25 | "title": null, 26 | "url": "c", 27 | "children": [ 28 | { 29 | "type": "text", 30 | "value": "\nb", 31 | "position": { 32 | "start": { 33 | "line": 1, 34 | "column": 4, 35 | "offset": 3 36 | }, 37 | "end": { 38 | "line": 2, 39 | "column": 2, 40 | "offset": 5 41 | } 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 3, 49 | "offset": 2 50 | }, 51 | "end": { 52 | "line": 2, 53 | "column": 6, 54 | "offset": 9 55 | } 56 | } 57 | }, 58 | { 59 | "type": "text", 60 | "value": " d", 61 | "position": { 62 | "start": { 63 | "line": 2, 64 | "column": 6, 65 | "offset": 9 66 | }, 67 | "end": { 68 | "line": 2, 69 | "column": 8, 70 | "offset": 11 71 | } 72 | } 73 | } 74 | ], 75 | "position": { 76 | "start": { 77 | "line": 1, 78 | "column": 1, 79 | "offset": 0 80 | }, 81 | "end": { 82 | "line": 2, 83 | "column": 8, 84 | "offset": 11 85 | } 86 | } 87 | }, 88 | { 89 | "type": "paragraph", 90 | "children": [ 91 | { 92 | "type": "text", 93 | "value": "a ", 94 | "position": { 95 | "start": { 96 | "line": 4, 97 | "column": 1, 98 | "offset": 13 99 | }, 100 | "end": { 101 | "line": 4, 102 | "column": 3, 103 | "offset": 15 104 | } 105 | } 106 | }, 107 | { 108 | "type": "link", 109 | "title": null, 110 | "url": "c", 111 | "children": [ 112 | { 113 | "type": "text", 114 | "value": "b\n", 115 | "position": { 116 | "start": { 117 | "line": 4, 118 | "column": 4, 119 | "offset": 16 120 | }, 121 | "end": { 122 | "line": 5, 123 | "column": 1, 124 | "offset": 18 125 | } 126 | } 127 | } 128 | ], 129 | "position": { 130 | "start": { 131 | "line": 4, 132 | "column": 3, 133 | "offset": 15 134 | }, 135 | "end": { 136 | "line": 5, 137 | "column": 5, 138 | "offset": 22 139 | } 140 | } 141 | }, 142 | { 143 | "type": "text", 144 | "value": " d", 145 | "position": { 146 | "start": { 147 | "line": 5, 148 | "column": 5, 149 | "offset": 22 150 | }, 151 | "end": { 152 | "line": 5, 153 | "column": 7, 154 | "offset": 24 155 | } 156 | } 157 | } 158 | ], 159 | "position": { 160 | "start": { 161 | "line": 4, 162 | "column": 1, 163 | "offset": 13 164 | }, 165 | "end": { 166 | "line": 5, 167 | "column": 7, 168 | "offset": 24 169 | } 170 | } 171 | }, 172 | { 173 | "type": "paragraph", 174 | "children": [ 175 | { 176 | "type": "text", 177 | "value": "a ", 178 | "position": { 179 | "start": { 180 | "line": 7, 181 | "column": 1, 182 | "offset": 26 183 | }, 184 | "end": { 185 | "line": 7, 186 | "column": 3, 187 | "offset": 28 188 | } 189 | } 190 | }, 191 | { 192 | "type": "link", 193 | "title": null, 194 | "url": "d", 195 | "children": [ 196 | { 197 | "type": "text", 198 | "value": "b\nc", 199 | "position": { 200 | "start": { 201 | "line": 7, 202 | "column": 4, 203 | "offset": 29 204 | }, 205 | "end": { 206 | "line": 8, 207 | "column": 2, 208 | "offset": 32 209 | } 210 | } 211 | } 212 | ], 213 | "position": { 214 | "start": { 215 | "line": 7, 216 | "column": 3, 217 | "offset": 28 218 | }, 219 | "end": { 220 | "line": 8, 221 | "column": 6, 222 | "offset": 36 223 | } 224 | } 225 | }, 226 | { 227 | "type": "text", 228 | "value": " e", 229 | "position": { 230 | "start": { 231 | "line": 8, 232 | "column": 6, 233 | "offset": 36 234 | }, 235 | "end": { 236 | "line": 8, 237 | "column": 8, 238 | "offset": 38 239 | } 240 | } 241 | } 242 | ], 243 | "position": { 244 | "start": { 245 | "line": 7, 246 | "column": 1, 247 | "offset": 26 248 | }, 249 | "end": { 250 | "line": 8, 251 | "column": 8, 252 | "offset": 38 253 | } 254 | } 255 | }, 256 | { 257 | "type": "paragraph", 258 | "children": [ 259 | { 260 | "type": "text", 261 | "value": "a ", 262 | "position": { 263 | "start": { 264 | "line": 10, 265 | "column": 1, 266 | "offset": 40 267 | }, 268 | "end": { 269 | "line": 10, 270 | "column": 3, 271 | "offset": 42 272 | } 273 | } 274 | }, 275 | { 276 | "type": "link", 277 | "title": null, 278 | "url": "c", 279 | "children": [ 280 | { 281 | "type": "text", 282 | "value": "b", 283 | "position": { 284 | "start": { 285 | "line": 10, 286 | "column": 4, 287 | "offset": 43 288 | }, 289 | "end": { 290 | "line": 10, 291 | "column": 5, 292 | "offset": 44 293 | } 294 | } 295 | } 296 | ], 297 | "position": { 298 | "start": { 299 | "line": 10, 300 | "column": 3, 301 | "offset": 42 302 | }, 303 | "end": { 304 | "line": 11, 305 | "column": 3, 306 | "offset": 49 307 | } 308 | } 309 | }, 310 | { 311 | "type": "text", 312 | "value": " d", 313 | "position": { 314 | "start": { 315 | "line": 11, 316 | "column": 3, 317 | "offset": 49 318 | }, 319 | "end": { 320 | "line": 11, 321 | "column": 5, 322 | "offset": 51 323 | } 324 | } 325 | } 326 | ], 327 | "position": { 328 | "start": { 329 | "line": 10, 330 | "column": 1, 331 | "offset": 40 332 | }, 333 | "end": { 334 | "line": 11, 335 | "column": 5, 336 | "offset": 51 337 | } 338 | } 339 | }, 340 | { 341 | "type": "paragraph", 342 | "children": [ 343 | { 344 | "type": "text", 345 | "value": "a ", 346 | "position": { 347 | "start": { 348 | "line": 13, 349 | "column": 1, 350 | "offset": 53 351 | }, 352 | "end": { 353 | "line": 13, 354 | "column": 3, 355 | "offset": 55 356 | } 357 | } 358 | }, 359 | { 360 | "type": "link", 361 | "title": null, 362 | "url": "c", 363 | "children": [ 364 | { 365 | "type": "text", 366 | "value": "b", 367 | "position": { 368 | "start": { 369 | "line": 13, 370 | "column": 4, 371 | "offset": 56 372 | }, 373 | "end": { 374 | "line": 13, 375 | "column": 5, 376 | "offset": 57 377 | } 378 | } 379 | } 380 | ], 381 | "position": { 382 | "start": { 383 | "line": 13, 384 | "column": 3, 385 | "offset": 55 386 | }, 387 | "end": { 388 | "line": 14, 389 | "column": 2, 390 | "offset": 62 391 | } 392 | } 393 | }, 394 | { 395 | "type": "text", 396 | "value": " d", 397 | "position": { 398 | "start": { 399 | "line": 14, 400 | "column": 2, 401 | "offset": 62 402 | }, 403 | "end": { 404 | "line": 14, 405 | "column": 4, 406 | "offset": 64 407 | } 408 | } 409 | } 410 | ], 411 | "position": { 412 | "start": { 413 | "line": 13, 414 | "column": 1, 415 | "offset": 53 416 | }, 417 | "end": { 418 | "line": 14, 419 | "column": 4, 420 | "offset": 64 421 | } 422 | } 423 | }, 424 | { 425 | "type": "paragraph", 426 | "children": [ 427 | { 428 | "type": "text", 429 | "value": "a ", 430 | "position": { 431 | "start": { 432 | "line": 16, 433 | "column": 1, 434 | "offset": 66 435 | }, 436 | "end": { 437 | "line": 16, 438 | "column": 3, 439 | "offset": 68 440 | } 441 | } 442 | }, 443 | { 444 | "type": "link", 445 | "title": "d", 446 | "url": "c", 447 | "children": [ 448 | { 449 | "type": "text", 450 | "value": "b", 451 | "position": { 452 | "start": { 453 | "line": 16, 454 | "column": 4, 455 | "offset": 69 456 | }, 457 | "end": { 458 | "line": 16, 459 | "column": 5, 460 | "offset": 70 461 | } 462 | } 463 | } 464 | ], 465 | "position": { 466 | "start": { 467 | "line": 16, 468 | "column": 3, 469 | "offset": 68 470 | }, 471 | "end": { 472 | "line": 17, 473 | "column": 5, 474 | "offset": 78 475 | } 476 | } 477 | }, 478 | { 479 | "type": "text", 480 | "value": " e", 481 | "position": { 482 | "start": { 483 | "line": 17, 484 | "column": 5, 485 | "offset": 78 486 | }, 487 | "end": { 488 | "line": 17, 489 | "column": 7, 490 | "offset": 80 491 | } 492 | } 493 | } 494 | ], 495 | "position": { 496 | "start": { 497 | "line": 16, 498 | "column": 1, 499 | "offset": 66 500 | }, 501 | "end": { 502 | "line": 17, 503 | "column": 7, 504 | "offset": 80 505 | } 506 | } 507 | }, 508 | { 509 | "type": "paragraph", 510 | "children": [ 511 | { 512 | "type": "text", 513 | "value": "a ", 514 | "position": { 515 | "start": { 516 | "line": 19, 517 | "column": 1, 518 | "offset": 82 519 | }, 520 | "end": { 521 | "line": 19, 522 | "column": 3, 523 | "offset": 84 524 | } 525 | } 526 | }, 527 | { 528 | "type": "link", 529 | "title": "d\ne", 530 | "url": "c", 531 | "children": [ 532 | { 533 | "type": "text", 534 | "value": "b", 535 | "position": { 536 | "start": { 537 | "line": 19, 538 | "column": 4, 539 | "offset": 85 540 | }, 541 | "end": { 542 | "line": 19, 543 | "column": 5, 544 | "offset": 86 545 | } 546 | } 547 | } 548 | ], 549 | "position": { 550 | "start": { 551 | "line": 19, 552 | "column": 3, 553 | "offset": 84 554 | }, 555 | "end": { 556 | "line": 20, 557 | "column": 4, 558 | "offset": 96 559 | } 560 | } 561 | }, 562 | { 563 | "type": "text", 564 | "value": " f", 565 | "position": { 566 | "start": { 567 | "line": 20, 568 | "column": 4, 569 | "offset": 96 570 | }, 571 | "end": { 572 | "line": 20, 573 | "column": 6, 574 | "offset": 98 575 | } 576 | } 577 | } 578 | ], 579 | "position": { 580 | "start": { 581 | "line": 19, 582 | "column": 1, 583 | "offset": 82 584 | }, 585 | "end": { 586 | "line": 20, 587 | "column": 6, 588 | "offset": 98 589 | } 590 | } 591 | }, 592 | { 593 | "type": "paragraph", 594 | "children": [ 595 | { 596 | "type": "text", 597 | "value": "a ", 598 | "position": { 599 | "start": { 600 | "line": 22, 601 | "column": 1, 602 | "offset": 100 603 | }, 604 | "end": { 605 | "line": 22, 606 | "column": 3, 607 | "offset": 102 608 | } 609 | } 610 | }, 611 | { 612 | "type": "link", 613 | "title": "d\ne\nf", 614 | "url": "c", 615 | "children": [ 616 | { 617 | "type": "text", 618 | "value": "b", 619 | "position": { 620 | "start": { 621 | "line": 22, 622 | "column": 4, 623 | "offset": 103 624 | }, 625 | "end": { 626 | "line": 22, 627 | "column": 5, 628 | "offset": 104 629 | } 630 | } 631 | } 632 | ], 633 | "position": { 634 | "start": { 635 | "line": 22, 636 | "column": 3, 637 | "offset": 102 638 | }, 639 | "end": { 640 | "line": 24, 641 | "column": 4, 642 | "offset": 116 643 | } 644 | } 645 | }, 646 | { 647 | "type": "text", 648 | "value": " g", 649 | "position": { 650 | "start": { 651 | "line": 24, 652 | "column": 4, 653 | "offset": 116 654 | }, 655 | "end": { 656 | "line": 24, 657 | "column": 6, 658 | "offset": 118 659 | } 660 | } 661 | } 662 | ], 663 | "position": { 664 | "start": { 665 | "line": 22, 666 | "column": 1, 667 | "offset": 100 668 | }, 669 | "end": { 670 | "line": 24, 671 | "column": 6, 672 | "offset": 118 673 | } 674 | } 675 | } 676 | ], 677 | "position": { 678 | "start": { 679 | "line": 1, 680 | "column": 1, 681 | "offset": 0 682 | }, 683 | "end": { 684 | "line": 25, 685 | "column": 1, 686 | "offset": 119 687 | } 688 | } 689 | } 690 | -------------------------------------------------------------------------------- /test/fixtures/link-resource-eol.md: -------------------------------------------------------------------------------- 1 | a [ 2 | b](c) d 3 | 4 | a [b 5 | ](c) d 6 | 7 | a [b 8 | c](d) e 9 | 10 | a [b]( 11 | c) d 12 | 13 | a [b](c 14 | ) d 15 | 16 | a [b](c 17 | "d") e 18 | 19 | a [b](c "d 20 | e") f 21 | 22 | a [b](c "d 23 | e 24 | f") g 25 | -------------------------------------------------------------------------------- /test/fixtures/link-resource.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Resources: ", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 12, 19 | "offset": 11 20 | } 21 | } 22 | }, 23 | { 24 | "type": "link", 25 | "title": null, 26 | "url": "b", 27 | "children": [ 28 | { 29 | "type": "text", 30 | "value": "a", 31 | "position": { 32 | "start": { 33 | "line": 1, 34 | "column": 13, 35 | "offset": 12 36 | }, 37 | "end": { 38 | "line": 1, 39 | "column": 14, 40 | "offset": 13 41 | } 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 12, 49 | "offset": 11 50 | }, 51 | "end": { 52 | "line": 1, 53 | "column": 18, 54 | "offset": 17 55 | } 56 | } 57 | }, 58 | { 59 | "type": "text", 60 | "value": ", ", 61 | "position": { 62 | "start": { 63 | "line": 1, 64 | "column": 18, 65 | "offset": 17 66 | }, 67 | "end": { 68 | "line": 1, 69 | "column": 20, 70 | "offset": 19 71 | } 72 | } 73 | }, 74 | { 75 | "type": "link", 76 | "title": "e", 77 | "url": "d", 78 | "children": [ 79 | { 80 | "type": "text", 81 | "value": "c", 82 | "position": { 83 | "start": { 84 | "line": 1, 85 | "column": 21, 86 | "offset": 20 87 | }, 88 | "end": { 89 | "line": 1, 90 | "column": 22, 91 | "offset": 21 92 | } 93 | } 94 | } 95 | ], 96 | "position": { 97 | "start": { 98 | "line": 1, 99 | "column": 20, 100 | "offset": 19 101 | }, 102 | "end": { 103 | "line": 1, 104 | "column": 30, 105 | "offset": 29 106 | } 107 | } 108 | }, 109 | { 110 | "type": "text", 111 | "value": ", ", 112 | "position": { 113 | "start": { 114 | "line": 1, 115 | "column": 30, 116 | "offset": 29 117 | }, 118 | "end": { 119 | "line": 1, 120 | "column": 32, 121 | "offset": 31 122 | } 123 | } 124 | }, 125 | { 126 | "type": "link", 127 | "title": "h", 128 | "url": "g", 129 | "children": [ 130 | { 131 | "type": "text", 132 | "value": "f", 133 | "position": { 134 | "start": { 135 | "line": 1, 136 | "column": 33, 137 | "offset": 32 138 | }, 139 | "end": { 140 | "line": 1, 141 | "column": 34, 142 | "offset": 33 143 | } 144 | } 145 | } 146 | ], 147 | "position": { 148 | "start": { 149 | "line": 1, 150 | "column": 32, 151 | "offset": 31 152 | }, 153 | "end": { 154 | "line": 1, 155 | "column": 42, 156 | "offset": 41 157 | } 158 | } 159 | }, 160 | { 161 | "type": "text", 162 | "value": ", ", 163 | "position": { 164 | "start": { 165 | "line": 1, 166 | "column": 42, 167 | "offset": 41 168 | }, 169 | "end": { 170 | "line": 1, 171 | "column": 44, 172 | "offset": 43 173 | } 174 | } 175 | }, 176 | { 177 | "type": "link", 178 | "title": "k", 179 | "url": "j", 180 | "children": [ 181 | { 182 | "type": "text", 183 | "value": "i", 184 | "position": { 185 | "start": { 186 | "line": 1, 187 | "column": 45, 188 | "offset": 44 189 | }, 190 | "end": { 191 | "line": 1, 192 | "column": 46, 193 | "offset": 45 194 | } 195 | } 196 | } 197 | ], 198 | "position": { 199 | "start": { 200 | "line": 1, 201 | "column": 44, 202 | "offset": 43 203 | }, 204 | "end": { 205 | "line": 1, 206 | "column": 54, 207 | "offset": 53 208 | } 209 | } 210 | }, 211 | { 212 | "type": "text", 213 | "value": ", ", 214 | "position": { 215 | "start": { 216 | "line": 1, 217 | "column": 54, 218 | "offset": 53 219 | }, 220 | "end": { 221 | "line": 1, 222 | "column": 56, 223 | "offset": 55 224 | } 225 | } 226 | }, 227 | { 228 | "type": "link", 229 | "title": null, 230 | "url": "m", 231 | "children": [ 232 | { 233 | "type": "text", 234 | "value": "l", 235 | "position": { 236 | "start": { 237 | "line": 1, 238 | "column": 57, 239 | "offset": 56 240 | }, 241 | "end": { 242 | "line": 1, 243 | "column": 58, 244 | "offset": 57 245 | } 246 | } 247 | } 248 | ], 249 | "position": { 250 | "start": { 251 | "line": 1, 252 | "column": 56, 253 | "offset": 55 254 | }, 255 | "end": { 256 | "line": 1, 257 | "column": 64, 258 | "offset": 63 259 | } 260 | } 261 | }, 262 | { 263 | "type": "text", 264 | "value": ".", 265 | "position": { 266 | "start": { 267 | "line": 1, 268 | "column": 64, 269 | "offset": 63 270 | }, 271 | "end": { 272 | "line": 1, 273 | "column": 65, 274 | "offset": 64 275 | } 276 | } 277 | } 278 | ], 279 | "position": { 280 | "start": { 281 | "line": 1, 282 | "column": 1, 283 | "offset": 0 284 | }, 285 | "end": { 286 | "line": 1, 287 | "column": 65, 288 | "offset": 64 289 | } 290 | } 291 | }, 292 | { 293 | "type": "paragraph", 294 | "children": [ 295 | { 296 | "type": "text", 297 | "value": "“Content” in images: ", 298 | "position": { 299 | "start": { 300 | "line": 3, 301 | "column": 1, 302 | "offset": 66 303 | }, 304 | "end": { 305 | "line": 3, 306 | "column": 22, 307 | "offset": 87 308 | } 309 | } 310 | }, 311 | { 312 | "type": "link", 313 | "title": null, 314 | "url": "d", 315 | "children": [ 316 | { 317 | "type": "text", 318 | "value": "a ", 319 | "position": { 320 | "start": { 321 | "line": 3, 322 | "column": 23, 323 | "offset": 88 324 | }, 325 | "end": { 326 | "line": 3, 327 | "column": 25, 328 | "offset": 90 329 | } 330 | } 331 | }, 332 | { 333 | "type": "emphasis", 334 | "children": [ 335 | { 336 | "type": "text", 337 | "value": "b", 338 | "position": { 339 | "start": { 340 | "line": 3, 341 | "column": 26, 342 | "offset": 91 343 | }, 344 | "end": { 345 | "line": 3, 346 | "column": 27, 347 | "offset": 92 348 | } 349 | } 350 | } 351 | ], 352 | "position": { 353 | "start": { 354 | "line": 3, 355 | "column": 25, 356 | "offset": 90 357 | }, 358 | "end": { 359 | "line": 3, 360 | "column": 28, 361 | "offset": 93 362 | } 363 | } 364 | }, 365 | { 366 | "type": "text", 367 | "value": " ", 368 | "position": { 369 | "start": { 370 | "line": 3, 371 | "column": 28, 372 | "offset": 93 373 | }, 374 | "end": { 375 | "line": 3, 376 | "column": 29, 377 | "offset": 94 378 | } 379 | } 380 | }, 381 | { 382 | "type": "inlineCode", 383 | "value": "c", 384 | "position": { 385 | "start": { 386 | "line": 3, 387 | "column": 29, 388 | "offset": 94 389 | }, 390 | "end": { 391 | "line": 3, 392 | "column": 32, 393 | "offset": 97 394 | } 395 | } 396 | } 397 | ], 398 | "position": { 399 | "start": { 400 | "line": 3, 401 | "column": 22, 402 | "offset": 87 403 | }, 404 | "end": { 405 | "line": 3, 406 | "column": 36, 407 | "offset": 101 408 | } 409 | } 410 | }, 411 | { 412 | "type": "text", 413 | "value": ".", 414 | "position": { 415 | "start": { 416 | "line": 3, 417 | "column": 36, 418 | "offset": 101 419 | }, 420 | "end": { 421 | "line": 3, 422 | "column": 37, 423 | "offset": 102 424 | } 425 | } 426 | } 427 | ], 428 | "position": { 429 | "start": { 430 | "line": 3, 431 | "column": 1, 432 | "offset": 66 433 | }, 434 | "end": { 435 | "line": 3, 436 | "column": 37, 437 | "offset": 102 438 | } 439 | } 440 | }, 441 | { 442 | "type": "paragraph", 443 | "children": [ 444 | { 445 | "type": "text", 446 | "value": "Empty: ", 447 | "position": { 448 | "start": { 449 | "line": 5, 450 | "column": 1, 451 | "offset": 104 452 | }, 453 | "end": { 454 | "line": 5, 455 | "column": 8, 456 | "offset": 111 457 | } 458 | } 459 | }, 460 | { 461 | "type": "link", 462 | "title": null, 463 | "url": "", 464 | "children": [], 465 | "position": { 466 | "start": { 467 | "line": 5, 468 | "column": 8, 469 | "offset": 111 470 | }, 471 | "end": { 472 | "line": 5, 473 | "column": 12, 474 | "offset": 115 475 | } 476 | } 477 | }, 478 | { 479 | "type": "text", 480 | "value": ".", 481 | "position": { 482 | "start": { 483 | "line": 5, 484 | "column": 12, 485 | "offset": 115 486 | }, 487 | "end": { 488 | "line": 5, 489 | "column": 13, 490 | "offset": 116 491 | } 492 | } 493 | } 494 | ], 495 | "position": { 496 | "start": { 497 | "line": 5, 498 | "column": 1, 499 | "offset": 104 500 | }, 501 | "end": { 502 | "line": 5, 503 | "column": 13, 504 | "offset": 116 505 | } 506 | } 507 | }, 508 | { 509 | "type": "paragraph", 510 | "children": [ 511 | { 512 | "type": "text", 513 | "value": "Character references and escapes:\n", 514 | "position": { 515 | "start": { 516 | "line": 7, 517 | "column": 1, 518 | "offset": 118 519 | }, 520 | "end": { 521 | "line": 8, 522 | "column": 1, 523 | "offset": 152 524 | } 525 | } 526 | }, 527 | { 528 | "type": "link", 529 | "title": "i*j\tk&l", 530 | "url": "e*f\tg&h", 531 | "children": [ 532 | { 533 | "type": "text", 534 | "value": "a*b\tc&d", 535 | "position": { 536 | "start": { 537 | "line": 8, 538 | "column": 2, 539 | "offset": 153 540 | }, 541 | "end": { 542 | "line": 8, 543 | "column": 17, 544 | "offset": 168 545 | } 546 | } 547 | } 548 | ], 549 | "position": { 550 | "start": { 551 | "line": 8, 552 | "column": 1, 553 | "offset": 152 554 | }, 555 | "end": { 556 | "line": 8, 557 | "column": 53, 558 | "offset": 204 559 | } 560 | } 561 | } 562 | ], 563 | "position": { 564 | "start": { 565 | "line": 7, 566 | "column": 1, 567 | "offset": 118 568 | }, 569 | "end": { 570 | "line": 8, 571 | "column": 53, 572 | "offset": 204 573 | } 574 | } 575 | } 576 | ], 577 | "position": { 578 | "start": { 579 | "line": 1, 580 | "column": 1, 581 | "offset": 0 582 | }, 583 | "end": { 584 | "line": 8, 585 | "column": 53, 586 | "offset": 204 587 | } 588 | } 589 | } 590 | -------------------------------------------------------------------------------- /test/fixtures/link-resource.md: -------------------------------------------------------------------------------- 1 | Resources: [a](b), [c](d "e"), [f](g 'h'), [i](j (k)), [l](). 2 | 3 | “Content” in images: [a *b* `c`](d). 4 | 5 | Empty: [](). 6 | 7 | Character references and escapes: 8 | [a\*b c&d](e\*f g&h "i\*j k&l") -------------------------------------------------------------------------------- /test/fixtures/list.md: -------------------------------------------------------------------------------- 1 | 1. a 2 | 1. b 3 | 1. c 4 | 5 | * d 6 | 7 | 1. e 8 | ```js 9 | 10 | ``` 11 | f 12 | 2. g 13 | h 14 | 15 | - i 16 | 17 | j 18 | 19 | + k 20 | 21 | + l 22 | 23 | 9. m 24 | 10. n 25 | 26 | * 27 | o 28 | * 29 | ~~~p 30 | 31 | ~~~ 32 | 33 | - q 34 | 35 | r 36 | - 37 | s 38 | - t 39 | 40 | 41 | u 42 | - 43 | 44 | 45 | - v 46 | 47 | > + w 48 | > 49 | > + x 50 | 51 | * y 52 | 53 | 1. z 54 | 55 | 1. a 56 | 57 | - 1) b 58 | 59 | 2) c 60 | -------------------------------------------------------------------------------- /test/fixtures/paragraph.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "A short paragraph.", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 19, 19 | "offset": 18 20 | } 21 | } 22 | } 23 | ], 24 | "position": { 25 | "start": { 26 | "line": 1, 27 | "column": 1, 28 | "offset": 0 29 | }, 30 | "end": { 31 | "line": 1, 32 | "column": 19, 33 | "offset": 18 34 | } 35 | } 36 | }, 37 | { 38 | "type": "paragraph", 39 | "children": [ 40 | { 41 | "type": "text", 42 | "value": "A\nlonger paragraph.", 43 | "position": { 44 | "start": { 45 | "line": 3, 46 | "column": 1, 47 | "offset": 20 48 | }, 49 | "end": { 50 | "line": 4, 51 | "column": 18, 52 | "offset": 39 53 | } 54 | } 55 | } 56 | ], 57 | "position": { 58 | "start": { 59 | "line": 3, 60 | "column": 1, 61 | "offset": 20 62 | }, 63 | "end": { 64 | "line": 4, 65 | "column": 18, 66 | "offset": 39 67 | } 68 | } 69 | }, 70 | { 71 | "type": "paragraph", 72 | "children": [ 73 | { 74 | "type": "text", 75 | "value": "A couple blank lines.", 76 | "position": { 77 | "start": { 78 | "line": 7, 79 | "column": 1, 80 | "offset": 42 81 | }, 82 | "end": { 83 | "line": 7, 84 | "column": 22, 85 | "offset": 63 86 | } 87 | } 88 | } 89 | ], 90 | "position": { 91 | "start": { 92 | "line": 7, 93 | "column": 1, 94 | "offset": 42 95 | }, 96 | "end": { 97 | "line": 7, 98 | "column": 22, 99 | "offset": 63 100 | } 101 | } 102 | }, 103 | { 104 | "type": "paragraph", 105 | "children": [ 106 | { 107 | "type": "text", 108 | "value": "Lots of blank lines.", 109 | "position": { 110 | "start": { 111 | "line": 11, 112 | "column": 1, 113 | "offset": 67 114 | }, 115 | "end": { 116 | "line": 11, 117 | "column": 21, 118 | "offset": 87 119 | } 120 | } 121 | } 122 | ], 123 | "position": { 124 | "start": { 125 | "line": 11, 126 | "column": 1, 127 | "offset": 67 128 | }, 129 | "end": { 130 | "line": 11, 131 | "column": 21, 132 | "offset": 87 133 | } 134 | } 135 | } 136 | ], 137 | "position": { 138 | "start": { 139 | "line": 1, 140 | "column": 1, 141 | "offset": 0 142 | }, 143 | "end": { 144 | "line": 12, 145 | "column": 1, 146 | "offset": 88 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /test/fixtures/paragraph.md: -------------------------------------------------------------------------------- 1 | A short paragraph. 2 | 3 | A 4 | longer paragraph. 5 | 6 | 7 | A couple blank lines. 8 | 9 | 10 | 11 | Lots of blank lines. 12 | -------------------------------------------------------------------------------- /test/fixtures/thematic-break.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "thematicBreak", 6 | "position": { 7 | "start": { 8 | "line": 1, 9 | "column": 1, 10 | "offset": 0 11 | }, 12 | "end": { 13 | "line": 1, 14 | "column": 4, 15 | "offset": 3 16 | } 17 | } 18 | }, 19 | { 20 | "type": "thematicBreak", 21 | "position": { 22 | "start": { 23 | "line": 3, 24 | "column": 1, 25 | "offset": 5 26 | }, 27 | "end": { 28 | "line": 3, 29 | "column": 4, 30 | "offset": 8 31 | } 32 | } 33 | }, 34 | { 35 | "type": "paragraph", 36 | "children": [ 37 | { 38 | "type": "text", 39 | "value": "+++", 40 | "position": { 41 | "start": { 42 | "line": 5, 43 | "column": 1, 44 | "offset": 10 45 | }, 46 | "end": { 47 | "line": 5, 48 | "column": 4, 49 | "offset": 13 50 | } 51 | } 52 | } 53 | ], 54 | "position": { 55 | "start": { 56 | "line": 5, 57 | "column": 1, 58 | "offset": 10 59 | }, 60 | "end": { 61 | "line": 5, 62 | "column": 4, 63 | "offset": 13 64 | } 65 | } 66 | }, 67 | { 68 | "type": "thematicBreak", 69 | "position": { 70 | "start": { 71 | "line": 7, 72 | "column": 1, 73 | "offset": 15 74 | }, 75 | "end": { 76 | "line": 7, 77 | "column": 6, 78 | "offset": 20 79 | } 80 | } 81 | }, 82 | { 83 | "type": "paragraph", 84 | "children": [ 85 | { 86 | "type": "text", 87 | "value": "++ ++ ++", 88 | "position": { 89 | "start": { 90 | "line": 9, 91 | "column": 1, 92 | "offset": 22 93 | }, 94 | "end": { 95 | "line": 9, 96 | "column": 9, 97 | "offset": 30 98 | } 99 | } 100 | } 101 | ], 102 | "position": { 103 | "start": { 104 | "line": 9, 105 | "column": 1, 106 | "offset": 22 107 | }, 108 | "end": { 109 | "line": 9, 110 | "column": 9, 111 | "offset": 30 112 | } 113 | } 114 | }, 115 | { 116 | "type": "thematicBreak", 117 | "position": { 118 | "start": { 119 | "line": 11, 120 | "column": 1, 121 | "offset": 32 122 | }, 123 | "end": { 124 | "line": 11, 125 | "column": 4, 126 | "offset": 35 127 | } 128 | } 129 | }, 130 | { 131 | "type": "paragraph", 132 | "children": [ 133 | { 134 | "type": "text", 135 | "value": "-+-", 136 | "position": { 137 | "start": { 138 | "line": 13, 139 | "column": 1, 140 | "offset": 37 141 | }, 142 | "end": { 143 | "line": 13, 144 | "column": 4, 145 | "offset": 40 146 | } 147 | } 148 | } 149 | ], 150 | "position": { 151 | "start": { 152 | "line": 13, 153 | "column": 1, 154 | "offset": 37 155 | }, 156 | "end": { 157 | "line": 13, 158 | "column": 4, 159 | "offset": 40 160 | } 161 | } 162 | } 163 | ], 164 | "position": { 165 | "start": { 166 | "line": 1, 167 | "column": 1, 168 | "offset": 0 169 | }, 170 | "end": { 171 | "line": 14, 172 | "column": 1, 173 | "offset": 41 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /test/fixtures/thematic-break.md: -------------------------------------------------------------------------------- 1 | *** 2 | 3 | --- 4 | 5 | +++ 6 | 7 | - - - 8 | 9 | ++ ++ ++ 10 | 11 | ___ 12 | 13 | -+- 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "checkJs": true, 4 | "customConditions": ["development"], 5 | "declaration": true, 6 | "declarationMap": true, 7 | "emitDeclarationOnly": true, 8 | "exactOptionalPropertyTypes": true, 9 | "lib": ["es2022"], 10 | "module": "node16", 11 | "strict": true, 12 | "target": "es2022" 13 | }, 14 | "exclude": ["coverage/", "lib/", "node_modules/", "index.js"], 15 | "include": ["**/*.js", "dev/lib/types.d.ts", "dev/index.d.ts"] 16 | } 17 | --------------------------------------------------------------------------------