elements

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package elements provides enhanced element processing functionality This module handles code block processing including syntax highlighting, language detection, and code formatting

Package elements provides enhanced element processing functionality This module handles footnote processing including detection, linking, and accessibility improvements

Package elements provides enhanced element processing functionality This module handles heading processing including navigation element removal, anchor link cleanup, and text content extraction

Package elements provides enhanced element processing functionality This module handles image processing including optimization, lazy loading, responsive processing, and Alt text generation

Package elements provides enhanced element processing functionality This module handles mathematical formula processing including MathML extraction, LaTeX conversion, and math display normalization

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessCodeBlocks

func ProcessCodeBlocks(doc *goquery.Document, options *CodeBlockProcessingOptions)

ProcessCodeBlocks processes all code blocks in the document (public interface) TypeScript original code:

export function processCodeBlocks(doc: Document, options?: CodeBlockOptions): void {
  const processor = new CodeBlockProcessor(doc);
  processor.processAllCodeBlocks(options || defaultOptions);
}

func ProcessHeadings

func ProcessHeadings(doc *goquery.Document, options *HeadingProcessingOptions)

ProcessHeadings processes all headings in the document (public interface) TypeScript original code:

export function processHeadings(doc: Document, options?: HeadingOptions): void {
  const processor = new HeadingProcessor(doc);
  processor.processAllHeadings(options || defaultOptions);
}

func ProcessImages

func ProcessImages(doc *goquery.Document, options *ImageProcessingOptions)

ProcessImages processes all images in the document (public interface) TypeScript original code:

export function processImages(doc: Document, options?: ImageProcessingOptions): void {
  const processor = new ImageProcessor(doc);
  processor.processImages(options);
}

func ProcessMath

func ProcessMath(doc *goquery.Document, options *MathProcessingOptions)

ProcessMath processes all mathematical formulas in the document (public interface) TypeScript original code:

export function processMath(doc: Document, options?: MathOptions): void {
  const processor = new MathProcessor(doc);
  processor.processAllMath(options || defaultOptions);
}

Types

type CodeBlockProcessingOptions

type CodeBlockProcessingOptions struct {
	DetectLanguage        bool
	FormatCode            bool
	AddLineNumbers        bool
	EnableSyntaxHighlight bool
	WrapInPre             bool
}

CodeBlockProcessingOptions contains options for code block processing TypeScript original code:

interface CodeBlockOptions {
  detectLanguage?: boolean;
  formatCode?: boolean;
  addLineNumbers?: boolean;
  enableSyntaxHighlight?: boolean;
  wrapInPre?: boolean;
}

func DefaultCodeBlockProcessingOptions

func DefaultCodeBlockProcessingOptions() *CodeBlockProcessingOptions

DefaultCodeBlockProcessingOptions returns default options for code block processing TypeScript original code:

const defaultOptions: CodeBlockOptions = {
  detectLanguage: true,
  formatCode: true,
  addLineNumbers: false,
  enableSyntaxHighlight: true,
  wrapInPre: true
};

type CodeBlockProcessor

type CodeBlockProcessor struct {
	// contains filtered or unexported fields
}

CodeBlockProcessor handles code block processing and enhancement TypeScript original code:

class CodeBlockProcessor {
  constructor(private document: Document) {}
}

func NewCodeBlockProcessor

func NewCodeBlockProcessor(doc *goquery.Document) *CodeBlockProcessor

NewCodeBlockProcessor creates a new code block processor TypeScript original code: constructor(private doc: Document) {}

func (*CodeBlockProcessor) ProcessCodeBlocks

func (p *CodeBlockProcessor) ProcessCodeBlocks(options *CodeBlockProcessingOptions)

ProcessCodeBlocks processes all code blocks in the document TypeScript original code: export const codeBlockRules = [

{
  selector: [
    'pre',
    'div[class*="prismjs"]',
    '.syntaxhighlighter',
    '.highlight',
    '.highlight-source',
    '.wp-block-syntaxhighlighter-code',
    '.wp-block-code',
    'div[class*="language-"]'
  ].join(', '),
  element: 'pre',
  transform: (el: Element, doc: Document): Element => {
    // Processing logic here
  }
}

];

type Footnote

type Footnote struct {
	ID         string
	Number     int
	Reference  *goquery.Selection
	Definition *goquery.Selection
	Content    string
	RefText    string
	Linked     bool
}

Footnote represents a footnote with its reference and definition TypeScript original code:

interface FootnoteData {
  content: any;
  originalId: string;
  refs: string[];
}

func ProcessFootnotes

func ProcessFootnotes(doc *goquery.Document, options *FootnoteProcessingOptions) []*Footnote

ProcessFootnotes processes all footnotes in the document (public interface) TypeScript original code:

export function standardizeFootnotes(element: any): void {
  const handler = new FootnoteHandler(element.ownerDocument);
  handler.standardizeFootnotes(element);
}

type FootnoteProcessingOptions

type FootnoteProcessingOptions struct {
	DetectFootnotes      bool
	LinkFootnotes        bool
	ImproveAccessibility bool
	GenerateSection      bool
	NumberFootnotes      bool
	FootnotePrefix       string
	SectionTitle         string
	SectionLocation      string // "end", "after-content", "custom"
}

FootnoteProcessingOptions contains options for footnote processing TypeScript original code:

interface FootnoteData {
  content: any;
  originalId: string;
  refs: string[];
}

interface FootnoteCollection {
  [footnoteNumber: number]: FootnoteData;
}

func DefaultFootnoteProcessingOptions

func DefaultFootnoteProcessingOptions() *FootnoteProcessingOptions

DefaultFootnoteProcessingOptions returns default options for footnote processing TypeScript original code:

const defaultOptions = {
  detectFootnotes: true,
  linkFootnotes: true,
  improveAccessibility: true,
  generateSection: true,
  numberFootnotes: true
};

type FootnoteProcessor

type FootnoteProcessor struct {
	// contains filtered or unexported fields
}

FootnoteProcessor handles footnote processing and enhancement TypeScript original code:

class FootnoteHandler {
  private doc: any;

  constructor(doc: any) {
    this.doc = doc;
  }
}

func NewFootnoteProcessor

func NewFootnoteProcessor(doc *goquery.Document) *FootnoteProcessor

NewFootnoteProcessor creates a new footnote processor TypeScript original code:

constructor(doc: any) {
  this.doc = doc;
}

func (*FootnoteProcessor) CleanupFootnotes

func (p *FootnoteProcessor) CleanupFootnotes(footnotes []*Footnote) []*Footnote

CleanupFootnotes removes duplicate and invalid footnotes TypeScript original code:

cleanupFootnotes(footnotes: Footnote[]): Footnote[] {
  const uniqueFootnotes = new Map();
  const cleaned = [];

  for (const footnote of footnotes) {
    if (!uniqueFootnotes.has(footnote.id) && footnote.isValid()) {
      uniqueFootnotes.set(footnote.id, footnote);
      cleaned.push(footnote);
    }
  }

  return cleaned;
}

func (*FootnoteProcessor) GetFootnotes

func (p *FootnoteProcessor) GetFootnotes() []*Footnote

GetFootnotes returns all footnotes found in the document TypeScript original code:

getFootnotes(): Footnote[] {
  return this.footnotes;
}

func (*FootnoteProcessor) HasFootnotes

func (p *FootnoteProcessor) HasFootnotes() bool

HasFootnotes checks if the document has footnotes TypeScript original code:

hasFootnotes(): boolean {
  return this.footnotes.length > 0;
}

func (*FootnoteProcessor) ProcessFootnotes

func (p *FootnoteProcessor) ProcessFootnotes(options *FootnoteProcessingOptions) []*Footnote

ProcessFootnotes processes all footnotes in the document TypeScript original code:

standardizeFootnotes(element: any) {
  const footnotes = this.collectFootnotes(element);
  // Standardize inline footnotes using the collected IDs
  const footnoteInlineReferences = element.querySelectorAll(FOOTNOTE_INLINE_REFERENCES);
  // Process all footnote references and definitions
}

type HeadingProcessingOptions

type HeadingProcessingOptions struct {
	RemoveNavigation  bool
	PreserveStructure bool
	AllowedAttributes []string
}

HeadingProcessingOptions contains options for heading processing TypeScript original code:

interface HeadingOptions {
  removeNavigation?: boolean;
  preserveStructure?: boolean;
  allowedAttributes?: string[];
}

func DefaultHeadingProcessingOptions

func DefaultHeadingProcessingOptions() *HeadingProcessingOptions

DefaultHeadingProcessingOptions returns default options for heading processing TypeScript original code:

const defaultOptions: HeadingOptions = {
  removeNavigation: true,
  preserveStructure: true,
  allowedAttributes: ['id', 'class', 'data-*']
};

type HeadingProcessor

type HeadingProcessor struct {
	// contains filtered or unexported fields
}

HeadingProcessor handles heading processing and enhancement TypeScript original code: export const headingRules = [

{
  selector: 'h1, h2, h3, h4, h5, h6',
  element: 'keep',
  transform: (el: Element): Element => {
    // Processing logic here
  }
}

];

func NewHeadingProcessor

func NewHeadingProcessor(doc *goquery.Document) *HeadingProcessor

NewHeadingProcessor creates a new heading processor TypeScript original code:

class HeadingProcessor {
  constructor(private document: Document) {}
}

func (*HeadingProcessor) ProcessHeadings

func (p *HeadingProcessor) ProcessHeadings(options *HeadingProcessingOptions)

ProcessHeadings processes all headings in the document TypeScript original code: export const headingRules = [

{
  selector: 'h1, h2, h3, h4, h5, h6',
  element: 'keep',
  transform: (el: Element): Element => {
    // Processing logic
  }
}

];

type ImageProcessingOptions

type ImageProcessingOptions struct {
	EnableLazyLoading bool
	EnableResponsive  bool
	GenerateAltText   bool
	OptimizeImages    bool
	RemoveSmallImages bool
	MinImageWidth     int
	MinImageHeight    int
	MaxImageWidth     int
	MaxImageHeight    int
}

ImageProcessingOptions contains options for image processing TypeScript original code:

interface ImageProcessingOptions {
  enableLazyLoading?: boolean;
  enableResponsive?: boolean;
  generateAltText?: boolean;
  optimizeImages?: boolean;
  removeSmallImages?: boolean;
  minImageWidth?: number;
  minImageHeight?: number;
  maxImageWidth?: number;
  maxImageHeight?: number;
}

func DefaultImageProcessingOptions

func DefaultImageProcessingOptions() *ImageProcessingOptions

DefaultImageProcessingOptions returns default options for image processing TypeScript original code:

const defaultImageOptions: ImageProcessingOptions = {
  enableLazyLoading: true,
  enableResponsive: true,
  generateAltText: true,
  optimizeImages: true,
  removeSmallImages: true,
  minImageWidth: 50,
  minImageHeight: 50,
  maxImageWidth: 1200,
  maxImageHeight: 800
};

type ImageProcessor

type ImageProcessor struct {
	// contains filtered or unexported fields
}

ImageProcessor handles image processing and enhancement TypeScript original code: const b64DataUrlRegex = /^data:image\/([^;]+);base64,/; const srcsetPattern = /\.(jpg|jpeg|png|webp)\s+\d/; const srcPattern = /^\s*\S+\.(jpg|jpeg|png|webp)\S*\s*$/; const imageUrlPattern = /\.(jpg|jpeg|png|webp|gif|avif)(\?.*)?$/i; const widthPattern = /\s(\d+)w/; const dprPattern = /dpr=(\d+(?:\.\d+)?)/; const urlPattern = /^([^\s]+)/; const filenamePattern = /^[\w\-\.\/\\]+\.(jpg|jpeg|png|gif|webp|svg)$/i; const datePattern = /^\d{4}-\d{2}-\d{2}$/;

export const imageRules = [

{
  selector: 'picture',
  element: 'picture',
  transform: (el: Element, doc: Document): Element => { ... }
},
// ... other image processing rules

];

func NewImageProcessor

func NewImageProcessor(doc *goquery.Document) *ImageProcessor

NewImageProcessor creates a new image processor TypeScript original code:

class ImageProcessor {
  constructor(private document: Document) {}
}

func (*ImageProcessor) ProcessImages

func (p *ImageProcessor) ProcessImages(options *ImageProcessingOptions)

ProcessImages processes all images in the document TypeScript original code:

processImages(options?: ImageProcessingOptions): void {
  const imgs = this.document.querySelectorAll('img');
  imgs.forEach(img => this.processImage(img, options));

  const figures = this.document.querySelectorAll('figure');
  figures.forEach(figure => this.processFigure(figure, options));

  const pictures = this.document.querySelectorAll('picture');
  pictures.forEach(picture => this.processPicture(picture, options));

  if (options?.removeSmallImages) {
    this.removeSmallImages(options);
  }
}

type MathData

type MathData struct {
	MathML  string `json:"mathml,omitempty"`
	LaTeX   string `json:"latex,omitempty"`
	Type    string `json:"type,omitempty"`
	Display string `json:"display,omitempty"`
}

MathData represents extracted mathematical content TypeScript original code:

export interface MathData {
  mathml?: string;
  latex?: string;
  type?: 'katex' | 'mathjax' | 'mathml' | 'latex';
  display?: 'block' | 'inline';
}

type MathProcessingOptions

type MathProcessingOptions struct {
	ExtractMathML   bool
	ExtractLaTeX    bool
	CleanupScripts  bool
	PreserveDisplay bool
}

MathProcessingOptions contains options for math processing TypeScript original code:

interface MathOptions {
  extractMathML?: boolean;
  extractLaTeX?: boolean;
  cleanupScripts?: boolean;
  preserveDisplay?: boolean;
}

func DefaultMathProcessingOptions

func DefaultMathProcessingOptions() *MathProcessingOptions

DefaultMathProcessingOptions returns default options for math processing TypeScript original code:

const defaultOptions: MathOptions = {
  extractMathML: true,
  extractLaTeX: true,
  cleanupScripts: true,
  preserveDisplay: true
};

type MathProcessor

type MathProcessor struct {
	// contains filtered or unexported fields
}

MathProcessor handles mathematical formula processing and enhancement TypeScript original code: export const mathRules = [

{
  selector: mathSelectors,
  element: 'math',
  transform: (el: Element, doc: Document): Element => {
    // Processing logic here
  }
}

];

func NewMathProcessor

func NewMathProcessor(doc *goquery.Document) *MathProcessor

NewMathProcessor creates a new math processor TypeScript original code:

class MathProcessor {
  constructor(private document: Document) {}
}

func (*MathProcessor) ProcessMath

func (p *MathProcessor) ProcessMath(options *MathProcessingOptions)

ProcessMath processes all mathematical formulas in the document TypeScript original code: export const mathRules = [

{
  selector: mathSelectors,
  element: 'math',
  transform: (el: Element, doc: Document): Element => {
    const mathData = getMathMLFromElement(el);
    const latex = getLatexFromElement(el);
    const isBlock = isBlockDisplay(el);
    const cleanMathEl = createCleanMathEl(doc, mathData, latex, isBlock);
    // Cleanup logic...
  }
}

];

type RoleProcessingOptions

type RoleProcessingOptions struct {
	ConvertParagraphs bool
	ConvertLists      bool
	ConvertButtons    bool
	ConvertLinks      bool
}

RoleProcessingOptions configures role processing behavior

func DefaultRoleProcessingOptions

func DefaultRoleProcessingOptions() *RoleProcessingOptions

DefaultRoleProcessingOptions returns default options for role processing

type RoleProcessor

type RoleProcessor struct {
	// contains filtered or unexported fields
}

RoleProcessor handles conversion of ARIA roles to semantic HTML elements

func NewRoleProcessor

func NewRoleProcessor(doc *goquery.Document) *RoleProcessor

NewRoleProcessor creates a new role processor

func (*RoleProcessor) ProcessRoles

func (p *RoleProcessor) ProcessRoles(options *RoleProcessingOptions)

ProcessRoles processes all role-based elements in the document

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL