markdownify

package module
v0.0.0-...-4c9f0e6 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: MIT Imports: 7 Imported by: 0

README

markdownify-go

Go Reference Go Report Card

A Go library for converting HTML to Markdown. This library was developed as a Go port of matthewwithanm/python-markdownify.

Features

  • Simple and idiomatic Go interface
  • Support for various HTML elements (headings, links, lists, tables, and more)
  • Flexible configuration options
  • Clear error handling
  • Fully typed API interface leveraging Go generics

Installation

go get github.com/cnosuke/markdownify-go

Quick Start

package main

import (
    "fmt"
    "log"
    
    markdownify "github.com/cnosuke/markdownify-go"
)

func main() {
    // Create a client
    client, err := markdownify.NewClient()
    if err != nil {
        log.Fatalf("Client creation error: %v", err)
    }
    
    // Convert HTML to Markdown
    md, err := client.Markdownify("<b>Hello</b> <a href='https://example.com'>Example</a>")
    if err != nil {
        log.Fatalf("Conversion error: %v", err)
    }
    
    fmt.Println(md) // **Hello** [Example](https://example.com)
}

Advanced Usage

With Options
package main

import (
    "fmt"
    "log"
    
    markdownify "github.com/cnosuke/markdownify-go"
)

func main() {
    // Create a client with options
    client, err := markdownify.NewClient(
        markdownify.WithHeadingStyle(markdownify.HeadingStyleATX),
        markdownify.WithStrongEmSymbol(markdownify.SymbolUnderscore),
        markdownify.WithNewlineStyle(markdownify.NewlineStyleBackslash),
        markdownify.WithEscapeAsterisks(false),
    )
    if err != nil {
        log.Fatalf("Client creation error: %v", err)
    }
    
    // Convert HTML to Markdown
    md, err := client.Markdownify(`
        <h1>Title</h1>
        <p>This is <b>bold</b> text.<br>
        It contains a <a href="https://example.com">link</a> too.</p>
        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
        </ul>
    `)
    if err != nil {
        log.Fatalf("Conversion error: %v", err)
    }
    
    fmt.Println(md)
}

Options

markdownify-go supports the following options:

Option Description Default Value
WithAutolinks Use autolink style when 'a' tag content matches its href true
WithDefaultTitle Set link title to href when title is not specified false
WithHeadingStyle Define how headings are converted (ATX, ATX_CLOSED, UNDERLINED) UNDERLINED
WithBullets Define bullet style to use (string or array) "*+-"
WithStrongEmSymbol Define which symbol to use for emphasis (* or _) *
WithSubSymbol Define characters to wrap <sub> text ""
WithSupSymbol Define characters to wrap <sup> text ""
WithNewlineStyle Define markdown style for line breaks (<br>) (SPACES, BACKSLASH) SPACES
WithEscapeAsterisks Escape * in text as \* true
WithEscapeUnderscores Escape _ in text as \_ true
WithEscapeMisc Escape other punctuation in text false
WithStrip List of tags to exclude nil
WithConvert List of tags to convert nil
WithTableInferHeader Treat first row as header in tables without header false
WithWrap Wrap text paragraphs false
WithWrapWidth Set width for wrapping 80
WithStripDocument Remove leading/trailing newlines in document STRIP

API Reference

For detailed API documentation, see the Go Reference.

Error Handling

The library provides detailed error information. Errors are wrapped with descriptive messages and can be unwrapped for details.

md, err := client.Markdownify(html)
if err != nil {
    var mdErr *markdownify.Error
    if errors.As(err, &mdErr) {
        // Handle markdownify-specific error
        fmt.Printf("Error message: %s\n", mdErr.Message)
    } else {
        // Handle other errors
    }
}

Development Status

This library is currently under development. While it's functional and tested, we're continuously improving it. Feedback and contributions are welcome!

License

MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to submit a Pull Request.

Acknowledgments

Documentation

Index

Constants

View Source
const (
	// HeadingStyleATX はATXスタイルの見出し(例: # 見出し)を表します
	HeadingStyleATX = "atx"
	// HeadingStyleATXClosed はクローズドATXスタイルの見出し(例: # 見出し #)を表します
	HeadingStyleATXClosed = "atx_closed"
	// HeadingStyleUnderlined はアンダーラインスタイルの見出し(例: 見出し\n====)を表します
	HeadingStyleUnderlined = "underlined"
	// HeadingStyleSETEXT はHeadingStyleUnderlinedの別名です
	HeadingStyleSETEXT = HeadingStyleUnderlined
)

見出しスタイル定数

View Source
const (
	// NewlineStyleSpaces は空白2つを使った改行(例: 行末  \n)を表します
	NewlineStyleSpaces = "spaces"
	// NewlineStyleBackslash はバックスラッシュを使った改行(例: 行末\\\n)を表します
	NewlineStyleBackslash = "backslash"
)

改行スタイル定数

View Source
const (
	// SymbolAsterisk はアスタリスク(*)を使った強調を表します
	SymbolAsterisk = "*"
	// SymbolUnderscore はアンダースコア(_)を使った強調を表します
	SymbolUnderscore = "_"
)

強調スタイル定数

View Source
const (
	// StripDocumentNone はドキュメントの先頭/末尾の改行を削除しないことを表します
	StripDocumentNone = "none"
	// StripDocumentLSTRIP はドキュメントの先頭の改行を削除することを表します
	StripDocumentLSTRIP = "lstrip"
	// StripDocumentRSTRIP はドキュメントの末尾の改行を削除することを表します
	StripDocumentRSTRIP = "rstrip"
	// StripDocumentSTRIP はドキュメントの先頭と末尾の改行を削除することを表します
	StripDocumentSTRIP = "strip"
)

ドキュメントストリップスタイル定数

View Source
const (
	// DefaultAutolinks はautolinksのデフォルト値です
	DefaultAutolinks = true
	// DefaultBullets は箇条書きのデフォルト値です
	DefaultBullets = "*+-"
	// DefaultCodeLanguage はコードブロックの言語のデフォルト値です
	DefaultCodeLanguage = ""
	// DefaultTitle はデフォルトタイトルのデフォルト値です
	DefaultDefaultTitle = false
	// DefaultEscapeAsterisks はアスタリスクエスケープのデフォルト値です
	DefaultEscapeAsterisks = true
	// DefaultEscapeUnderscores はアンダースコアエスケープのデフォルト値です
	DefaultEscapeUnderscores = true
	// DefaultEscapeMisc はその他の文字エスケープのデフォルト値です
	DefaultEscapeMisc = false
	// DefaultHeadingStyle は見出しスタイルのデフォルト値です
	DefaultHeadingStyle = HeadingStyleUnderlined
	// DefaultNewlineStyle は改行スタイルのデフォルト値です
	DefaultNewlineStyle = NewlineStyleSpaces
	// DefaultStrongEmSymbol は強調シンボルのデフォルト値です
	DefaultStrongEmSymbol = SymbolAsterisk
	// DefaultSubSymbol はsubscriptシンボルのデフォルト値です
	DefaultSubSymbol = ""
	// DefaultSupSymbol はsuperscriptシンボルのデフォルト値です
	DefaultSupSymbol = ""
	// DefaultTableInferHeader はテーブルヘッダー推論のデフォルト値です
	DefaultTableInferHeader = false
	// DefaultWrap はテキストラップのデフォルト値です
	DefaultWrap = false
	// DefaultWrapWidth はラップ幅のデフォルト値です
	DefaultWrapWidth = 80
	// DefaultStripDocument はドキュメントストリップのデフォルト値です
	DefaultStripDocument = StripDocumentSTRIP
)

デフォルト値

View Source
const (
	// RegexConvertHeading は見出し変換用の正規表現パターン名です
	RegexConvertHeading = "convert_h(\\d+)"
	// RegexLineWithContent は内容を含む行用の正規表現パターン名です
	RegexLineWithContent = "^(.*)"
	// RegexWhitespace は空白文字用の正規表現パターン名です
	RegexWhitespace = "[\\t ]+"
	// RegexAllWhitespace はすべての空白文字用の正規表現パターン名です
	RegexAllWhitespace = "[\\t \\r\\n]+"
	// RegexNewlineWhitespace は改行と空白文字用の正規表現パターン名です
	RegexNewlineWhitespace = "[\\t \\r\\n]*[\\r\\n][\\t \\r\\n]*"
	// RegexHTMLHeading はHTML見出し用の正規表現パターン名です
	RegexHTMLHeading = "h(\\d+)"
	// RegexMakeConvertFnName は変換関数名作成用の正規表現パターン名です
	RegexMakeConvertFnName = "[\\[\\]:-]"
	// RegexExtractNewlines は改行抽出用の正規表現パターン名です
	// Python版の正規表現: r'^(\n*)((?:.*[^\n])?)(n*)$'
	RegexExtractNewlines = "^(\\n*)((?:.*[^\\n])?)?(\\n*)$"
	// RegexEscapeMiscChars はその他の文字エスケープ用の正規表現パターン名です
	RegexEscapeMiscChars = "([\\]\\\\&<`[>~=+|])"
	// RegexEscapeMiscDashSequences はダッシュシーケンスエスケープ用の正規表現パターン名です
	RegexEscapeMiscDashSequences = "(\\s|^)(-+(?:\\s|$))"
	// RegexEscapeMiscHashes はハッシュエスケープ用の正規表現パターン名です
	RegexEscapeMiscHashes = "(\\s|^)(#{1,6}(?:\\s|$))"
	// RegexEscapeMiscListItems はリストアイテムエスケープ用の正規表現パターン名です
	RegexEscapeMiscListItems = "((?:\\s|^)[0-9]{1,9})([.)](?:\\s|$))"
)

正規表現パターン名(実際の正規表現はutils.goで定義)

Variables

View Source
var (
	// ErrInvalidHeadingStyle は無効な見出しスタイルが指定された場合に返されます
	ErrInvalidHeadingStyle = errors.New("invalid heading style")

	// ErrInvalidNewlineStyle は無効な改行スタイルが指定された場合に返されます
	ErrInvalidNewlineStyle = errors.New("invalid newline style")

	// ErrInvalidStrongEmSymbol は無効な強調シンボルが指定された場合に返されます
	ErrInvalidStrongEmSymbol = errors.New("invalid strong/em symbol")

	// ErrInvalidStripDocument は無効なドキュメントストリップオプションが指定された場合に返されます
	ErrInvalidStripDocument = errors.New("invalid strip document option")

	// ErrConflictingOptions は競合するオプションが指定された場合に返されます
	ErrConflictingOptions = errors.New("conflicting options: cannot specify both strip and convert")

	// ErrInvalidHTML は無効なHTMLが与えられた場合に返されます
	ErrInvalidHTML = errors.New("invalid HTML")

	// ErrInvalidOption は無効なオプションが指定された場合に返されます
	ErrInvalidOption = errors.New("invalid option")

	// ErrInvalidWrapWidth は無効なラップ幅が指定された場合に返されます
	ErrInvalidWrapWidth = errors.New("invalid wrap width")
)

定義済みエラー

Functions

func Apply

func Apply[T Configurable](target *T, options ...Option[T]) error

Apply はオプションをターゲットに適用

func ChompGeneric

func ChompGeneric[T GenericString](text T) (prefix, suffix, content string)

ChompGeneric はインラインタグ内のテキストの先頭と末尾の空白を処理します あらゆる文字列型に対応するジェネリック版のchomp関数です

func CreateATXHeadingGeneric

func CreateATXHeadingGeneric[T GenericString](text T, level int, closed bool) string

CreateATXHeadingGeneric はATX形式の見出しを作成します あらゆる文字列型に対応するジェネリック版のcreateATXHeading関数です

func CreateInlineConverterGeneric

func CreateInlineConverterGeneric[T GenericString](markupFn func() string) func(text T, parentTags map[string]bool) string

CreateInlineConverterGeneric はインライン要素の変換関数を生成します あらゆる文字列型に対応するジェネリック版のcreateInlineConverter関数です

func CreateUnderlinedHeadingGeneric

func CreateUnderlinedHeadingGeneric[T GenericString](text T, level int) string

CreateUnderlinedHeadingGeneric はアンダーライン形式の見出しを作成します あらゆる文字列型に対応するジェネリック版のcreateUnderlinedHeading関数です

func EscapeSpecialCharsGeneric

func EscapeSpecialCharsGeneric[T GenericString](text T, config ClientConfig, parentTags map[string]bool) string

EscapeSpecialCharsGeneric は特殊文字をエスケープします あらゆる文字列型に対応するジェネリック版のescapeSpecialChars関数です

func ExtractNewlinesGeneric

func ExtractNewlinesGeneric[T GenericString](text T) (leadingNewlines string, content string, trailingNewlines string)

ExtractNewlinesGeneric は文字列から先頭の改行、本文、末尾の改行を抽出します あらゆる文字列型に対応するジェネリック版のextractNewlines関数です

func IsConflictingOptionsError

func IsConflictingOptionsError(err error) bool

IsConflictingOptionsError はエラーがErrConflictingOptionsであるかどうかを判定します

func IsInvalidHTMLError

func IsInvalidHTMLError(err error) bool

IsInvalidHTMLError はエラーがErrInvalidHTMLであるかどうかを判定します

func IsInvalidHeadingStyleError

func IsInvalidHeadingStyleError(err error) bool

IsInvalidHeadingStyleError はエラーがErrInvalidHeadingStyleであるかどうかを判定します

func IsInvalidNewlineStyleError

func IsInvalidNewlineStyleError(err error) bool

IsInvalidNewlineStyleError はエラーがErrInvalidNewlineStyleであるかどうかを判定します

func NormalizeWhitespace

func NormalizeWhitespace(selection *goquery.Selection) *goquery.Selection

NormalizeWhitespace はテキストの空白を正規化するパイプ

func NormalizeWhitespaceGeneric

func NormalizeWhitespaceGeneric[T GenericString](text T, inPreBlock bool) string

NormalizeWhitespaceGeneric は空白文字を正規化します あらゆる文字列型に対応するジェネリック版のnormalizeWhitespace関数です

Types

type Client

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

Client はジェネリクスを活用したHTMLからMarkdownへの変換クライアント

func NewClient

func NewClient(options ...ConfigOption) (*Client, error)

NewClient は新しいクライアントを作成

func (*Client) Config

func (c *Client) Config() ClientConfig

Config はクライアントの現在の設定を返す

func (*Client) Markdownify

func (c *Client) Markdownify(html string) (string, error)

Markdownify はHTMLをMarkdownに変換

func (*Client) MarkdownifyToMarkdownText

func (c *Client) MarkdownifyToMarkdownText(html string) (MarkdownText, error)

MarkdownifyToMarkdownText はHTMLをMarkdownTextに変換

func (*Client) WithConverter

func (c *Client) WithConverter(converter Converter[*goquery.Selection, MarkdownText]) *Client

WithConverter は指定したコンバーターを使用するようクライアントを設定

type ClientConfig

type ClientConfig struct {
	// Autolinks はaタグの内容がhrefと一致する場合に自動リンクスタイルを使用するかどうかを指定します
	Autolinks bool

	// Bullets は使用する箇条書きスタイルを指定します
	Bullets string

	// CodeLanguage はpreセクションで使用する言語を指定します
	CodeLanguage string

	// CodeLanguageCallback はコード言語を抽出するためのコールバック関数です
	CodeLanguageCallback func(selection *goquery.Selection) string

	// Convert は変換するタグのリストを指定します
	Convert []string

	// Strip は変換から除外するタグのリストを指定します
	Strip []string

	// DefaultTitle はタイトルが指定されていない場合にhrefをリンクのタイトルとして使用するかどうかを指定します
	DefaultTitle bool

	// EscapeAsterisks はテキスト内のアスタリスクをエスケープするかどうかを指定します
	EscapeAsterisks bool

	// EscapeUnderscores はテキスト内のアンダースコアをエスケープするかどうかを指定します
	EscapeUnderscores bool

	// EscapeMisc はその他の特殊文字をエスケープするかどうかを指定します
	EscapeMisc bool

	// HeadingStyle は見出しの変換スタイルを指定します
	HeadingStyle string

	// KeepInlineImagesIn はインライン画像を保持するタグのリストを指定します
	KeepInlineImagesIn []string

	// NewlineStyle は改行スタイルを指定します
	NewlineStyle string

	// StripDocument はドキュメントの先頭と末尾の改行をどのように扱うかを指定します
	StripDocument string

	// StrongEmSymbol は強調に使用するシンボルを指定します
	StrongEmSymbol string

	// SubSymbol はsubscriptに使用するシンボルを指定します
	SubSymbol string

	// SupSymbol はsuperscriptに使用するシンボルを指定します
	SupSymbol string

	// TableInferHeader はテーブルにヘッダーが存在しない場合に最初の行をヘッダーとして扱うかどうかを指定します
	TableInferHeader bool

	// Wrap はテキスト段落をラップするかどうかを指定します
	Wrap bool

	// WrapWidth はラップする幅を指定します
	WrapWidth int
}

ClientConfig はクライアントの設定を保持します

type ConfigOption

type ConfigOption = Option[ClientConfig]

ConfigOption はClientConfig専用のオプション

func WithAutolinks(enabled bool) ConfigOption

WithAutolinks は自動リンクオプションを設定するオプション

func WithBullets

func WithBullets(bullets string) ConfigOption

WithBullets は箇条書きスタイルを設定するオプション

func WithCodeLanguage

func WithCodeLanguage(language string) ConfigOption

WithCodeLanguage はデフォルトのコード言語を設定するオプション

func WithCodeLanguageCallback

func WithCodeLanguageCallback(callback func(*goquery.Selection) string) ConfigOption

WithCodeLanguageCallback はコード言語を決定するためのコールバック関数を設定するオプション

func WithConvert

func WithConvert(tags []string) ConfigOption

WithConvert は変換するタグのリストを設定するオプション

func WithDefaultTitle

func WithDefaultTitle(enabled bool) ConfigOption

WithDefaultTitle はリンクのデフォルトタイトルを有効にするオプション

func WithEscapeAsterisks

func WithEscapeAsterisks(enabled bool) ConfigOption

WithEscapeAsterisks はアスタリスクのエスケープを設定するオプション

func WithEscapeMisc

func WithEscapeMisc(enabled bool) ConfigOption

WithEscapeMisc はその他の文字のエスケープを設定するオプション

func WithEscapeUnderscores

func WithEscapeUnderscores(enabled bool) ConfigOption

WithEscapeUnderscores はアンダースコアのエスケープを設定するオプション

func WithHeadingStyle

func WithHeadingStyle(style string) ConfigOption

WithHeadingStyle は見出しスタイルを設定するオプション

func WithKeepInlineImagesIn

func WithKeepInlineImagesIn(tags []string) ConfigOption

WithKeepInlineImagesIn はインライン画像を維持するタグのリストを設定するオプション

func WithNewlineStyle

func WithNewlineStyle(style string) ConfigOption

WithNewlineStyle は改行スタイルを設定するオプション

func WithStrip

func WithStrip(tags []string) ConfigOption

WithStrip はstripするタグのリストを設定するオプション

func WithStripDocument

func WithStripDocument(mode string) ConfigOption

WithStripDocument はドキュメント改行の処理方法を設定するオプション

func WithStrongEmSymbol

func WithStrongEmSymbol(symbol string) ConfigOption

WithStrongEmSymbol は強調シンボルを設定するオプション

func WithSubSymbol

func WithSubSymbol(symbol string) ConfigOption

WithSubSymbol はsubscript用のシンボルを設定するオプション

func WithSupSymbol

func WithSupSymbol(symbol string) ConfigOption

WithSupSymbol はsuperscript用のシンボルを設定するオプション

func WithTableInferHeader

func WithTableInferHeader(enabled bool) ConfigOption

WithTableInferHeader はテーブルのヘッダー推論を設定するオプション

func WithWrap

func WithWrap(enabled bool) ConfigOption

WithWrap はテキストラッピングを設定するオプション

func WithWrapWidth

func WithWrapWidth(width int) ConfigOption

WithWrapWidth はラップ幅を設定するオプション

type Configurable

type Configurable interface {
	any
}

Configurable は設定可能なオブジェクトを表現する型を制約します

type ConversionContext

type ConversionContext struct {
	Text       string
	ParentTags map[string]bool
	Config     ClientConfig
}

ConversionContext は変換コンテキスト情報を保持する

type ConversionFunc

type ConversionFunc[T GoquerySelection, R MarkupOutput] func(input T, context ConversionContext) R

ConversionFunc は HTMLElement から MarkupOutput への変換関数

type Converter

type Converter[Input GoquerySelection, Output MarkupOutput] interface {
	Convert(input Input) Output
}

Converter は入力タイプInputから出力タイプOutputへの変換を行うジェネリックインターフェース

type ConverterRegistry

type ConverterRegistry[K RegisterKey, V any] struct {
	// contains filtered or unexported fields
}

ConverterRegistry はHTML要素名と変換関数のマッピングを型安全に管理

func NewConverterRegistry

func NewConverterRegistry[K RegisterKey, V any]() *ConverterRegistry[K, V]

NewConverterRegistry は新しいレジストリを作成します

func (*ConverterRegistry[K, V]) Get

func (r *ConverterRegistry[K, V]) Get(key K) (V, bool)

Get は登録された変換関数を取得

func (*ConverterRegistry[K, V]) Keys

func (r *ConverterRegistry[K, V]) Keys() []K

Keys は登録されているすべてのキーを取得

func (*ConverterRegistry[K, V]) Register

func (r *ConverterRegistry[K, V]) Register(key K, converter V)

Register は変換関数を登録

type Error

type Error struct {
	// Message はエラーメッセージです
	Message string

	// Err は元のエラーです
	Err error
}

Error はmarkdownify処理中に発生するエラーを表します

func NewMarkdownifyError

func NewMarkdownifyError(message string, err error) *Error

NewMarkdownifyError は新しいErrorを作成します

func (*Error) Error

func (e *Error) Error() string

Error はエラーメッセージを返します

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap は元のエラーを返します

type GenericString

type GenericString interface {
	~string
}

GenericString は文字列型を表す型制約

type GoquerySelection

type GoquerySelection interface {
	*goquery.Selection
}

GoquerySelection は*goquery.Selection専用の制約を提供

type HTMLElement

type HTMLElement interface {
	comparable
}

HTMLElement は HTML 要素を表現する型を制約します

type HTMLElementConverter

type HTMLElementConverter = ConversionFunc[*goquery.Selection, string]

HTMLElementConverter はHTML要素を変換するジェネリック関数型

type HTMLProcessor

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

HTMLProcessor はHTML要素の処理パイプライン

func NewHTMLProcessor

func NewHTMLProcessor(pipes ...Pipe[*goquery.Selection]) *HTMLProcessor

NewHTMLProcessor は新しいHTML処理パイプラインを作成

func (*HTMLProcessor) Process

func (p *HTMLProcessor) Process(selection *goquery.Selection) *goquery.Selection

Process はHTMLをパイプラインで処理

type HTMLTag

type HTMLTag string

HTMLTag は HTML タグを型安全に表現します

const (
	TagParagraph   HTMLTag = "p"
	TagDiv         HTMLTag = "div"
	TagSection     HTMLTag = "section"
	TagArticle     HTMLTag = "article"
	TagBlockquote  HTMLTag = "blockquote"
	TagHeading1    HTMLTag = "h1"
	TagHeading2    HTMLTag = "h2"
	TagHeading3    HTMLTag = "h3"
	TagHeading4    HTMLTag = "h4"
	TagHeading5    HTMLTag = "h5"
	TagHeading6    HTMLTag = "h6"
	TagAnchor      HTMLTag = "a"
	TagBold        HTMLTag = "b"
	TagStrong      HTMLTag = "strong"
	TagEm          HTMLTag = "em"
	TagItalic      HTMLTag = "i"
	TagCode        HTMLTag = "code"
	TagBreak       HTMLTag = "br"
	TagImage       HTMLTag = "img"
	TagDel         HTMLTag = "del"
	TagStrike      HTMLTag = "s"
	TagSub         HTMLTag = "sub"
	TagSup         HTMLTag = "sup"
	TagKbd         HTMLTag = "kbd"
	TagSamp        HTMLTag = "samp"
	TagList        HTMLTag = "ul"
	TagOrderedList HTMLTag = "ol"
	TagListItem    HTMLTag = "li"
	TagDL          HTMLTag = "dl"
	TagDT          HTMLTag = "dt"
	TagDD          HTMLTag = "dd"
	TagTable       HTMLTag = "table"
	TagTableRow    HTMLTag = "tr"
	TagTableCell   HTMLTag = "td"
	TagTableHeader HTMLTag = "th"
	TagCaption     HTMLTag = "caption"
	TagFigCaption  HTMLTag = "figcaption"
	TagHR          HTMLTag = "hr"
	TagPre         HTMLTag = "pre"
	TagScript      HTMLTag = "script"
	TagStyle       HTMLTag = "style"
	TagMeta        HTMLTag = "meta"
	TagLink        HTMLTag = "link"
)

HTML タグを列挙型のように定義

func StringToHTMLTag

func StringToHTMLTag(tagName string) HTMLTag

StringToHTMLTag は文字列からHTMLTagに変換

type HTMLToMarkdownConverter

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

HTMLToMarkdownConverter はHTML(goquery.Selection)からMarkdownテキストへの変換を実装

func NewHTMLToMarkdownConverter

func NewHTMLToMarkdownConverter(config ClientConfig) *HTMLToMarkdownConverter

NewHTMLToMarkdownConverter は新しいコンバーターを作成

func (*HTMLToMarkdownConverter) Convert

func (c *HTMLToMarkdownConverter) Convert(selection *goquery.Selection) MarkdownText

Convert はHTML全体をMarkdownに変換(Converter[*goquery.Selection, MarkdownText]インターフェースを実装)

type MarkdownText

type MarkdownText string

MarkdownText は Markdown テキストを表現する型

func (MarkdownText) String

func (m MarkdownText) String() string

String は文字列表現を返す

type MarkupOutput

type MarkupOutput interface {
	~string
}

MarkupOutput はマークアップ出力を表現する型を制約します

type Option

type Option[T Configurable] func(*T) error

Option は設定可能なオブジェクトに対するオプション関数型

type OptionValue

type OptionValue[T comparable] struct {
	// contains filtered or unexported fields
}

OptionValue はオプション値を型安全に扱うための型

func NewOptionValue

func NewOptionValue[T comparable](defaultValue T) OptionValue[T]

NewOptionValue は新しいオプション値を作成

func (OptionValue[T]) IsSet

func (o OptionValue[T]) IsSet() bool

IsSet はオプション値が設定されているかどうかを返す

func (*OptionValue[T]) Set

func (o *OptionValue[T]) Set(value T)

Set はオプション値を設定

func (OptionValue[T]) Value

func (o OptionValue[T]) Value() T

Value はオプション値を取得

type Pipe

type Pipe[T any] func(T) T

Pipe は変換パイプラインの一部を表す

func RemoveIgnoredElements

func RemoveIgnoredElements(config ClientConfig) Pipe[*goquery.Selection]

RemoveIgnoredElements は無視すべき要素を削除するパイプ

type Pipeline

type Pipeline[T any] struct {
	// contains filtered or unexported fields
}

Pipeline は複数のPipeを組み合わせた処理のチェーン

func NewPipeline

func NewPipeline[T any](pipes ...Pipe[T]) *Pipeline[T]

NewPipeline は新しいパイプラインを作成

func (*Pipeline[T]) AddPipe

func (p *Pipeline[T]) AddPipe(pipe Pipe[T])

AddPipe はパイプラインに新しいパイプを追加

func (*Pipeline[T]) Process

func (p *Pipeline[T]) Process(input T) T

Process はパイプラインを通じて入力を処理

type RegisterKey

type RegisterKey interface {
	comparable
}

RegisterKey はレジストリのキーとして使用できる型を制約します

type Rule

type Rule[T any, R any] struct {
	Match func(T) bool
	Apply func(T) R
}

Rule は変換ルールを表す

type RuleEngine

type RuleEngine[T any, R any] struct {
	// contains filtered or unexported fields
}

RuleEngine は複数のルールを管理し適用する

func NewRuleEngine

func NewRuleEngine[T any, R any](fallback func(T) R) *RuleEngine[T, R]

NewRuleEngine は新しいルールエンジンを作成

func (*RuleEngine[T, R]) AddRule

func (p *RuleEngine[T, R]) AddRule(match func(T) bool, apply func(T) R)

AddRule はルールを追加

func (*RuleEngine[T, R]) Apply

func (p *RuleEngine[T, R]) Apply(input T) R

Apply は適切なルールを見つけて適用

type TagConverterRegistry

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

TagConverterRegistry は型安全なタグと変換関数のマッピングを提供

func NewTagConverterRegistry

func NewTagConverterRegistry() *TagConverterRegistry

NewTagConverterRegistry は HTML タグ専用のレジストリを作成

func (*TagConverterRegistry) Get

Get は登録された変換関数を取得

func (*TagConverterRegistry) GetByString

func (r *TagConverterRegistry) GetByString(tagName string) (HTMLElementConverter, bool)

GetByString は文字列からHTMLTagに変換して関数を取得

func (*TagConverterRegistry) Register

func (r *TagConverterRegistry) Register(tag HTMLTag, converter HTMLElementConverter)

Register は変換関数を登録

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

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