comet.html

The html module provides utility functions for working with input and output HTML text.

Methods

comet.html.getRawText(input)

Converts an HTML input string to raw text that no longer contains formatting tags.

All HTML entities and tags are removed. The input must be valid HTML.

Parameters

input (str) – The input HTML text

Returns

The raw text content

Return type

str

Raises
Available

CScript

html::raw_text

comet.html.toTagged(input, options)

Converts an HTML input string to InDesign® TaggedText.

Input must be valid XHTML.

See here for a description of supported HTML attributes.

Parameters
  • input (str) – The input HTML text

  • options (dict) –

    The conversion options.

    Keys must be str.

    The following options are available:

    kCSSUnescapeMode:

    • Value type: int

    • Default: -1

    How should the escaping of unsupported characters in style names from an export be reverted? * -1 = Anything * 0 = Hex Mode * 1 = Slash Mode

    See here.

    ’kPrefix’:

    • Value type: str

    • Default: ‘%!TT’

    Prefix to prepend to the result.

    See here.

    ’kCharStyleAware’:

    Whether to insert TT Jokers into the text

    See here.

Returns

The convertext text content

Return type

str

Raises
  • TypeError – When parameter types are invalid

  • ValueError

    • When parameter input is empty

    • When parameter options contains invalid values

  • CometError – On internal error

Available

CScript

html::to_tagged

comet.html.exportText(input, options)

Export the content of a text frame as HTML.

Style information is put into a separate .css file into a subfolder in the target folder.

More information can be found here

Parameters
  • input

    The source text to export.

    The parameter type can be:

    • CFrame:

      A text frame. This will export the entire text inside the frame’s chain.

    • CTextModel:

      A text model. This exports the entire text inside the model.

    • tuple [CTextModel, int, int]

      A text model with start and length. Length may be -1 = to end

  • options (dict[str, int | bool | str]) –

    Options for the export.

    Keys must be str.

    The following options are available:

    ’kOutputFolder’

    • Value type: str

    Target folder.

    Required when exporting to a file

    When this option is provided, the function returns None.

    Also requires the additional option ‘kOutputName’.

    ’kOutputName’

    • Value type: str

    Name of the output file (without extension).

    Required when exporting to a file

    When this option is provided, the function returns None.

    Also requires the additional option ‘kOutputFolder’.

    ’kStartPosition’

    • Value type: int

    • Default value: 0

    Start index in the text model

    When parameter input is CTextModel, this is relative to the text model!

    ’kLength’

    • Value type: int

    • Default value: -1

    Length in the text model (-1 = until the end).

    When parameter input is CTextModel, this is relative to the text model!

    ’kDocTitle’

    • Value type: str

    • Default value: [Filename]

    Title of the HTML document

    ’kCopyImages’

    Link or copy images? (False = link, True = copy)

    ’kExportUnsupported’

    Export in HTML unsupported images as .png?

    ’kExportMissing’

    Export missing images from previews as .png?

    ’kWriteCSS’

    Write CSS?

    ’kInputCSS’

    • Value type: str

    • Default value: ‘’

    Alternative CSS.

    When this parameter is set, the input is used as CSS instead of the generated one.

    The input can be a path to a CSS file or a CSS definition.

    ’kCSSEscapeMode’

    • Value type: int

    • Default value: 0

    Which escape style should be used for unsupported characters in style names?

    • 0: Hex Mode

    • 1: Slash Mode

    See here.

    ’kBodyOnly’

    Export complete HMLT incl. <html><body> tags or only the <body> contents?

    • False: Complete HTML

    • True: Only contents of <body>

    ’kEscapeBrackets’

    Create XML conform output?

    • False: No

    • True: Yes, the folling replacings are done:

      • < to &lt;

      • > to &gt;

      • & to &amp;

    ’kHexColors’

    Export CSS color values in hexadecimal format?

Returns

  • When exporting to a string: the result HTML string.

  • When exporting to a file: None

Return type

str | None

Raises
Available

CScript

html::export_frame