mrkdwn

package module
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: MIT Imports: 9 Imported by: 0

README

html-to-mrkdwn-go

Test Go Reference Go Report Card

Convert HTML to Slack's mrkdwn format.

package main

import (
	"fmt"

	mrkdwn "github.com/matsubara0507/html-to-mrkdwn-go"
)

func main() {
	html := `
		<p><strong>Hello</strong> <a href="https://example.com">cruel</a> <em>world</em>!</p>
		<p><img src="https://media.giphy.com/media/5xtDarEbygs3Pu7p3jO/giphy.gif"></p>
	`
	md, err := mrkdwn.FromHTML(html)
	if err != nil {
		panic(err)
	}
	fmt.Println(md.Text)
	// *Hello*<https://example.com|cruel>  _world_!
	//
	// https://media.giphy.com/media/5xtDarEbygs3Pu7p3jO/giphy.gif
}

This package is greatly inspired by html-to-mrkdwn npm package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonmarkRules

func CommonmarkRules() (rules []md.Rule)

ref: html-to-markdown/commonmark.go

func FirstImage

func FirstImage(html string) (string, error)

func SlackEscape

func SlackEscape(text string) string

func SlackHeadingRule

func SlackHeadingRule() md.Rule

func SlackImagesRule

func SlackImagesRule() md.Rule

func SlackLinkRule

func SlackLinkRule() md.Rule

func SlackListItemRule

func SlackListItemRule() md.Rule

func SlackPlugin

func SlackPlugin() md.Plugin

Types

type Mrkdwn

type Mrkdwn struct {
	Text  string
	Image string
}

func FromHTML

func FromHTML(html string) (*Mrkdwn, error)

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL