How kepano/defuddle works
Main Components
• Defuddle Engine – The heart of this library. It includes the core parsing functionality that takes in a DOM document and outputs an article object having properties like content, title, metadata, math content, and more.
• Elements Modules – Under the src/elements directory, you have several modules that handle specific parts of content standardization:
• Code: Handles formatting and standardization of code blocks.
• Headings: Manages the extraction and transformation of heading elements.
• Math Modules: (math.base.ts, math.core.ts, math.full.ts, math.ts) These modules deal with converting math content including MathML elements. The “full” bundle uses the advanced math libraries.
• Metadata Extraction & Constants – These modules (metadata.ts, constants.ts) deal with gathering page meta-data and defining important constants.
• Types & Interfaces – The types.ts file defines the contract for the article object and supports type safety across the system.
• Bundles – Two entry points are provided: one in src/index.ts for the core bundle and one in src/index.full.ts for the full bundle that integrates additional math conversion capabilities.
Relationships and Interactions between Components
• The consumer calls the Defuddle constructor (from src/defuddle.ts) with a DOM document (and optional settings such as debug) and then invokes the parse() method.
• The parse method orchestrates the process by calling several helper modules/functions:
• It delegates heading and code block standardization to the corresponding element modules.
• For math content, depending on whether the core or full bundle is used, different math conversion modules are invoked.
• Metadata extraction is integrated to produce the final article output.
• External integrations:
• In server-side usage, an external package (e.g., JSDOM) is used to create a DOM, which then is passed to Defuddle.
• In the full bundle, external libraries such as mathml-to-latex and temml are integrated.
Architectural Patterns and Design Principles
• Modularity – The clear separation into different modules (elements, metadata, constants, types) supports a modular, loosely-coupled architecture.
• Extensibility – The design anticipates future extensions (e.g., new element modules, additional metadata extraction, alternative math conversion).
• Bundle Variants – Separation between the “core” and “full” functionality shows the use of feature toggles/build-time decisions in the architecture.
• Configurability – Options such as debug mode indicate that the system is designed to run in various environments with customizable behavior.
Relevant Technologies/Frameworks
• Webpack – Indicate that Webpack is used for bundling.
• External libraries:
• For advanced math conversion in the full bundle (e.g., mathml-to-latex, temml).
• JSDOM for server-side HTML parsing.