html

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

gomuks - A terminal Matrix client written in Go. Copyright (C) 2020 Tulir Asokan

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

From https://github.com/golang/image/blob/master/colornames/colornames.go

Index

Constants

View Source
const BlockQuoteChar = '>'
View Source
const HorizontalLineChar = '━'
View Source
const SpoilerColor = tcell.ColorYellow
View Source
const TabLength = 4

Variables

View Source
var BlockTags = []string{"p", "h1", "h2", "h3", "h4", "h5", "h6", "ol", "ul", "li", "pre", "blockquote", "div", "hr", "table"}

Functions

func AdjustStyleBold

func AdjustStyleBold(style tcell.Style) tcell.Style

func AdjustStyleItalic

func AdjustStyleItalic(style tcell.Style) tcell.Style

func AdjustStyleStrikethrough

func AdjustStyleStrikethrough(style tcell.Style) tcell.Style

func AdjustStyleUnderline

func AdjustStyleUnderline(style tcell.Style) tcell.Style

Types

type AdjustStyleFunc

type AdjustStyleFunc func(tcell.Style) tcell.Style

AdjustStyleFunc is a lambda function type to edit an existing tcell Style.

func AdjustStyleBackgroundColor

func AdjustStyleBackgroundColor(color tcell.Color) AdjustStyleFunc
func AdjustStyleLink(url, id string) AdjustStyleFunc

func AdjustStyleTextColor

func AdjustStyleTextColor(color tcell.Color) AdjustStyleFunc

type AdjustStyleReason added in v0.3.0

type AdjustStyleReason int
const (
	AdjustStyleReasonNormal AdjustStyleReason = iota
	AdjustStyleReasonHideSpoiler
)

type BaseEntity

type BaseEntity struct {
	// The HTML tag of this entity.
	Tag string
	// Style for this entity.
	Style tcell.Style
	// Whether or not this is a block-type entity.
	Block bool
	// Height to use for entity if both text and children are empty.
	DefaultHeight int
	// contains filtered or unexported fields
}

func (*BaseEntity) AdjustStyle

func (be *BaseEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

AdjustStyle changes the style of this text entity.

func (*BaseEntity) CalculateBuffer

func (be *BaseEntity) CalculateBuffer(width, startX int, ctx DrawContext) int

CalculateBuffer prepares this entity for rendering with the given parameters.

func (*BaseEntity) Clone

func (be *BaseEntity) Clone() Entity

Clone creates a copy of this base entity.

func (*BaseEntity) Draw

func (be *BaseEntity) Draw(screen mauview.Screen, ctx DrawContext)

func (*BaseEntity) GetTag

func (be *BaseEntity) GetTag() string

GetTag returns the HTML tag of this entity.

func (*BaseEntity) Height

func (be *BaseEntity) Height() int

Height returns the render height of this entity.

func (*BaseEntity) IsBlock

func (be *BaseEntity) IsBlock() bool

IsBlock returns whether or not this is a block-type entity.

func (*BaseEntity) IsEmpty added in v0.3.0

func (be *BaseEntity) IsEmpty() bool

func (*BaseEntity) PlainText

func (be *BaseEntity) PlainText() string

func (*BaseEntity) String

func (be *BaseEntity) String() string

String returns a textual representation of this BaseEntity struct.

type BlockquoteEntity

type BlockquoteEntity struct {
	*ContainerEntity
}

func NewBlockquoteEntity

func NewBlockquoteEntity(children []Entity) *BlockquoteEntity

func (*BlockquoteEntity) AdjustStyle

func (be *BlockquoteEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

func (*BlockquoteEntity) Clone

func (be *BlockquoteEntity) Clone() Entity

func (*BlockquoteEntity) Draw

func (be *BlockquoteEntity) Draw(screen mauview.Screen, ctx DrawContext)

func (*BlockquoteEntity) PlainText

func (be *BlockquoteEntity) PlainText() string

func (*BlockquoteEntity) String

func (be *BlockquoteEntity) String() string

type BreakEntity

type BreakEntity struct {
	*BaseEntity
}

func NewBreakEntity

func NewBreakEntity() *BreakEntity

func (*BreakEntity) AdjustStyle

func (be *BreakEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

AdjustStyle changes the style of this text entity.

func (*BreakEntity) Clone

func (be *BreakEntity) Clone() Entity

func (*BreakEntity) Draw

func (be *BreakEntity) Draw(screen mauview.Screen, ctx DrawContext)

func (*BreakEntity) PlainText

func (be *BreakEntity) PlainText() string

func (*BreakEntity) String

func (be *BreakEntity) String() string

type CodeBlockEntity

type CodeBlockEntity struct {
	*ContainerEntity
	Background tcell.Style
}

func NewCodeBlockEntity

func NewCodeBlockEntity(children []Entity, background tcell.Style) *CodeBlockEntity

func (*CodeBlockEntity) AdjustStyle

func (ce *CodeBlockEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

func (*CodeBlockEntity) Clone

func (ce *CodeBlockEntity) Clone() Entity

func (*CodeBlockEntity) Draw

func (ce *CodeBlockEntity) Draw(screen mauview.Screen, ctx DrawContext)

type ContainerEntity

type ContainerEntity struct {
	*BaseEntity

	// The children of this container entity.
	Children []Entity
	// Number of cells to indent children.
	Indent int
}

func (*ContainerEntity) AdjustStyle

func (ce *ContainerEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

AdjustStyle recursively changes the style of this entity and all its children.

func (*ContainerEntity) CalculateBuffer

func (ce *ContainerEntity) CalculateBuffer(width, startX int, ctx DrawContext) int

CalculateBuffer prepares this entity and all its children for rendering with the given parameters

func (*ContainerEntity) Clone

func (ce *ContainerEntity) Clone() Entity

Clone creates a deep copy of this base entity.

func (*ContainerEntity) Draw

func (ce *ContainerEntity) Draw(screen mauview.Screen, ctx DrawContext)

Draw draws this entity onto the given mauview Screen.

func (*ContainerEntity) IsEmpty added in v0.3.0

func (ce *ContainerEntity) IsEmpty() bool

func (*ContainerEntity) PlainText

func (ce *ContainerEntity) PlainText() string

PlainText returns the plaintext content in this entity and all its children.

func (*ContainerEntity) String

func (ce *ContainerEntity) String() string

String returns a textual representation of this BaseEntity struct.

type DrawContext added in v0.3.0

type DrawContext struct {
	IsSelected   bool
	BareMessages bool
}

type Entity

type Entity interface {
	// AdjustStyle recursively changes the style of the entity and all its children.
	AdjustStyle(AdjustStyleFunc, AdjustStyleReason) Entity
	// Draw draws the entity onto the given mauview Screen.
	Draw(screen mauview.Screen, ctx DrawContext)
	// IsBlock returns whether or not it's a block-type entity.
	IsBlock() bool
	// GetTag returns the HTML tag of the entity.
	GetTag() string
	// PlainText returns the plaintext content in the entity and all its children.
	PlainText() string
	// String returns a string representation of the entity struct.
	String() string
	// Clone creates a deep copy of the entity.
	Clone() Entity

	// Height returns the render height of the entity.
	Height() int
	// CalculateBuffer prepares the entity and all its children for rendering with the given parameters
	CalculateBuffer(width, startX int, ctx DrawContext) int

	IsEmpty() bool
	// contains filtered or unexported methods
}

func Parse

func Parse(prefs *config.UserPreferences, room *rooms.Room, content *event.MessageEventContent, evt *muksevt.Event, senderDisplayname string) Entity

Parse parses a HTML-formatted Matrix event into a UIMessage.

func TextToEntity added in v0.3.0

func TextToEntity(text string, eventID id.EventID, linkify bool) Entity

type HorizontalLineEntity

type HorizontalLineEntity struct {
	*BaseEntity
}

func NewHorizontalLineEntity

func NewHorizontalLineEntity() *HorizontalLineEntity

func (*HorizontalLineEntity) AdjustStyle

func (he *HorizontalLineEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

func (*HorizontalLineEntity) Clone

func (he *HorizontalLineEntity) Clone() Entity

func (*HorizontalLineEntity) Draw

func (he *HorizontalLineEntity) Draw(screen mauview.Screen, ctx DrawContext)

func (*HorizontalLineEntity) PlainText

func (he *HorizontalLineEntity) PlainText() string

func (*HorizontalLineEntity) String

func (he *HorizontalLineEntity) String() string

type ListEntity

type ListEntity struct {
	*ContainerEntity
	Ordered bool
	Start   int
}

func NewListEntity

func NewListEntity(ordered bool, start int, children []Entity) *ListEntity

func (*ListEntity) AdjustStyle

func (le *ListEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

func (*ListEntity) Clone

func (le *ListEntity) Clone() Entity

func (*ListEntity) Draw

func (le *ListEntity) Draw(screen mauview.Screen, ctx DrawContext)

func (*ListEntity) PlainText

func (le *ListEntity) PlainText() string

func (*ListEntity) String

func (le *ListEntity) String() string

type SpoilerEntity added in v0.3.0

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

func NewSpoilerEntity added in v0.3.0

func NewSpoilerEntity(visible *ContainerEntity, reason string) *SpoilerEntity

func (*SpoilerEntity) AdjustStyle added in v0.3.0

func (se *SpoilerEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

func (*SpoilerEntity) CalculateBuffer added in v0.3.0

func (se *SpoilerEntity) CalculateBuffer(width, startX int, ctx DrawContext) int

func (*SpoilerEntity) Clone added in v0.3.0

func (se *SpoilerEntity) Clone() Entity

func (*SpoilerEntity) Draw added in v0.3.0

func (se *SpoilerEntity) Draw(screen mauview.Screen, ctx DrawContext)

func (*SpoilerEntity) GetTag added in v0.3.0

func (se *SpoilerEntity) GetTag() string

func (*SpoilerEntity) Height added in v0.3.0

func (se *SpoilerEntity) Height() int

func (*SpoilerEntity) IsBlock added in v0.3.0

func (se *SpoilerEntity) IsBlock() bool

func (*SpoilerEntity) IsEmpty added in v0.3.0

func (se *SpoilerEntity) IsEmpty() bool

func (*SpoilerEntity) PlainText added in v0.3.0

func (se *SpoilerEntity) PlainText() string

func (*SpoilerEntity) String added in v0.3.0

func (se *SpoilerEntity) String() string

type TextEntity

type TextEntity struct {
	*BaseEntity
	// Text in this entity.
	Text string
	// contains filtered or unexported fields
}

func NewTextEntity

func NewTextEntity(text string) *TextEntity

NewTextEntity creates a new text-only Entity.

func (*TextEntity) AdjustStyle

func (te *TextEntity) AdjustStyle(fn AdjustStyleFunc, reason AdjustStyleReason) Entity

func (*TextEntity) CalculateBuffer

func (te *TextEntity) CalculateBuffer(width, startX int, ctx DrawContext) int

func (*TextEntity) Clone

func (te *TextEntity) Clone() Entity

func (*TextEntity) Draw

func (te *TextEntity) Draw(screen mauview.Screen, ctx DrawContext)

func (*TextEntity) IsEmpty added in v0.3.0

func (te *TextEntity) IsEmpty() bool

func (*TextEntity) PlainText

func (te *TextEntity) PlainText() string

func (*TextEntity) String

func (te *TextEntity) String() string

Jump to

Keyboard shortcuts

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