Namespace: print

Marked. print

Print feature handling

Source:
print.js

Methods


<static> addLogoStyles()

Add CSS styles for logo sizing in headers/footers

Source:
print.js

<static> addPaddingForLastPage(pageHeight, currentPage)

Add padding to the last page to ensure proper scroll positioning

Parameters:
Name Type Description
pageHeight number

The page height

currentPage number

The current page index

Source:
print.js
Returns:

Updated document height

Type
number

<static> addScrollBehaviorOverride()

Add CSS override to disable scroll-behavior during PDF export This prevents pagination issues where smooth scrolling causes content to be captured at the wrong scroll position

Source:
print.js

<static> adjustHeaderFooterHeight()

Dynamically adjust header/footer height based on logo dimensions

Source:
print.js

<static> buildHeadingHierarchyCache(pages)

Build heading hierarchy cache for all pages during pagination

Parameters:
Name Type Description
pages Array

Array of page elements from pagination

Source:
print.js

<static> checkIfHeadingIsOrphaned(headingElement, pageEnd, contentAreaHeight)

Check if a heading is orphaned (no content below it on the same page)

Parameters:
Name Type Description
headingElement Element

The heading element to check

pageEnd number

The end position of the current page

contentAreaHeight number

The height of the content area

Source:
print.js
Returns:

True if the heading is orphaned

Type
boolean

<static> clearHeadingHierarchyCache()

Clear the heading hierarchy cache

Source:
print.js

<static> createFootnoteContainer(pageFootnotes)

Create a single footnote container

Parameters:
Name Type Description
pageFootnotes Array

Array of footnotes for this page

Source:
print.js
Returns:

The footnote container element

Type
Element

<static> createFootnoteContainers(footnotes, contentAreaHeight)

Create footnote containers and insert them into the DOM

Parameters:
Name Type Description
footnotes Array

Array of footnote objects

contentAreaHeight number

Height of the content area

Source:
print.js

<static> debugPageContent(pageIndex, pageHeight)

Debug function to analyze content positioning and help identify pagination issues

Parameters:
Name Type Description
pageIndex number

The page index to analyze

pageHeight number

The page height

Source:
print.js
Returns:

Analysis results

Type
object

<static> extractFootnotes()

Extract footnotes from the document

Source:
print.js
Returns:

Array of footnote objects

Type
Array

<static> getCurrentHeadingHierarchy(pageNumber, pageOffset)

Get current heading hierarchy based on page position

Parameters:
Name Type Description
pageNumber number

Current page number (1-based)

pageOffset number

Optional page offset for print context

Source:
print.js
Returns:

Object with h1, h2, h3 properties containing current heading text

Type
object

<static> getUpdatedDocumentHeight()

Get the updated document height after pagination

Source:
print.js
Returns:

Updated document height

Type
number

<static> handleWatchedHeadings(pageIndex, contentAreaHeight, movedElements)

Handle headings that were marked for watching after their next elements were moved

Parameters:
Name Type Description
pageIndex number

The current page index

contentAreaHeight number

The height of the content area

movedElements Set

Set of elements that have already been moved

Source:
print.js

<static> isPageEmpty(pageIndex, pageHeight)

Check if a page is truly empty (has no meaningful content)

Parameters:
Name Type Description
pageIndex number

The page index to check

pageHeight number

The page height

Source:
print.js
Returns:

True if the page is empty

Type
boolean

<static> makeBandW(bool, format, critic)

Set page up for printing, removing color and extra elements

Parameters:
Name Type Description
bool string

Do or undo BandW

format string

The file format to prepare for

critic string

CriticMarkup type

Source:
print.js
Returns:

Success string

Type
string

<static> paginateEntireDocument(paginationBuffer, contentAreaHeight)

Complete pagination function that handles the entire document

Parameters:
Name Type Description
paginationBuffer number

Buffer for determining cutoff points

contentAreaHeight number

Height of the content area

Source:
print.js
Returns:

Total number of pages after pagination

Type
number

<static> positionFootnoteContainers(contentAreaHeight)

Position footnote containers at the bottom of their respective pages

Parameters:
Name Type Description
contentAreaHeight number

Height of the content area

Source:
print.js

<static> preparePrintOperation(printing, critic, callback)

Prepare for print operation

Parameters:
Name Type Description
printing boolean | string

Is printing

critic boolean | string

CriticMarkup mode

callback function

Callback function

Source:
print.js

<static> preventOrphanedHeadings(pageIndex, contentAreaHeight, movedElements)

Proactively check and move orphaned headings to prevent them from being the last element on a page

Parameters:
Name Type Description
pageIndex number

The current page index

contentAreaHeight number

The height of the content area

movedElements Set

Set of elements that have already been moved

Source:
print.js

<static> printPrepared()

Default callback function

Source:
print.js

<static> processConditionalSeparators(input, headings)

Process conditional separators in header/footer templates

Parameters:
Name Type Description
input string

String containing %sep() tokens

headings object

Current heading hierarchy

Source:
print.js
Returns:

String with processed separators

Type
string

<static> processFootnotesForCurrentPage()

Process footnotes for placement at the bottom of pages

Deprecated:
  • This function is no longer used - footnote processing now happens after pagination
Source:
print.js

<static> refreshHeaderFooterFontPreferences()

Refresh header/footer font preferences (useful when preferences change)

Source:
print.js

<static> resetHeaderFooterHeight()

Reset header/footer height when logo is removed

Source:
print.js

<static> resetPagination()

Reset pagination state (clear moved elements tracking)

Source:
print.js

<static> setCustomHeaderFooterHeight(height)

Set custom header/footer height (useful for manual overrides)

Parameters:
Name Type Description
height string

Height value (e.g., "2em", "40px")

Source:
print.js

<static> setHeaderFooterFontPreferences()

Set header/footer font preferences and calculate proper height

Source:
print.js

<static> splitTableAtPage(table, pageEnd)

Split a table at page boundary by finding the last row that fits on the current page and adding padding-top to the next row to push it to the next page.

Parameters:
Name Type Description
table HTMLElement

The table element to split

pageEnd number

The page boundary position (absolute Y)

Source:
print.js
Returns:

Result object with split: true/false and details

Type
Object

init()

Initialize print variables

Source:
print.js

processVariables(input, opt)

Replace print header/footer variables

Parameters:
Name Type Description
input string

String containing variables tokens

opt object

Options

Source:
print.js
Returns:

String with replaced variables

Type
string

Namespace: print

Marked. print

Marked print and pagination subsystem.

Provides pagination, page-break handling, footnote layout, and printing helpers for the Marked app. This module operates directly on the rendered HTML within the preview WebView and computes page-relative positions using the current contentAreaHeight (the printable viewport height).

Debug logging: enable by setting the local constant PRINT_DEBUG=true. Useful filter tags include:

  • [PAGINATION DEBUG]
  • [HEADING PAD DEBUG]
  • [BREAK-AFTER DEBUG] / [BOTTOM PADDING DEBUG]
  • [TOC DEBUG], [LIST DEBUG], [FOOTNOTE DEBUG]

Exposed functions are returned at the bottom of the IIFE.

Source:
print.js

Methods


<static> addLogoStyles()

Add CSS styles for logo sizing in headers/footers

Source:
print.js

<static> addPaddingForLastPage(pageHeight, currentPage)

Add padding to the last page to ensure proper scroll positioning

Parameters:
Name Type Description
pageHeight number

The page height

currentPage number

The current page index

Source:
print.js
Returns:

Updated document height

Type
number

<static> addScrollBehaviorOverride()

Add CSS override to disable scroll-behavior during PDF export This prevents pagination issues where smooth scrolling causes content to be captured at the wrong scroll position

Source:
print.js

<static> adjustHeaderFooterHeight()

Dynamically adjust header/footer height based on logo dimensions

Source:
print.js

<static> buildHeadingHierarchyCache(pages)

Build heading hierarchy cache for all pages during pagination

Parameters:
Name Type Description
pages Array

Array of page elements from pagination

Source:
print.js

<static> checkIfHeadingIsOrphaned(headingElement, pageEnd, contentAreaHeight)

Check if a heading is orphaned (no content below it on the same page)

Parameters:
Name Type Description
headingElement Element

The heading element to check

pageEnd number

The end position of the current page

contentAreaHeight number

The height of the content area

Source:
print.js
Returns:

True if the heading is orphaned

Type
boolean

<static> clearHeadingHierarchyCache()

Clear the heading hierarchy cache

Source:
print.js

<static> createFootnoteContainer(pageFootnotes)

Create a single footnote container

Parameters:
Name Type Description
pageFootnotes Array

Array of footnotes for this page

Source:
print.js
Returns:

The footnote container element

Type
Element

<static> createFootnoteContainers(footnotes, contentAreaHeight)

Create footnote containers and insert them into the DOM

Parameters:
Name Type Description
footnotes Array

Array of footnote objects

contentAreaHeight number

Height of the content area

Source:
print.js

<static> debugPageContent(pageIndex, pageHeight)

Debug function to analyze content positioning and help identify pagination issues

Parameters:
Name Type Description
pageIndex number

The page index to analyze

pageHeight number

The page height

Source:
print.js
Returns:

Analysis results

Type
object

<static> extractFootnotes()

Extract footnotes from the document

Source:
print.js
Returns:

Array of footnote objects

Type
Array

<static> getCurrentHeadingHierarchy(pageNumber, pageOffset)

Get current heading hierarchy based on page position

Parameters:
Name Type Description
pageNumber number

Current page number (1-based)

pageOffset number

Optional page offset for print context

Source:
print.js
Returns:

Object with h1, h2, h3 properties containing current heading text

Type
object

<static> getUpdatedDocumentHeight()

Get the updated document height after pagination

Source:
print.js
Returns:

Updated document height

Type
number

<static> handleWatchedHeadings(pageIndex, contentAreaHeight, movedElements)

Handle headings that were marked for watching after their next elements were moved

Parameters:
Name Type Description
pageIndex number

The current page index

contentAreaHeight number

The height of the content area

movedElements Set

Set of elements that have already been moved

Source:
print.js

<static> isPageEmpty(pageIndex, pageHeight)

Check if a page is truly empty (has no meaningful content)

Parameters:
Name Type Description
pageIndex number

The page index to check

pageHeight number

The page height

Source:
print.js
Returns:

True if the page is empty

Type
boolean

<static> makeBandW(bool, format, critic)

Set page up for printing, removing color and extra elements

Parameters:
Name Type Description
bool string

Do or undo BandW

format string

The file format to prepare for

critic string

CriticMarkup type

Source:
print.js
Returns:

Success string

Type
string

<static> paginateEntireDocument(paginationBuffer, contentAreaHeight)

Complete pagination function that handles the entire document

Parameters:
Name Type Description
paginationBuffer number

Buffer for determining cutoff points

contentAreaHeight number

Height of the content area

Source:
print.js
Returns:

Total number of pages after pagination

Type
number

<static> positionFootnoteContainers(contentAreaHeight)

Position footnote containers at the bottom of their respective pages

Parameters:
Name Type Description
contentAreaHeight number

Height of the content area

Source:
print.js

<static> preparePrintOperation(printing, critic, callback)

Prepare for print operation

Parameters:
Name Type Description
printing boolean | string

Is printing

critic boolean | string

CriticMarkup mode

callback function

Callback function

Source:
print.js

<static> preventOrphanedHeadings(pageIndex, contentAreaHeight, movedElements)

Proactively check and move orphaned headings to prevent them from being the last element on a page

Parameters:
Name Type Description
pageIndex number

The current page index

contentAreaHeight number

The height of the content area

movedElements Set

Set of elements that have already been moved

Source:
print.js

<static> printPrepared()

Default callback function

Source:
print.js

<static> processConditionalSeparators(input, headings)

Process conditional separators in header/footer templates

Parameters:
Name Type Description
input string

String containing %sep() tokens

headings object

Current heading hierarchy

Source:
print.js
Returns:

String with processed separators

Type
string

<static> processFootnotesForCurrentPage()

Process footnotes for placement at the bottom of pages

Deprecated:
  • This function is no longer used - footnote processing now happens after pagination
Source:
print.js

<static> refreshHeaderFooterFontPreferences()

Refresh header/footer font preferences (useful when preferences change)

Source:
print.js

<static> resetHeaderFooterHeight()

Reset header/footer height when logo is removed

Source:
print.js

<static> resetPagination()

Reset pagination state (clear moved elements tracking)

Source:
print.js

<static> setCustomHeaderFooterHeight(height)

Set custom header/footer height (useful for manual overrides)

Parameters:
Name Type Description
height string

Height value (e.g., "2em", "40px")

Source:
print.js

<static> setHeaderFooterFontPreferences()

Set header/footer font preferences and calculate proper height

Source:
print.js

<static> splitTableAtPage(table, pageEnd)

Split a table at page boundary by finding the last row that fits on the current page and adding padding-top to the next row to push it to the next page.

Parameters:
Name Type Description
table HTMLElement

The table element to split

pageEnd number

The page boundary position (absolute Y)

Source:
print.js
Returns:

Result object with split: true/false and details

Type
Object

init()

Initialize print variables

Source:
print.js

processVariables(input, opt)

Replace print header/footer variables

Parameters:
Name Type Description
input string

String containing variables tokens

opt object

Options

Source:
print.js
Returns:

String with replaced variables

Type
string