pkg

package
v0.0.0-...-d7e1556 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package latex is a LaTeX renderer for the Blackfriday Markdown processor.

Example
package main

import (
	"os"

	bflatex "github.com/moisespsena-go/md2latex/pkg"
	bf "github.com/russross/blackfriday/v2"
)

func main() {
	const input = `<!-- data
created: 2022-03-25T14:44:40-03:00
modified: 2022-03-25T14:44:50-03:00
type: Checklist
-->

# Section

Some _Markdown_ text.

## Subsection

Foobar.

` + "```" + `[mdt:skip]plantuml:md-sample-class
@startuml
class Test
@enduml
` + "```"

	extensions := bf.CommonExtensions | bf.Titleblock
	renderer := &bflatex.Renderer{Opts: bflatex.Opts{
		Author:    "John Doe",
		Languages: "english,french",
		Flags:     bflatex.TOC,
	}}
	md := bf.New(bf.WithExtensions(extensions))

	ast := md.Parse([]byte(input))

	renderer.Render(os.Stdout, ast)
}
Output:

\section{Section}
Some \emph{Markdown} text.

\subsection{Subsection}
Foobar.

Index

Examples

Constants

View Source
const Quotation = "quotation"

Variables

View Source
var DefaultHeaders = []string{
	`chapter`,
	`section`,
	`subsection`,
	`subsubsection`,
	`paragraph`,
	`subparagraph`,
	`textbf`,
}
View Source
var TStackedDict = &gad.Type{Parent: gad.TBase, TypeName: "StackedDict"}
View Source
var WriteString = io.WriteString

Functions

func Exec

func Exec(cfg RunConfig) (err error)

func FormatFileName

func FormatFileName(fmt, name string) string

func Run

func Run(w io.Writer, input []byte, opts ...bf.Option)

Run prints out the whole document with CompletePage and TOC flags enabled.

func WriteByte

func WriteByte(w io.Writer, b byte) (n int, err error)

func WriteRune

func WriteRune(w io.Writer, r rune) (n int, err error)

Types

type Code

type Code struct {
	Quotation         string   `mapstructure:"quotation"`
	QuotationAuthored string   `mapstructure:"quotation_authored"`
	List              string   `mapstructure:"list"`
	Enum              string   `mapstructure:"enum"`
	Definition        string   `mapstructure:"definition"`
	Headers           []string `mapstructure:"default_headers"`

	DefaultInlineCodeLang string `mapstructure:"default_inline_code_lang"`

	Wrap struct {
		Table map[string]*Wrap `mapstructure:"table"`
	} `mapstructure:"wrap"`
}

type CodeHandler

type CodeHandler func(r *Renderer, w io.Writer, node *bf.Node, arg, data []byte) error

type DevNull

type DevNull struct {
}

func (DevNull) Close

func (DevNull) Close() error

func (DevNull) Write

func (DevNull) Write(p []byte) (int, error)

type DirFS

type DirFS string

func (DirFS) CreateAll

func (d DirFS) CreateAll(name string) (w io.WriteCloser, err error)

func (DirFS) Open

func (dir DirFS) Open(name string) (fs.File, error)

func (DirFS) Sub

func (d DirFS) Sub(dir string) (f fs.FS, err error)

type DoneCodeHandler

type DoneCodeHandler func(w io.Writer) error

func LoadScripts

func LoadScripts(codeHandlers map[string]CodeHandler, cfg *RunConfig) (done []DoneCodeHandler, err error)

type FS

type FS interface {
	fs.FS
	fs.SubFS
	CreateAll(name string) (w io.WriteCloser, err error)
}

type Flag

type Flag int

Flag controls the options of the renderer.

const (
	FlagsNone Flag = 0

	// CompletePage generates a complete LaTeX document, preamble included.
	CompletePage Flag = 1 << iota

	// ChapterTitle uses the titleblock (if the extension is on) as chapter title.
	// Ignored when CompletePage is on.
	ChapterTitle

	// No paragraph indentation.
	NoParIndent

	SkipLinks // Never link.
	Safelink  // Only link to trusted protocols.

	TOC // Generate the table of content.
)

type ImagePathReplacer

type ImagePathReplacer struct {
	Searcher string `mapstructure:"s"`
	Replacer string `mapstructure:"r"`
	// contains filtered or unexported fields
}

func (*ImagePathReplacer) Replace

func (r *ImagePathReplacer) Replace(s string) (v string, ok bool)

type LatexRaw

type LatexRaw struct {
	Dst   string
	Value []string
}

type Opts

type Opts struct {

	// Flags allow customizing this renderer's behavior.
	Flags Flag `mapstructure:"flags"`

	// The document author displayed by the `\maketitle` command.
	// This will only display if the `Titleblock` extension is on and a title is
	// present.
	Author string `mapstructure:"author"`

	// The languages to be used by the `babel` package.
	// Languages must be comma-spearated.
	Languages string `mapstructure:"languages"`

	Code `mapstructure:"code"`

	WebImagesDir         string               `mapstructure:"web_images_dir"`
	WebImagesDirOverride string               `mapstructure:"web_images_dir_override"`
	ImagePathReplacers   []*ImagePathReplacer `mapstructure:"image_path_replacers"`

	Titled bool `mapstructure:"titled"`

	HtmlBlockHandler func(r *Renderer, w io.Writer, node *bf.Node, entering bool) bf.WalkStatus `mapstructure:"htmlBlockHandler"`
	CodeHandler      map[string]CodeHandler
}

type PathFS

type PathFS struct {
	FS      FS
	Dir     string
	RootDir string
}

func (*PathFS) CreateAll

func (c *PathFS) CreateAll(name string) (w io.WriteCloser, err error)

func (*PathFS) Open

func (c *PathFS) Open(name string) (fs.File, error)

func (*PathFS) ReadFile

func (c *PathFS) ReadFile(out io.Writer, pth string) error

func (PathFS) Sub

func (c PathFS) Sub(name string) (sub *PathFS, err error)

type Renderer

type Renderer struct {
	Opts

	OnError    func(err error)
	Downloaded func(name, url string)
	// contains filtered or unexported fields
}

Renderer is a type that implements the Renderer interface for LaTeX output.

func NewRenderer

func NewRenderer(opts Opts) *Renderer

func (*Renderer) Cmd

func (r *Renderer) Cmd(w io.Writer, command string, entering bool)

func (*Renderer) Env

func (r *Renderer) Env(w io.Writer, environment string, entering bool, args ...string)

func (*Renderer) Escape

func (r *Renderer) Escape(w io.Writer, t []byte)

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, ast *bf.Node)

Render prints out the whole document from the ast, header and footer included.

func (*Renderer) RenderFooter

func (r *Renderer) RenderFooter(w io.Writer, ast *bf.Node)

RenderHeader prints the '\end{document}' if CompletePage is on.

func (*Renderer) RenderHeader

func (r *Renderer) RenderHeader(w io.Writer, ast *bf.Node)

RenderHeader prints the LaTeX preamble if CompletePage is on.

func (*Renderer) RenderNode

func (r *Renderer) RenderNode(w io.Writer, node *bf.Node, entering bool) bf.WalkStatus

RenderNode renders a single node. As a rule of thumb to enforce consistency, each node is responsible for appending the needed line breaks. Line breaks are never prepended.

type RequestOptions

type RequestOptions struct {
	Header http.Header
}

type RunConfig

type RunConfig struct {
	Now            time.Time
	FS             FS
	Input          string
	Output         string
	JoinedOutput   string
	CodeScriptsDir string
	GadModulesPath []string
	ScriptEnv      []string
	LatexRawFiles  map[string]*LatexRaw
	Opts           Opts
	PathFS
}

type Wrap

type Wrap struct {
	Before string `mapstructure:"before"`
	After  string `mapstructure:"after"`
}

Jump to

Keyboard shortcuts

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