Version: v0.0.0-...-39237e8 Latest Latest

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

Go to latest
Published: May 9, 2021 License: BSD-2-Clause Imports: 10 Imported by: 0




View Source
const CSS = `` /* 9670-byte string literal not displayed */

CSS we use. If Converter.FullHTML is true, it's included as part of generated HTML. Otherwise you have to provide HTML wrapper where you can either embed this CSS as <style>${css}</style> or reference it as <link rel="stylesheet" href="${css_file}">

View Source
const CSSPlus = `
.breadcrumbs {


CSSPlus is CSS additional to what Notion CSS has


This section is empty.


func CleanAttributeValue

func CleanAttributeValue(v string) string

CleanAttributeValue cleans value of an attribute

func EscapeHTML

func EscapeHTML(s string) string

EscapeHTML escapes HTML in the same way as Notion.

func FilePathFromPageCoverURL

func FilePathFromPageCoverURL(uri string, block *notionapi.Block) string

func GetBlockColorClass

func GetBlockColorClass(block *notionapi.Block) string

GetBlockColorClass returns "block-color-" + format.block_color which is name of css class for different colors

func GetDownloadedFileName

func GetDownloadedFileName(uri string, block *notionapi.Block) string

func HTMLFileNameForPage

func HTMLFileNameForPage(page *notionapi.Page) string

HTMLFileNameForPage returns file name for html file

func ToHTML

func ToHTML(page *notionapi.Page, crumbs []Crumb) []byte

ToHTML converts a page to HTML


type BlockRenderFunc

type BlockRenderFunc func(block *notionapi.Block) bool

BlockRenderFunc is a function for rendering a particular block

type Converter

type Converter struct {
	// Buf is where HTML is being written to
	Buf  *bytes.Buffer
	Page *notionapi.Page

	// tracks current number of numbered lists
	ListNo int

	// if true tries to render as closely to Notion's HTML
	// export as possible
	NotionCompat bool

	// UseKatexToRenderEquation requires katex CLI to be installed
	// npm install -g katex
	// If true, converts BlockEquation to HTML using katex
	// Tested with katex 0.10.2
	UseKatexToRenderEquation bool

	// If UseKatexToRenderEquation is true, you can provide path to katex binary
	// here. Otherwise we'll try to locate it using exec.LookPath()
	// If UseKatexToRenderEquation is true but we can't locate katex binary
	// we'll return an error
	KatexPath string

	// if true, adds <a href="#{$NotionID}">svg(anchor-icon)</a>
	// to h1/h2/h3
	AddHeaderAnchor bool

	// allows over-riding rendering of specific blocks
	// return false for default rendering
	RenderBlockOverride BlockRenderFunc

	// RewriteURL allows re-writing URLs e.g. to convert inter-notion URLs
	// to destination URLs
	RewriteURL func(url string) string

	// Returns URL for a title cell (that links to a page)
	TableTitleCellURLOverride func(tv *notionapi.TableView, row, col int) string

	// if true, generates stand-alone HTML with inline CSS
	// otherwise it's just the inner part going inside the body
	FullHTML bool

	// we need this to properly render ordered and numbered lists
	CurrBlocks   []*notionapi.Block
	CurrBlockIdx int

	PageByIDProvider PageByIDProvider

	// data provided by they caller, useful when providing
	// RenderBlockOverride
	Data interface{}
	// contains filtered or unexported fields

Converter converts a Page to HTML

func NewConverter

func NewConverter(page *notionapi.Page) *Converter

NewConverter returns customizable HTML renderer

func (*Converter) A

func (c *Converter) A(uri, text, cls string)

A writes <a></a> element to output

func (*Converter) DefaultRenderFunc

func (c *Converter) DefaultRenderFunc(blockType string) func(*notionapi.Block)

DefaultRenderFunc returns a defult rendering function for a type of a given block

func (*Converter) FormatDate

func (c *Converter) FormatDate(d *notionapi.Date) string

FormatDate formats the data

func (*Converter) GetInlineContent

func (c *Converter) GetInlineContent(blocks []*notionapi.TextSpan) string

GetInlineContent is like RenderInlines but instead of writing to output buffer, we return it as string

func (*Converter) IsNextBlockOfType

func (c *Converter) IsNextBlockOfType(t string) bool

IsNextBlockOfType returns true if next block is of a given type

func (*Converter) IsPrevBlockOfType

func (c *Converter) IsPrevBlockOfType(t string) bool

IsPrevBlockOfType returns true if previous block is of a given type

func (*Converter) NextBlock

func (c *Converter) NextBlock() *notionapi.Block

NextBlock is a block preceding current block

func (*Converter) PageByID

func (c *Converter) PageByID(pageID string) *notionapi.Page

PageByID returns Page given its ID

func (*Converter) PopBuffer

func (c *Converter) PopBuffer() *bytes.Buffer

PopBuffer pops a buffer

func (*Converter) PrevBlock

func (c *Converter) PrevBlock() *notionapi.Block

PrevBlock is a block preceding current block

func (*Converter) Printf

func (c *Converter) Printf(format string, args ...interface{})

func (*Converter) PushNewBuffer

func (c *Converter) PushNewBuffer()

PushNewBuffer creates a new buffer and sets Buf to it

func (*Converter) RenderAudio

func (c *Converter) RenderAudio(block *notionapi.Block)

RenderAudio renders BlockAudio

func (*Converter) RenderBlock

func (c *Converter) RenderBlock(block *notionapi.Block)

RenderBlock renders a block to html

func (*Converter) RenderBookmark

func (c *Converter) RenderBookmark(block *notionapi.Block)

RenderBookmark renders BlockBookmark

func (*Converter) RenderBreadcrumb

func (c *Converter) RenderBreadcrumb(block *notionapi.Block)

RenderBreadcrumb renders BlockBreadcrumb

func (*Converter) RenderBulletedList

func (c *Converter) RenderBulletedList(block *notionapi.Block)

RenderBulletedList renders BlockBulletedList

func (*Converter) RenderCVPage

func (c *Converter) RenderCVPage(page *notionapi.Page, crumbs []Crumb, title string)

func (*Converter) RenderCallout

func (c *Converter) RenderCallout(block *notionapi.Block)

RenderCallout renders BlockCallout

func (*Converter) RenderCaption

func (c *Converter) RenderCaption(block *notionapi.Block)

RenderCaption renders a caption

func (*Converter) RenderChildren

func (c *Converter) RenderChildren(block *notionapi.Block)

func (*Converter) RenderCode

func (c *Converter) RenderCode(block *notionapi.Block)

RenderCode renders BlockCode

func (*Converter) RenderCodepen

func (c *Converter) RenderCodepen(block *notionapi.Block)

RenderCodepen renders BlockCodepen

func (*Converter) RenderCollectionView

func (c *Converter) RenderCollectionView(block *notionapi.Block)

RenderCollectionView renders BlockCollectionView

func (*Converter) RenderCollectionViewPage

func (c *Converter) RenderCollectionViewPage(block *notionapi.Block)

RenderCollectionViewPage renders BlockCollectionViewPage

func (*Converter) RenderColumn

func (c *Converter) RenderColumn(block *notionapi.Block)

RenderColumn renders BlockColumn Its parent is BlockColumnList

func (*Converter) RenderColumnList

func (c *Converter) RenderColumnList(block *notionapi.Block)

RenderColumnList renders BlockColumnList Its children are BlockColumn

func (*Converter) RenderCrumbs

func (c *Converter) RenderCrumbs(crumbs []Crumb, title string)

RenderCrumbs alternate breadcrumb renderer

func (*Converter) RenderDivider

func (c *Converter) RenderDivider(block *notionapi.Block)

RenderDivider renders BlockDivider

func (*Converter) RenderDrive

func (c *Converter) RenderDrive(block *notionapi.Block)

RenderDrive renders BlockDrive

func (*Converter) RenderEmbed

func (c *Converter) RenderEmbed(block *notionapi.Block)

RenderEmbed renders BlockEmbed

func (*Converter) RenderEquation

func (c *Converter) RenderEquation(block *notionapi.Block)

RenderEquation renders BlockEquation

func (*Converter) RenderFigma

func (c *Converter) RenderFigma(block *notionapi.Block)

RenderFigma renders BlockFigma

func (*Converter) RenderFile

func (c *Converter) RenderFile(block *notionapi.Block)

RenderFile renders BlockFile

func (*Converter) RenderGist

func (c *Converter) RenderGist(block *notionapi.Block)

RenderGist renders BlockGist

func (*Converter) RenderHeader

func (c *Converter) RenderHeader(block *notionapi.Block)

RenderHeader renders BlockHeader

func (*Converter) RenderHeaderLevel

func (c *Converter) RenderHeaderLevel(block *notionapi.Block, level int)

RenderHeaderLevel renders BlockHeader, SubHeader and SubSubHeader

func (*Converter) RenderImage

func (c *Converter) RenderImage(block *notionapi.Block)

RenderImage renders BlockImage

func (*Converter) RenderInline

func (c *Converter) RenderInline(b *notionapi.TextSpan)

RenderInline renders inline block

func (*Converter) RenderInlines

func (c *Converter) RenderInlines(blocks []*notionapi.TextSpan)

RenderInlines renders inline blocks

func (*Converter) RenderMaps

func (c *Converter) RenderMaps(block *notionapi.Block)

RenderMaps renders BlockMaps

func (*Converter) RenderNumberedList

func (c *Converter) RenderNumberedList(block *notionapi.Block)

RenderNumberedList renders BlockNumberedList

func (*Converter) RenderPDF

func (c *Converter) RenderPDF(block *notionapi.Block)

RenderPDF renders BlockPDF

func (*Converter) RenderPage

func (c *Converter) RenderPage(block *notionapi.Block)

RenderPage renders BlockPage

func (*Converter) RenderQuote

func (c *Converter) RenderQuote(block *notionapi.Block)

RenderQuote renders BlockQuote

func (*Converter) RenderSubHeader

func (c *Converter) RenderSubHeader(block *notionapi.Block)

RenderSubHeader renders BlockSubHeader

func (*Converter) RenderSubSubHeader

func (c *Converter) RenderSubSubHeader(block *notionapi.Block)

RenderSubSubHeader renders BlocSubSubkHeader

func (*Converter) RenderTableOfContents

func (c *Converter) RenderTableOfContents(block *notionapi.Block)

RenderTableOfContents renders BlockTableOfContents

func (*Converter) RenderText

func (c *Converter) RenderText(block *notionapi.Block)

RenderText renders BlockText

func (*Converter) RenderTodo

func (c *Converter) RenderTodo(block *notionapi.Block)

RenderTodo renders BlockTodo

func (*Converter) RenderToggle

func (c *Converter) RenderToggle(block *notionapi.Block)

RenderToggle renders BlockToggle

func (*Converter) RenderTweet

func (c *Converter) RenderTweet(block *notionapi.Block)

RenderTweet renders BlockTweet

func (*Converter) RenderVideo

func (c *Converter) RenderVideo(block *notionapi.Block)

RenderVideo renders BlockVideo

func (*Converter) RewrittenURL

func (c *Converter) RewrittenURL(uri string) string

RewrittenURL optionally transforms the url via the function provided by the user

func (*Converter) ToHTML

func (c *Converter) ToHTML(crumbs []Crumb) ([]byte, error)

ToHTML renders a page to html

type Crumb

type Crumb struct {
	Name string
	Link string
	Skip bool

type PageByIDFromPages

type PageByIDFromPages struct {
	// contains filtered or unexported fields

func NewPageByIDFromPages

func NewPageByIDFromPages(pages []*notionapi.Page) *PageByIDFromPages

NewPageByIDFromPages creates PageByIDProvider from array of pages

func (*PageByIDFromPages) PageByID

func (p *PageByIDFromPages) PageByID(pageID string) *notionapi.Page

type PageByIDProvider

type PageByIDProvider interface {
	PageByID(id string) *notionapi.Page

Jump to

Keyboard shortcuts

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