replacer

package module
v0.0.0-...-a2119cf Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: MIT Imports: 6 Imported by: 1

README

goldmark-text-replacer

GoDoc

Goldmark text replacer extension.

md := goldmark.New(
    replacer.Options(
        "(c)", "©",
        "(r)", "®",
        "...", "…",
        "(tm)", "™",
        "<-", "&larr;",
        "->", "&rarr;",
        "<->", "&harr;",
    ),
)
var source = []byte("(c)Dmitry Sedykh")
err := md.Convert(source, os.Stdout)
if err != nil {
    log.Fatal(err)
}

Documentation

Overview

Package replacer is a extension for the goldmark (http://github.com/yuin/goldmark).

This extension adds support for authomaticaly replacing text in markdowns.

Example
package main

import (
	"log"
	"os"

	replacer "github.com/mdigger/goldmark-text-replacer"
	"github.com/yuin/goldmark"
)

func main() {
	md := goldmark.New(
		replacer.Options(
			"(c)", "&copy;",
			"(r)", "&reg;",
			"...", "&hellip;",
			"(tm)", "&trade;",
			"<-", "&larr;",
			"->", "&rarr;",
			"<->", "&harr;",
			"--", "&mdash;",
		),
	)
	var source = []byte("(c)Dmitry Sedykh")
	err := md.Convert(source, os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

<p>©Dmitry Sedykh</p>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(oldnew ...string) goldmark.Extender

New returns a new Replacer from a list of old, new string pairs. Replacements are performed in the order they appear in the target string, without overlapping matches. The old string comparisons are done in argument order.

It's panics if given an odd number of arguments.

func Options

func Options(oldnew ...string) goldmark.Option

Options return initialized text replacer goldmark.Option.

Types

This section is empty.

Jump to

Keyboard shortcuts

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