markdown_links.ts

Links and headings in rendered markdown, for MarkdownPreview and the markdown view's drawer — pure functions over mdz's parsed nodes, with no app state, plus the one DOM query matching links to their rendered anchors.

A link in a file resolves against the file's path, the way a repository host reads it: ./x.md, ../y/z.md, and x.md against the file's directory, and a root-relative /docs/x.md against the root of the open directory holding the file (the workspace, which is usually the repository). Whether the result exists is the file index's call (MarkdownLinkIndex), and what the index can't see is unknown, never broken.

view source

Declarations
#

21 declarations

FILE_INDEX_IGNORED_DIR_NAMES
#

markdown_links.ts view source

ReadonlySet<string>

type ReadonlySet<string>

import {FILE_INDEX_IGNORED_DIR_NAMES} from '@fuzdev/zzz/markdown_links.js';

Directory names the file index never enters, wherever they appear under a root — the backend filer's default ignores (DEFAULT_IGNORED_DIRS in crates/zzz_server/src/filer.rs, which a test holds this to). A link into one is skipped, not broken.

FILE_INDEX_TEMP_FILE_PREFIX
#

markdown_links.ts view source

".zzz-tmp-" import {FILE_INDEX_TEMP_FILE_PREFIX} from '@fuzdev/zzz/markdown_links.js';

The prefix of the backend's staging files, which the index never lists (TEMP_FILE_PREFIX in crates/zzz_server/src/scoped_fs.rs, which a test holds this to).

MARKDOWN_DIRECTORY_INDEX_NAMES
#

markdown_links.ts view source

readonly string[] import {MARKDOWN_DIRECTORY_INDEX_NAMES} from '@fuzdev/zzz/markdown_links.js';

The names a folder link opens, first found wins — a repository host shows the README.

MarkdownHeading
#

markdown_links.ts view source

MarkdownHeading import type {MarkdownHeading} from '@fuzdev/zzz/markdown_links.js';

A heading in a markdown document, for an outline.

level

type 6 | 2 | 1 | 4 | 3 | 5

id

The slug a #fragment names it by — '' when its text has none.

type string

text

type string

start

Where its source starts, a UTF-16 offset into the document.

type number

MarkdownLink
#

MarkdownLinkIndex
#

markdown_links.ts view source

MarkdownLinkIndex import type {MarkdownLinkIndex} from '@fuzdev/zzz/markdown_links.js';

What the file index knows — the files and folders under its roots — for telling a link's target exists, is missing, or is out of sight.

has_file

Whether a file is indexed at path.

type (path: string): boolean

path

type string
returns boolean

has_directory

Whether an indexed file sits somewhere under path, a directory with a trailing /.

type (path: string): boolean

path

type string
returns boolean

roots

The directories the index covers, each with a trailing /.

type readonly string[]

readonly

MarkdownLinkMark
#

markdown_links.ts view source

MarkdownLinkMark

type "broken" | "unknown"

import type {MarkdownLinkMark} from '@fuzdev/zzz/markdown_links.js';

How the preview marks a link: broken when the index says its target is missing, unknown when the index can't see where it points.

MarkdownLinkStatus
#

markdown_links.ts view source

MarkdownLinkStatus

type "file" | "directory" | "broken" | "outside" | "skipped" | "root_relative"

import type {MarkdownLinkStatus} from '@fuzdev/zzz/markdown_links.js';

How a path link stands against the file index:

  • file / directory — it names an indexed file, or a folder holding one
  • broken — it's inside a root the index covers, where the index would list it, yet nothing is there
  • the index can't say (see MarkdownLinkMark's unknown):
    • outside — outside every root the index covers
    • skipped — inside a folder the index never enters (FILE_INDEX_IGNORED_DIR_NAMES)
    • root_relative — written /… and not found from the workspace's root, which may not be the repository's

MarkdownLinkTarget
#

markdown_links.ts view source

MarkdownLinkTarget

type { kind: "external"; href: string; } | { kind: "fragment"; fragment: string; } | { kind: "path"; path: string; directory: boolean; fragment: string | null; root_relative: boolean; } | { kind: "inert"; }

import type {MarkdownLinkTarget} from '@fuzdev/zzz/markdown_links.js';

Where a link in a markdown file leads:

  • external — an http: or https: URL, left to the browser
  • fragment — a heading in the same document (#id, decoded)
  • path — an absolute path on disk, with directory when the link names a folder (a trailing /, or a last segment of . or ..), its decoded #fragment if any, and root_relative when it was written /…
  • inert — nothing to follow: empty, query-only, another scheme, protocol-relative, malformed, climbing past its root, or relative with no file to resolve against

query_markdown_link_anchors
#

resolve_markdown_link
#

ResolveMarkdownLinkOptions
#

markdown_links.ts view source

ResolveMarkdownLinkOptions import type {ResolveMarkdownLinkOptions} from '@fuzdev/zzz/markdown_links.js';

file_path?

The absolute path of the file the link is in — without it, every path link is inert.

type string | null

root_dir?

The directory (with a trailing /) a root-relative link resolves against — see to_root_dir. Without it, root-relative links are inert.

type string | null

to_directory_readme_path
#

markdown_links.ts view source

(dir_path: string, index: MarkdownLinkIndex): string | null import {to_directory_readme_path} from '@fuzdev/zzz/markdown_links.js';

The README a link to the folder at dir_path opens, or null when the index has none there (see MARKDOWN_DIRECTORY_INDEX_NAMES).

dir_path

the folder, with a trailing /

type string

index

what the file index knows

returns

string | null

to_markdown_headings
#

markdown_links.ts view source

(nodes: readonly MdzNode[]): MarkdownHeading[] import {to_markdown_headings} from '@fuzdev/zzz/markdown_links.js';

The document's headings in rendered order, those in blockquotes included — the ith is the preview's ith h1–h6.

nodes

the document, parsed by mdz_parse

type readonly MdzNode[]

returns

MarkdownHeading[]

to_markdown_link_mark
#

to_markdown_link_status
#

to_markdown_link_title
#

to_markdown_links
#

to_mdz_plain_text
#

markdown_links.ts view source

(nodes: readonly MdzNode[]): string import {to_mdz_plain_text} from '@fuzdev/zzz/markdown_links.js';

The plain text of nodes, formatting dropped.

nodes

type readonly MdzNode[]

returns

string

to_root_dir
#

markdown_links.ts view source

(path: string, roots: readonly string[]): string | null import {to_root_dir} from '@fuzdev/zzz/markdown_links.js';

The innermost of roots (directories with a trailing /) holding path, or null when none does — the directory a root-relative link in the file at path resolves against.

path

an absolute path

type string

roots

the open directories, each with a trailing /

type readonly string[]

returns

string | null

ToMarkdownLinksOptions
#

markdown_links.ts view source

ToMarkdownLinksOptions import type {ToMarkdownLinksOptions} from '@fuzdev/zzz/markdown_links.js';

file_path?

The absolute path of the document's file — without it, path links are inert.

type string | null

index?

What the file index knows; without it, nothing gets a status.

type MarkdownLinkIndex | null

Imported by
#