import MarkdownIt from 'markdown-it'; import * as smiles_drawer from 'smiles-drawer'; /** * CSS length value that can be provided as either a number (interpreted as the * base unit used by SmilesDrawer) or a CSS length string (px, rem, em, pt). */ type CssLengthValue = number | string; /** * Context for resolving CSS length strings to absolute numeric values. * * - rootFontSize: pixel size used for `rem` units (default: 16px). * - baseFontSize: pixel size used for `em` units (falls back to rootFontSize). */ interface CssUnitContext { rootFontSize?: number; baseFontSize?: number; } /** * Theme colors for SmilesDrawer rendering engine. * Each property represents a color for a specific atom or drawing element. * * See: https://github.com/reymond-group/smilesDrawer#options */ interface SmilesDrawerTheme { /** Carbon color (default: '#fff' for dark, '#222' for light) */ C: string; /** Oxygen color (default: '#e74c3c') */ O: string; /** Nitrogen color (default: '#3498db') */ N: string; /** Fluorine color (default: '#27ae60') */ F: string; /** Chlorine color (default: '#16a085') */ CL: string; /** Bromine color (default: '#d35400') */ BR: string; /** Iodine color (default: '#8e44ad') */ I: string; /** Phosphorus color (default: '#d35400') */ P: string; /** Sulfur color (default: '#f1c40f') */ S: string; /** Boron color (default: '#e67e22') */ B: string; /** Silicon color (default: '#e67e22') */ SI: string; /** Hydrogen color (default: '#fff' for dark, '#222' for light) */ H: string; /** Background color (default: '#141414' for dark, '#fff' for light) */ BACKGROUND: string; } /** * Options for configuring the SmilesDrawer rendering engine. * * See: https://github.com/reymond-group/smilesDrawer#options */ interface SmilesDrawerOptions { /** * All length-based properties accept either raw numbers (interpreted as SmilesDrawer base units) * or CSS length strings (e.g. '2rem', '12px', '50%'). */ /** Drawing width (default: 500px; for inline SMILES: 1em) */ width?: CssLengthValue; /** Drawing height (default: 500px; for inline SMILES: 1em) */ height?: CssLengthValue; /** Bond thickness (default: 0.6px) */ bondThickness?: CssLengthValue; /** Bond length (default: 15px) */ bondLength?: CssLengthValue; /** Short bond length (e.g. double bonds) as a fraction of bond length (default: 0.85) */ shortBondLength?: number; /** Bond spacing (e.g. space between double bonds) (default: 0.18 * 15px) */ bondSpacing?: CssLengthValue; /** Atom visualization style: 'default', 'balls', or 'none' (default: 'default') */ atomVisualization?: 'default' | 'balls' | 'none'; /** Large font size (default: 6pt) for element symbols */ fontSizeLarge?: CssLengthValue; /** Small font size (default: 4pt) for numbers */ fontSizeSmall?: CssLengthValue; /** Padding around the drawing (default: 20px) */ padding?: CssLengthValue; /** Enable experimental features for complex ring systems (default: false) */ experimental?: boolean; /** Show terminal carbons (e.g. CH3 groups) (default: false) */ terminalCarbons?: boolean; /** Show explicit hydrogens (default: false) */ explicitHydrogens?: boolean; /** Overlap sensitivity for atom placement (default: 0.42) */ overlapSensitivity?: number; /** Number of overlap resolution iterations (default: 1) */ overlapResolutionIterations?: number; /** Draw concatenated terminals and pseudo elements in a compact style (default: true) */ compactDrawing?: boolean; /** Draw isometric SMILES if available (default: true) */ isometric?: boolean; /** Draw debug information to canvas (default: false) */ debug?: boolean; /** Color themes for rendering, keyed by theme name (default: {dark, light}) */ themes?: Record; /** Name of the theme to use (e.g. 'light' or 'dark') */ theme?: string; /** Weights for reactants in reactions (advanced, rarely used) */ reactantWeights?: string | number[][]; /** Weights for products in reactions (advanced, rarely used) */ productWeights?: string | number[][]; /** Additional reaction options as a string (advanced, rarely used) */ reactionOptions?: string; /** Weights for atoms (advanced, rarely used) */ weights?: string | number[]; /** Weights for reagents in reactions (advanced, rarely used) */ reagentWeights?: string | number[][]; } /** * Options for configuring the markdown-it-smiles plugin. * These options extend the core SmilesDrawer options for integration with markdown-it. */ type SmilesDrawerLoaderResult = typeof smiles_drawer; interface PluginOptions { /** * URL to a custom font to use for rendering. */ fontUrl?: string; /** * Output format for rendered SMILES: SVG or image. */ format?: 'svg' | 'img'; /** * Path or URL to the SmileDrawer script to use for rendering. */ smilesDrawerScript?: string; /** * If true, the smiles will be rendered at parse time in both Node.js and browser environments. * Useful when SSR output or markdown-it-container needs pre-rendered markup. */ renderAtParse?: boolean; /** * SmileDrawer rendering options for different contexts. * - default: options for all renderings * - inline: options for inline SMILES * - block: options for block SMILES */ smilesDrawerOptions?: { /** Default options for all renderings */ default?: Partial; /** Options for inline SMILES */ inline?: Partial; /** Options for block SMILES */ block?: Partial; }; /** * Error handling options (only works when renderAtParse is true). * - onError: callback for handling errors * - fallbackImage: image to use if rendering fails */ errorHandling?: { /** Callback for handling errors */ onError?: (e: Error) => void; /** Fallback image URL or data URI if rendering fails */ fallbackImage?: string; }; /** * Optional loader used to resolve the SmilesDrawer module in environments where the * CDN script tag is not desirable (e.g. bundler or SSR contexts). * When running in a browser, the plugin will automatically register the loader on a * shared namespace so that the injected runtime script can reuse it. */ loadSmilesDrawer?: () => Promise | SmilesDrawerLoaderResult; /** * Override defaults used when converting CSS length strings to numeric values. */ cssUnitContext?: CssUnitContext; } /** * markdown-it-smiles plugin * * This module provides a Markdown-it plugin for rendering SMILES (Simplified molecular input line entry specification) * strings as chemical structure diagrams. It supports both block and inline SMILES, and can render as SVG or * image using the smiles-drawer library. * * Usage: * import MarkdownIt from 'markdown-it'; * import { MarkdownItSmiles } from 'markdown-it-smiles'; * const md = MarkdownIt().use(MarkdownItSmiles, options); * * Options: * See PluginOptions in './plugin-options'. * * Features: * - Block and inline SMILES rendering * - Customizable rendering options (themes, size, etc.) * - Node and browser support (with caveats for renderAtParse) * * @module markdown-it-smiles */ /** * MarkdownItSmiles plugin function for Markdown-it. * * Registers block and inline SMILES rules and sets up rendering logic. * * @param md - The MarkdownIt instance to extend. * @param options - Plugin options for customizing rendering and behavior. */ declare function MarkdownItSmiles(md: MarkdownIt, options?: PluginOptions): void; export { MarkdownItSmiles };