vendor dependencies with dep

This commit is contained in:
dhax 2017-09-25 20:20:52 +02:00
parent 93d8310491
commit 1384296a47
2712 changed files with 965742 additions and 0 deletions

24
vendor/github.com/jaytaylor/html2text/.gitignore generated vendored Normal file
View file

@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof

14
vendor/github.com/jaytaylor/html2text/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,14 @@
language: go
go:
- tip
- 1.8
- 1.7
- 1.6
- 1.5
- 1.4
- 1.3
- 1.2
notifications:
email:
on_success: change
on_failure: always

22
vendor/github.com/jaytaylor/html2text/LICENSE generated vendored Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Jay Taylor
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

137
vendor/github.com/jaytaylor/html2text/README.md generated vendored Normal file
View file

@ -0,0 +1,137 @@
# html2text
[![Documentation](https://godoc.org/github.com/jaytaylor/html2text?status.svg)](https://godoc.org/github.com/jaytaylor/html2text)
[![Build Status](https://travis-ci.org/jaytaylor/html2text.svg?branch=master)](https://travis-ci.org/jaytaylor/html2text)
[![Report Card](https://goreportcard.com/badge/github.com/jaytaylor/html2text)](https://goreportcard.com/report/github.com/jaytaylor/html2text)
### Converts HTML into text
## Introduction
Ensure your emails are readable by all!
Turns HTML into raw text, useful for sending fancy HTML emails with a equivalently nicely formatted TXT document as a fallback (e.g. for people who don't allow HTML emails or have other display issues).
html2text is a simple golang package for rendering HTML into plaintext.
There are still lots of improvements to be had, but FWIW this has worked fine for my [basic] HTML-2-text needs.
It requires go 1.x or newer ;)
## Download the package
```bash
go get github.com/jaytaylor/html2text
```
## Example usage
```go
package main
import (
"fmt"
"github.com/jaytaylor/html2text"
)
func main() {
inputHTML := `
<html>
<head>
<title>My Mega Service</title>
<link rel=\"stylesheet\" href=\"main.css\">
<style type=\"text/css\">body { color: #fff; }</style>
</head>
<body>
<div class="logo">
<a href="http://jaytaylor.com/"><img src="/logo-image.jpg" alt="Mega Service"/></a>
</div>
<h1>Welcome to your new account on my service!</h1>
<p>
Here is some more information:
<ul>
<li>Link 1: <a href="https://example.com">Example.com</a></li>
<li>Link 2: <a href="https://example2.com">Example2.com</a></li>
<li>Something else</li>
</ul>
</p>
<table>
<thead>
<tr><th>Header 1</th><th>Header 2</th></tr>
</thead>
<tfoot>
<tr><td>Footer 1</td><td>Footer 2</td></tr>
</tfoot>
<tbody>
<tr><td>Row 1 Col 1</td><td>Row 1 Col 2</td></tr>
<tr><td>Row 2 Col 1</td><td>Row 2 Col 2</td></tr>
</tbody>
</table>
</body>
</html>`
text, err := FromString(inputHTML, Options{PrettyTables: true})
if err != nil {
panic(err)
}
fmt.Println(text)
}
```
Output:
```
Mega Service ( http://jaytaylor.com/ )
******************************************
Welcome to your new account on my service!
******************************************
Here is some more information:
* Link 1: Example.com ( https://example.com )
* Link 2: Example2.com ( https://example2.com )
* Something else
+-------------+-------------+
| HEADER 1 | HEADER 2 |
+-------------+-------------+
| Row 1 Col 1 | Row 1 Col 2 |
| Row 2 Col 1 | Row 2 Col 2 |
+-------------+-------------+
| FOOTER 1 | FOOTER 2 |
+-------------+-------------+
```
## Unit-tests
Running the unit-tests is straightforward and standard:
```bash
go test
```
# License
Permissive MIT license.
## Contact
You are more than welcome to open issues and send pull requests if you find a bug or want a new feature.
If you appreciate this library please feel free to drop me a line and tell me! It's always nice to hear from people who have benefitted from my work.
Email: jay at (my github username).com
Twitter: [@jtaylor](https://twitter.com/jtaylor)

460
vendor/github.com/jaytaylor/html2text/html2text.go generated vendored Normal file
View file

@ -0,0 +1,460 @@
package html2text
import (
"bytes"
"io"
"regexp"
"strings"
"unicode"
"github.com/olekukonko/tablewriter"
"github.com/ssor/bom"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
)
// Options provide toggles and overrides to control specific rendering behaviors.
type Options struct {
PrettyTables bool // Turns on pretty ASCII rendering for table elements.
}
// FromHTMLNode renders text output from a pre-parsed HTML document.
func FromHTMLNode(doc *html.Node, o ...Options) (string, error) {
var options Options
if len(o) > 0 {
options = o[0]
}
ctx := textifyTraverseContext{
buf: bytes.Buffer{},
options: options,
}
if err := ctx.traverse(doc); err != nil {
return "", err
}
text := strings.TrimSpace(newlineRe.ReplaceAllString(
strings.Replace(ctx.buf.String(), "\n ", "\n", -1), "\n\n"),
)
return text, nil
}
// FromReader renders text output after parsing HTML for the specified
// io.Reader.
func FromReader(reader io.Reader, options ...Options) (string, error) {
newReader, err := bom.NewReaderWithoutBom(reader)
if err != nil {
return "", err
}
doc, err := html.Parse(newReader)
if err != nil {
return "", err
}
return FromHTMLNode(doc, options...)
}
// FromString parses HTML from the input string, then renders the text form.
func FromString(input string, options ...Options) (string, error) {
bs := bom.CleanBom([]byte(input))
text, err := FromReader(bytes.NewReader(bs), options...)
if err != nil {
return "", err
}
return text, nil
}
var (
spacingRe = regexp.MustCompile(`[ \r\n\t]+`)
newlineRe = regexp.MustCompile(`\n\n+`)
)
// traverseTableCtx holds text-related context.
type textifyTraverseContext struct {
buf bytes.Buffer
prefix string
tableCtx tableTraverseContext
options Options
endsWithSpace bool
justClosedDiv bool
blockquoteLevel int
lineLength int
}
// tableTraverseContext holds table ASCII-form related context.
type tableTraverseContext struct {
header []string
body [][]string
footer []string
tmpRow int
isInFooter bool
}
func (tableCtx *tableTraverseContext) init() {
tableCtx.body = [][]string{}
tableCtx.header = []string{}
tableCtx.footer = []string{}
tableCtx.isInFooter = false
tableCtx.tmpRow = 0
}
func (ctx *textifyTraverseContext) handleElement(node *html.Node) error {
ctx.justClosedDiv = false
switch node.DataAtom {
case atom.Br:
return ctx.emit("\n")
case atom.H1, atom.H2, atom.H3:
subCtx := textifyTraverseContext{}
if err := subCtx.traverseChildren(node); err != nil {
return err
}
str := subCtx.buf.String()
dividerLen := 0
for _, line := range strings.Split(str, "\n") {
if lineLen := len([]rune(line)); lineLen-1 > dividerLen {
dividerLen = lineLen - 1
}
}
var divider string
if node.DataAtom == atom.H1 {
divider = strings.Repeat("*", dividerLen)
} else {
divider = strings.Repeat("-", dividerLen)
}
if node.DataAtom == atom.H3 {
return ctx.emit("\n\n" + str + "\n" + divider + "\n\n")
}
return ctx.emit("\n\n" + divider + "\n" + str + "\n" + divider + "\n\n")
case atom.Blockquote:
ctx.blockquoteLevel++
ctx.prefix = strings.Repeat(">", ctx.blockquoteLevel) + " "
if err := ctx.emit("\n"); err != nil {
return err
}
if ctx.blockquoteLevel == 1 {
if err := ctx.emit("\n"); err != nil {
return err
}
}
if err := ctx.traverseChildren(node); err != nil {
return err
}
ctx.blockquoteLevel--
ctx.prefix = strings.Repeat(">", ctx.blockquoteLevel)
if ctx.blockquoteLevel > 0 {
ctx.prefix += " "
}
return ctx.emit("\n\n")
case atom.Div:
if ctx.lineLength > 0 {
if err := ctx.emit("\n"); err != nil {
return err
}
}
if err := ctx.traverseChildren(node); err != nil {
return err
}
var err error
if !ctx.justClosedDiv {
err = ctx.emit("\n")
}
ctx.justClosedDiv = true
return err
case atom.Li:
if err := ctx.emit("* "); err != nil {
return err
}
if err := ctx.traverseChildren(node); err != nil {
return err
}
return ctx.emit("\n")
case atom.B, atom.Strong:
subCtx := textifyTraverseContext{}
subCtx.endsWithSpace = true
if err := subCtx.traverseChildren(node); err != nil {
return err
}
str := subCtx.buf.String()
return ctx.emit("*" + str + "*")
case atom.A:
linkText := ""
// For simple link element content with single text node only, peek at the link text.
if node.FirstChild != nil && node.FirstChild.NextSibling == nil && node.FirstChild.Type == html.TextNode {
linkText = node.FirstChild.Data
}
// If image is the only child, take its alt text as the link text.
if img := node.FirstChild; img != nil && node.LastChild == img && img.DataAtom == atom.Img {
if altText := getAttrVal(img, "alt"); altText != "" {
if err := ctx.emit(altText); err != nil {
return err
}
}
} else if err := ctx.traverseChildren(node); err != nil {
return err
}
hrefLink := ""
if attrVal := getAttrVal(node, "href"); attrVal != "" {
attrVal = ctx.normalizeHrefLink(attrVal)
// Don't print link href if it matches link element content or if the link is empty.
if attrVal != "" && linkText != attrVal {
hrefLink = "( " + attrVal + " )"
}
}
return ctx.emit(hrefLink)
case atom.P, atom.Ul:
return ctx.paragraphHandler(node)
case atom.Table, atom.Tfoot, atom.Th, atom.Tr, atom.Td:
if ctx.options.PrettyTables {
return ctx.handleTableElement(node)
} else if node.DataAtom == atom.Table {
return ctx.paragraphHandler(node)
}
return ctx.traverseChildren(node)
case atom.Style, atom.Script, atom.Head:
// Ignore the subtree.
return nil
default:
return ctx.traverseChildren(node)
}
}
// paragraphHandler renders node children surrounded by double newlines.
func (ctx *textifyTraverseContext) paragraphHandler(node *html.Node) error {
if err := ctx.emit("\n\n"); err != nil {
return err
}
if err := ctx.traverseChildren(node); err != nil {
return err
}
return ctx.emit("\n\n")
}
// handleTableElement is only to be invoked when options.PrettyTables is active.
func (ctx *textifyTraverseContext) handleTableElement(node *html.Node) error {
if !ctx.options.PrettyTables {
panic("handleTableElement invoked when PrettyTables not active")
}
switch node.DataAtom {
case atom.Table:
if err := ctx.emit("\n\n"); err != nil {
return err
}
// Re-intialize all table context.
ctx.tableCtx.init()
// Browse children, enriching context with table data.
if err := ctx.traverseChildren(node); err != nil {
return err
}
buf := &bytes.Buffer{}
table := tablewriter.NewWriter(buf)
table.SetHeader(ctx.tableCtx.header)
table.SetFooter(ctx.tableCtx.footer)
table.AppendBulk(ctx.tableCtx.body)
// Render the table using ASCII.
table.Render()
if err := ctx.emit(buf.String()); err != nil {
return err
}
return ctx.emit("\n\n")
case atom.Tfoot:
ctx.tableCtx.isInFooter = true
if err := ctx.traverseChildren(node); err != nil {
return err
}
ctx.tableCtx.isInFooter = false
case atom.Tr:
ctx.tableCtx.body = append(ctx.tableCtx.body, []string{})
if err := ctx.traverseChildren(node); err != nil {
return err
}
ctx.tableCtx.tmpRow++
case atom.Th:
res, err := ctx.renderEachChild(node)
if err != nil {
return err
}
ctx.tableCtx.header = append(ctx.tableCtx.header, res)
case atom.Td:
res, err := ctx.renderEachChild(node)
if err != nil {
return err
}
if ctx.tableCtx.isInFooter {
ctx.tableCtx.footer = append(ctx.tableCtx.footer, res)
} else {
ctx.tableCtx.body[ctx.tableCtx.tmpRow] = append(ctx.tableCtx.body[ctx.tableCtx.tmpRow], res)
}
}
return nil
}
func (ctx *textifyTraverseContext) traverse(node *html.Node) error {
switch node.Type {
default:
return ctx.traverseChildren(node)
case html.TextNode:
data := strings.Trim(spacingRe.ReplaceAllString(node.Data, " "), " ")
return ctx.emit(data)
case html.ElementNode:
return ctx.handleElement(node)
}
}
func (ctx *textifyTraverseContext) traverseChildren(node *html.Node) error {
for c := node.FirstChild; c != nil; c = c.NextSibling {
if err := ctx.traverse(c); err != nil {
return err
}
}
return nil
}
func (ctx *textifyTraverseContext) emit(data string) error {
if data == "" {
return nil
}
var (
lines = ctx.breakLongLines(data)
err error
)
for _, line := range lines {
runes := []rune(line)
startsWithSpace := unicode.IsSpace(runes[0])
if !startsWithSpace && !ctx.endsWithSpace && !strings.HasPrefix(data, ".") {
if err = ctx.buf.WriteByte(' '); err != nil {
return err
}
ctx.lineLength++
}
ctx.endsWithSpace = unicode.IsSpace(runes[len(runes)-1])
for _, c := range line {
if _, err = ctx.buf.WriteString(string(c)); err != nil {
return err
}
ctx.lineLength++
if c == '\n' {
ctx.lineLength = 0
if ctx.prefix != "" {
if _, err = ctx.buf.WriteString(ctx.prefix); err != nil {
return err
}
}
}
}
}
return nil
}
const maxLineLen = 74
func (ctx *textifyTraverseContext) breakLongLines(data string) []string {
// Only break lines when in blockquotes.
if ctx.blockquoteLevel == 0 {
return []string{data}
}
var (
ret = []string{}
runes = []rune(data)
l = len(runes)
existing = ctx.lineLength
)
if existing >= maxLineLen {
ret = append(ret, "\n")
existing = 0
}
for l+existing > maxLineLen {
i := maxLineLen - existing
for i >= 0 && !unicode.IsSpace(runes[i]) {
i--
}
if i == -1 {
// No spaces, so go the other way.
i = maxLineLen - existing
for i < l && !unicode.IsSpace(runes[i]) {
i++
}
}
ret = append(ret, string(runes[:i])+"\n")
for i < l && unicode.IsSpace(runes[i]) {
i++
}
runes = runes[i:]
l = len(runes)
existing = 0
}
if len(runes) > 0 {
ret = append(ret, string(runes))
}
return ret
}
func (ctx *textifyTraverseContext) normalizeHrefLink(link string) string {
link = strings.TrimSpace(link)
link = strings.TrimPrefix(link, "mailto:")
return link
}
// renderEachChild visits each direct child of a node and collects the sequence of
// textuual representaitons separated by a single newline.
func (ctx *textifyTraverseContext) renderEachChild(node *html.Node) (string, error) {
buf := &bytes.Buffer{}
for c := node.FirstChild; c != nil; c = c.NextSibling {
s, err := FromHTMLNode(c, ctx.options)
if err != nil {
return "", err
}
if _, err = buf.WriteString(s); err != nil {
return "", err
}
if c.NextSibling != nil {
if err = buf.WriteByte('\n'); err != nil {
return "", err
}
}
}
return buf.String(), nil
}
func getAttrVal(node *html.Node, attrName string) string {
for _, attr := range node.Attr {
if attr.Key == attrName {
return attr.Val
}
}
return ""
}

973
vendor/github.com/jaytaylor/html2text/html2text_test.go generated vendored Normal file
View file

@ -0,0 +1,973 @@
package html2text
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"regexp"
"strings"
"testing"
)
const destPath = "testdata"
// EnableExtraLogging turns on additional testing log output.
// Extra test logging can be enabled by setting the environment variable
// HTML2TEXT_EXTRA_LOGGING to "1" or "true".
var EnableExtraLogging bool
func init() {
if v := os.Getenv("HTML2TEXT_EXTRA_LOGGING"); v == "1" || v == "true" {
EnableExtraLogging = true
}
}
// TODO Add tests for FromHTMLNode and FromReader.
func TestParseUTF8(t *testing.T) {
htmlFiles := []struct {
file string
keywordShouldNotExist string
keywordShouldExist string
}{
{
"utf8.html",
"学习之道:美国公认学习第一书title",
"次世界冠军赛上,我几近疯狂",
},
{
"utf8_with_bom.xhtml",
"1892年波兰文版序言title",
"种新的波兰文本已成为必要",
},
}
for _, htmlFile := range htmlFiles {
bs, err := ioutil.ReadFile(path.Join(destPath, htmlFile.file))
if err != nil {
t.Fatal(err)
}
text, err := FromReader(bytes.NewReader(bs))
if err != nil {
t.Fatal(err)
}
if !strings.Contains(text, htmlFile.keywordShouldExist) {
t.Fatalf("keyword %s should exists in file %s", htmlFile.keywordShouldExist, htmlFile.file)
}
if strings.Contains(text, htmlFile.keywordShouldNotExist) {
t.Fatalf("keyword %s should not exists in file %s", htmlFile.keywordShouldNotExist, htmlFile.file)
}
}
}
func TestStrippingWhitespace(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
"test text",
"test text",
},
{
" \ttext\ntext\n",
"text text",
},
{
" \na \n\t \n \n a \t",
"a a",
},
{
"test text",
"test text",
},
{
"test&nbsp;&nbsp;&nbsp; text&nbsp;",
"test    text",
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestParagraphsAndBreaks(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
"Test text",
"Test text",
},
{
"Test text<br>",
"Test text",
},
{
"Test text<br>Test",
"Test text\nTest",
},
{
"<p>Test text</p>",
"Test text",
},
{
"<p>Test text</p><p>Test text</p>",
"Test text\n\nTest text",
},
{
"\n<p>Test text</p>\n\n\n\t<p>Test text</p>\n",
"Test text\n\nTest text",
},
{
"\n<p>Test text<br/>Test text</p>\n",
"Test text\nTest text",
},
{
"\n<p>Test text<br> \tTest text<br></p>\n",
"Test text\nTest text",
},
{
"Test text<br><BR />Test text",
"Test text\n\nTest text",
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestTables(t *testing.T) {
testCases := []struct {
input string
tabularOutput string
plaintextOutput string
}{
{
"<table><tr><td></td><td></td></tr></table>",
// Empty table
// +--+--+
// | | |
// +--+--+
"+--+--+\n| | |\n+--+--+",
"",
},
{
"<table><tr><td>cell1</td><td>cell2</td></tr></table>",
// +-------+-------+
// | cell1 | cell2 |
// +-------+-------+
"+-------+-------+\n| cell1 | cell2 |\n+-------+-------+",
"cell1 cell2",
},
{
"<table><tr><td>row1</td></tr><tr><td>row2</td></tr></table>",
// +------+
// | row1 |
// | row2 |
// +------+
"+------+\n| row1 |\n| row2 |\n+------+",
"row1 row2",
},
{
`<table>
<tbody>
<tr><td><p>Row-1-Col-1-Msg1</p><p>Row-1-Col-1-Msg2</p></td><td>Row-1-Col-2</td></tr>
<tr><td>Row-2-Col-1</td><td>Row-2-Col-2</td></tr>
</tbody>
</table>`,
// +--------------------------------+-------------+
// | Row-1-Col-1-Msg1 | Row-1-Col-2 |
// | Row-1-Col-1-Msg2 | |
// | Row-2-Col-1 | Row-2-Col-2 |
// +--------------------------------+-------------+
`+--------------------------------+-------------+
| Row-1-Col-1-Msg1 | Row-1-Col-2 |
| Row-1-Col-1-Msg2 | |
| Row-2-Col-1 | Row-2-Col-2 |
+--------------------------------+-------------+`,
`Row-1-Col-1-Msg1
Row-1-Col-1-Msg2
Row-1-Col-2 Row-2-Col-1 Row-2-Col-2`,
},
{
`<table>
<tr><td>cell1-1</td><td>cell1-2</td></tr>
<tr><td>cell2-1</td><td>cell2-2</td></tr>
</table>`,
// +---------+---------+
// | cell1-1 | cell1-2 |
// | cell2-1 | cell2-2 |
// +---------+---------+
"+---------+---------+\n| cell1-1 | cell1-2 |\n| cell2-1 | cell2-2 |\n+---------+---------+",
"cell1-1 cell1-2 cell2-1 cell2-2",
},
{
`<table>
<thead>
<tr><th>Header 1</th><th>Header 2</th></tr>
</thead>
<tfoot>
<tr><td>Footer 1</td><td>Footer 2</td></tr>
</tfoot>
<tbody>
<tr><td>Row 1 Col 1</td><td>Row 1 Col 2</td></tr>
<tr><td>Row 2 Col 1</td><td>Row 2 Col 2</td></tr>
</tbody>
</table>`,
`+-------------+-------------+
| HEADER 1 | HEADER 2 |
+-------------+-------------+
| Row 1 Col 1 | Row 1 Col 2 |
| Row 2 Col 1 | Row 2 Col 2 |
+-------------+-------------+
| FOOTER 1 | FOOTER 2 |
+-------------+-------------+`,
"Header 1 Header 2 Footer 1 Footer 2 Row 1 Col 1 Row 1 Col 2 Row 2 Col 1 Row 2 Col 2",
},
// Two tables in same HTML (goal is to test that context is
// reinitalized correctly).
{
`<p>
<table>
<thead>
<tr><th>Table 1 Header 1</th><th>Table 1 Header 2</th></tr>
</thead>
<tfoot>
<tr><td>Table 1 Footer 1</td><td>Table 1 Footer 2</td></tr>
</tfoot>
<tbody>
<tr><td>Table 1 Row 1 Col 1</td><td>Table 1 Row 1 Col 2</td></tr>
<tr><td>Table 1 Row 2 Col 1</td><td>Table 1 Row 2 Col 2</td></tr>
</tbody>
</table>
<table>
<thead>
<tr><th>Table 2 Header 1</th><th>Table 2 Header 2</th></tr>
</thead>
<tfoot>
<tr><td>Table 2 Footer 1</td><td>Table 2 Footer 2</td></tr>
</tfoot>
<tbody>
<tr><td>Table 2 Row 1 Col 1</td><td>Table 2 Row 1 Col 2</td></tr>
<tr><td>Table 2 Row 2 Col 1</td><td>Table 2 Row 2 Col 2</td></tr>
</tbody>
</table>
</p>`,
`+---------------------+---------------------+
| TABLE 1 HEADER 1 | TABLE 1 HEADER 2 |
+---------------------+---------------------+
| Table 1 Row 1 Col 1 | Table 1 Row 1 Col 2 |
| Table 1 Row 2 Col 1 | Table 1 Row 2 Col 2 |
+---------------------+---------------------+
| TABLE 1 FOOTER 1 | TABLE 1 FOOTER 2 |
+---------------------+---------------------+
+---------------------+---------------------+
| TABLE 2 HEADER 1 | TABLE 2 HEADER 2 |
+---------------------+---------------------+
| Table 2 Row 1 Col 1 | Table 2 Row 1 Col 2 |
| Table 2 Row 2 Col 1 | Table 2 Row 2 Col 2 |
+---------------------+---------------------+
| TABLE 2 FOOTER 1 | TABLE 2 FOOTER 2 |
+---------------------+---------------------+`,
`Table 1 Header 1 Table 1 Header 2 Table 1 Footer 1 Table 1 Footer 2 Table 1 Row 1 Col 1 Table 1 Row 1 Col 2 Table 1 Row 2 Col 1 Table 1 Row 2 Col 2
Table 2 Header 1 Table 2 Header 2 Table 2 Footer 1 Table 2 Footer 2 Table 2 Row 1 Col 1 Table 2 Row 1 Col 2 Table 2 Row 2 Col 1 Table 2 Row 2 Col 2`,
},
{
"_<table><tr><td>cell</td></tr></table>_",
"_\n\n+------+\n| cell |\n+------+\n\n_",
"_\n\ncell\n\n_",
},
{
`<table>
<tr>
<th>Item</th>
<th>Description</th>
<th>Price</th>
</tr>
<tr>
<td>Golang</td>
<td>Open source programming language that makes it easy to build simple, reliable, and efficient software</td>
<td>$10.99</td>
</tr>
<tr>
<td>Hermes</td>
<td>Programmatically create beautiful e-mails using Golang.</td>
<td>$1.99</td>
</tr>
</table>`,
`+--------+--------------------------------+--------+
| ITEM | DESCRIPTION | PRICE |
+--------+--------------------------------+--------+
| Golang | Open source programming | $10.99 |
| | language that makes it easy | |
| | to build simple, reliable, and | |
| | efficient software | |
| Hermes | Programmatically create | $1.99 |
| | beautiful e-mails using | |
| | Golang. | |
+--------+--------------------------------+--------+`,
"Item Description Price Golang Open source programming language that makes it easy to build simple, reliable, and efficient software $10.99 Hermes Programmatically create beautiful e-mails using Golang. $1.99",
},
}
for _, testCase := range testCases {
options := Options{
PrettyTables: true,
}
// Check pretty tabular ASCII version.
if msg, err := wantString(testCase.input, testCase.tabularOutput, options); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
// Check plain version.
if msg, err := wantString(testCase.input, testCase.plaintextOutput); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestStrippingLists(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
"<ul></ul>",
"",
},
{
"<ul><li>item</li></ul>_",
"* item\n\n_",
},
{
"<li class='123'>item 1</li> <li>item 2</li>\n_",
"* item 1\n* item 2\n_",
},
{
"<li>item 1</li> \t\n <li>item 2</li> <li> item 3</li>\n_",
"* item 1\n* item 2\n* item 3\n_",
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestLinks(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
`<a></a>`,
``,
},
{
`<a href=""></a>`,
``,
},
{
`<a href="http://example.com/"></a>`,
`( http://example.com/ )`,
},
{
`<a href="">Link</a>`,
`Link`,
},
{
`<a href="http://example.com/">Link</a>`,
`Link ( http://example.com/ )`,
},
{
`<a href="http://example.com/"><span class="a">Link</span></a>`,
`Link ( http://example.com/ )`,
},
{
"<a href='http://example.com/'>\n\t<span class='a'>Link</span>\n\t</a>",
`Link ( http://example.com/ )`,
},
{
"<a href='mailto:contact@example.org'>Contact Us</a>",
`Contact Us ( contact@example.org )`,
},
{
"<a href=\"http://example.com:80/~user?aaa=bb&amp;c=d,e,f#foo\">Link</a>",
`Link ( http://example.com:80/~user?aaa=bb&c=d,e,f#foo )`,
},
{
"<a title='title' href=\"http://example.com/\">Link</a>",
`Link ( http://example.com/ )`,
},
{
"<a href=\" http://example.com/ \"> Link </a>",
`Link ( http://example.com/ )`,
},
{
"<a href=\"http://example.com/a/\">Link A</a> <a href=\"http://example.com/b/\">Link B</a>",
`Link A ( http://example.com/a/ ) Link B ( http://example.com/b/ )`,
},
{
"<a href=\"%%LINK%%\">Link</a>",
`Link ( %%LINK%% )`,
},
{
"<a href=\"[LINK]\">Link</a>",
`Link ( [LINK] )`,
},
{
"<a href=\"{LINK}\">Link</a>",
`Link ( {LINK} )`,
},
{
"<a href=\"[[!unsubscribe]]\">Link</a>",
`Link ( [[!unsubscribe]] )`,
},
{
"<p>This is <a href=\"http://www.google.com\" >link1</a> and <a href=\"http://www.google.com\" >link2 </a> is next.</p>",
`This is link1 ( http://www.google.com ) and link2 ( http://www.google.com ) is next.`,
},
{
"<a href=\"http://www.google.com\" >http://www.google.com</a>",
`http://www.google.com`,
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestImageAltTags(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
`<img />`,
``,
},
{
`<img src="http://example.ru/hello.jpg" />`,
``,
},
{
`<img alt="Example"/>`,
``,
},
{
`<img src="http://example.ru/hello.jpg" alt="Example"/>`,
``,
},
// Images do matter if they are in a link.
{
`<a href="http://example.com/"><img src="http://example.ru/hello.jpg" alt="Example"/></a>`,
`Example ( http://example.com/ )`,
},
{
`<a href="http://example.com/"><img src="http://example.ru/hello.jpg" alt="Example"></a>`,
`Example ( http://example.com/ )`,
},
{
`<a href='http://example.com/'><img src='http://example.ru/hello.jpg' alt='Example'/></a>`,
`Example ( http://example.com/ )`,
},
{
`<a href='http://example.com/'><img src='http://example.ru/hello.jpg' alt='Example'></a>`,
`Example ( http://example.com/ )`,
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestHeadings(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
"<h1>Test</h1>",
"****\nTest\n****",
},
{
"\t<h1>\nTest</h1> ",
"****\nTest\n****",
},
{
"\t<h1>\nTest line 1<br>Test 2</h1> ",
"***********\nTest line 1\nTest 2\n***********",
},
{
"<h1>Test</h1> <h1>Test</h1>",
"****\nTest\n****\n\n****\nTest\n****",
},
{
"<h2>Test</h2>",
"----\nTest\n----",
},
{
"<h1><a href='http://example.com/'>Test</a></h1>",
"****************************\nTest ( http://example.com/ )\n****************************",
},
{
"<h3> <span class='a'>Test </span></h3>",
"Test\n----",
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestBold(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
"<b>Test</b>",
"*Test*",
},
{
"\t<b>Test</b> ",
"*Test*",
},
{
"\t<b>Test line 1<br>Test 2</b> ",
"*Test line 1\nTest 2*",
},
{
"<b>Test</b> <b>Test</b>",
"*Test* *Test*",
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestDiv(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
"<div>Test</div>",
"Test",
},
{
"\t<div>Test</div> ",
"Test",
},
{
"<div>Test line 1<div>Test 2</div></div>",
"Test line 1\nTest 2",
},
{
"Test 1<div>Test 2</div> <div>Test 3</div>Test 4",
"Test 1\nTest 2\nTest 3\nTest 4",
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestBlockquotes(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
"<div>level 0<blockquote>level 1<br><blockquote>level 2</blockquote>level 1</blockquote><div>level 0</div></div>",
"level 0\n> \n> level 1\n> \n>> level 2\n> \n> level 1\n\nlevel 0",
},
{
"<blockquote>Test</blockquote>Test",
"> \n> Test\n\nTest",
},
{
"\t<blockquote> \nTest<br></blockquote> ",
"> \n> Test\n>",
},
{
"\t<blockquote> \nTest line 1<br>Test 2</blockquote> ",
"> \n> Test line 1\n> Test 2",
},
{
"<blockquote>Test</blockquote> <blockquote>Test</blockquote> Other Test",
"> \n> Test\n\n> \n> Test\n\nOther Test",
},
{
"<blockquote>Lorem ipsum Commodo id consectetur pariatur ea occaecat minim aliqua ad sit consequat quis ex commodo Duis incididunt eu mollit consectetur fugiat voluptate dolore in pariatur in commodo occaecat Ut occaecat velit esse labore aute quis commodo non sit dolore officia Excepteur cillum amet cupidatat culpa velit labore ullamco dolore mollit elit in aliqua dolor irure do</blockquote>",
"> \n> Lorem ipsum Commodo id consectetur pariatur ea occaecat minim aliqua ad\n> sit consequat quis ex commodo Duis incididunt eu mollit consectetur fugiat\n> voluptate dolore in pariatur in commodo occaecat Ut occaecat velit esse\n> labore aute quis commodo non sit dolore officia Excepteur cillum amet\n> cupidatat culpa velit labore ullamco dolore mollit elit in aliqua dolor\n> irure do",
},
{
"<blockquote>Lorem<b>ipsum</b><b>Commodo</b><b>id</b><b>consectetur</b><b>pariatur</b><b>ea</b><b>occaecat</b><b>minim</b><b>aliqua</b><b>ad</b><b>sit</b><b>consequat</b><b>quis</b><b>ex</b><b>commodo</b><b>Duis</b><b>incididunt</b><b>eu</b><b>mollit</b><b>consectetur</b><b>fugiat</b><b>voluptate</b><b>dolore</b><b>in</b><b>pariatur</b><b>in</b><b>commodo</b><b>occaecat</b><b>Ut</b><b>occaecat</b><b>velit</b><b>esse</b><b>labore</b><b>aute</b><b>quis</b><b>commodo</b><b>non</b><b>sit</b><b>dolore</b><b>officia</b><b>Excepteur</b><b>cillum</b><b>amet</b><b>cupidatat</b><b>culpa</b><b>velit</b><b>labore</b><b>ullamco</b><b>dolore</b><b>mollit</b><b>elit</b><b>in</b><b>aliqua</b><b>dolor</b><b>irure</b><b>do</b></blockquote>",
"> \n> Lorem *ipsum* *Commodo* *id* *consectetur* *pariatur* *ea* *occaecat* *minim*\n> *aliqua* *ad* *sit* *consequat* *quis* *ex* *commodo* *Duis* *incididunt* *eu*\n> *mollit* *consectetur* *fugiat* *voluptate* *dolore* *in* *pariatur* *in* *commodo*\n> *occaecat* *Ut* *occaecat* *velit* *esse* *labore* *aute* *quis* *commodo*\n> *non* *sit* *dolore* *officia* *Excepteur* *cillum* *amet* *cupidatat* *culpa*\n> *velit* *labore* *ullamco* *dolore* *mollit* *elit* *in* *aliqua* *dolor* *irure*\n> *do*",
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestIgnoreStylesScriptsHead(t *testing.T) {
testCases := []struct {
input string
output string
}{
{
"<style>Test</style>",
"",
},
{
"<style type=\"text/css\">body { color: #fff; }</style>",
"",
},
{
"<link rel=\"stylesheet\" href=\"main.css\">",
"",
},
{
"<script>Test</script>",
"",
},
{
"<script src=\"main.js\"></script>",
"",
},
{
"<script type=\"text/javascript\" src=\"main.js\"></script>",
"",
},
{
"<script type=\"text/javascript\">Test</script>",
"",
},
{
"<script type=\"text/ng-template\" id=\"template.html\"><a href=\"http://google.com\">Google</a></script>",
"",
},
{
"<script type=\"bla-bla-bla\" id=\"template.html\">Test</script>",
"",
},
{
`<html><head><title>Title</title></head><body></body></html>`,
"",
},
}
for _, testCase := range testCases {
if msg, err := wantString(testCase.input, testCase.output); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestText(t *testing.T) {
testCases := []struct {
input string
expr string
}{
{
`<li>
<a href="/new" data-ga-click="Header, create new repository, icon:repo"><span class="octicon octicon-repo"></span> New repository</a>
</li>`,
`\* New repository \( /new \)`,
},
{
`hi
<br>
hello <a href="https://google.com">google</a>
<br><br>
test<p>List:</p>
<ul>
<li><a href="foo">Foo</a></li>
<li><a href="http://www.microshwhat.com/bar/soapy">Barsoap</a></li>
<li>Baz</li>
</ul>
`,
`hi
hello google \( https://google.com \)
test
List:
\* Foo \( foo \)
\* Barsoap \( http://www.microshwhat.com/bar/soapy \)
\* Baz`,
},
// Malformed input html.
{
`hi
hello <a href="https://google.com">google</a>
test<p>List:</p>
<ul>
<li><a href="foo">Foo</a>
<li><a href="/
bar/baz">Bar</a>
<li>Baz</li>
</ul>
`,
`hi hello google \( https://google.com \) test
List:
\* Foo \( foo \)
\* Bar \( /\n[ \t]+bar/baz \)
\* Baz`,
},
}
for _, testCase := range testCases {
if msg, err := wantRegExp(testCase.input, testCase.expr); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
func TestPeriod(t *testing.T) {
testCases := []struct {
input string
expr string
}{
{
`<p>Lorem ipsum <span>test</span>.</p>`,
`Lorem ipsum test\.`,
},
{
`<p>Lorem ipsum <span>test.</span></p>`,
`Lorem ipsum test\.`,
},
}
for _, testCase := range testCases {
if msg, err := wantRegExp(testCase.input, testCase.expr); err != nil {
t.Error(err)
} else if len(msg) > 0 {
t.Log(msg)
}
}
}
type StringMatcher interface {
MatchString(string) bool
String() string
}
type RegexpStringMatcher string
func (m RegexpStringMatcher) MatchString(str string) bool {
return regexp.MustCompile(string(m)).MatchString(str)
}
func (m RegexpStringMatcher) String() string {
return string(m)
}
type ExactStringMatcher string
func (m ExactStringMatcher) MatchString(str string) bool {
return string(m) == str
}
func (m ExactStringMatcher) String() string {
return string(m)
}
func wantRegExp(input string, outputRE string, options ...Options) (string, error) {
return match(input, RegexpStringMatcher(outputRE), options...)
}
func wantString(input string, output string, options ...Options) (string, error) {
return match(input, ExactStringMatcher(output), options...)
}
func match(input string, matcher StringMatcher, options ...Options) (string, error) {
text, err := FromString(input, options...)
if err != nil {
return "", err
}
if !matcher.MatchString(text) {
return "", fmt.Errorf(`error: input did not match specified expression
Input:
>>>>
%v
<<<<
Output:
>>>>
%v
<<<<
Expected:
>>>>
%v
<<<<`,
input,
text,
matcher.String(),
)
}
var msg string
if EnableExtraLogging {
msg = fmt.Sprintf(
`
input:
%v
output:
%v
`,
input,
text,
)
}
return msg, nil
}
func Example() {
inputHTML := `
<html>
<head>
<title>My Mega Service</title>
<link rel=\"stylesheet\" href=\"main.css\">
<style type=\"text/css\">body { color: #fff; }</style>
</head>
<body>
<div class="logo">
<a href="http://jaytaylor.com/"><img src="/logo-image.jpg" alt="Mega Service"/></a>
</div>
<h1>Welcome to your new account on my service!</h1>
<p>
Here is some more information:
<ul>
<li>Link 1: <a href="https://example.com">Example.com</a></li>
<li>Link 2: <a href="https://example2.com">Example2.com</a></li>
<li>Something else</li>
</ul>
</p>
<table>
<thead>
<tr><th>Header 1</th><th>Header 2</th></tr>
</thead>
<tfoot>
<tr><td>Footer 1</td><td>Footer 2</td></tr>
</tfoot>
<tbody>
<tr><td>Row 1 Col 1</td><td>Row 1 Col 2</td></tr>
<tr><td>Row 2 Col 1</td><td>Row 2 Col 2</td></tr>
</tbody>
</table>
</body>
</html>`
text, err := FromString(inputHTML, Options{PrettyTables: true})
if err != nil {
panic(err)
}
fmt.Println(text)
// Output:
// Mega Service ( http://jaytaylor.com/ )
//
// ******************************************
// Welcome to your new account on my service!
// ******************************************
//
// Here is some more information:
//
// * Link 1: Example.com ( https://example.com )
// * Link 2: Example2.com ( https://example2.com )
// * Something else
//
// +-------------+-------------+
// | HEADER 1 | HEADER 2 |
// +-------------+-------------+
// | Row 1 Col 1 | Row 1 Col 2 |
// | Row 2 Col 1 | Row 2 Col 2 |
// +-------------+-------------+
// | FOOTER 1 | FOOTER 2 |
// +-------------+-------------+
}

22
vendor/github.com/jaytaylor/html2text/testdata/utf8.html generated vendored Executable file
View file

@ -0,0 +1,22 @@
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>学习之道:美国公认学习第一书title</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<link href="page_styles.css" rel="stylesheet" type="text/css" />
</head>
<body class="calibre">
<p id="filepos9452" class="calibre_"><span class="calibre6"><span class="bold">写在前面的话</span></span>
</p>
<p class="calibre_12">在台湾的那次世界冠军赛上,我几近疯狂,直至两年后的今天,我仍沉浸在这次的经历中。这是我生平第一次如此深入地审视我自己,甚至是第一次尝试审视自己。这个过程令人很是兴奋,同时也有点感觉怪异。我重新认识了自我,看到了自己的另外一面,自己从未发觉的另外一面。为了生存,为了取胜,我成了一名角斗士,彻头彻尾,简单纯粹。我并没有意识到这一角色早已在我的心中生根发芽,呼之欲出。也许,他的出现已是不可避免。</p>
<p class="calibre_7">而我这全新的一面,与我一直熟识的那个乔希,那个曾经害怕黑暗的孩子,那个象棋手,那个狂热于雨水、反复诵读杰克·克鲁亚克作品的年轻人之间,又有什么样的联系呢?这些都是我正在努力弄清楚的问题。</p>
<p class="calibre_7">自台湾赛事之后,我急切非常,一心想要回到训练中去,摆脱自己已经达到巅峰的想法。在过去的两年中,我已经重新开始。这是一个新的起点。前方的路还很长,有待进一步的探索。</p>
<p class="calibre_7">这本书的创作耗费了相当多的时间和精力。在成长的过程中,我在我的小房间里从未想过等待我的会是这样的战斗。在创作中,我的思想逐渐成熟;爱恋从分崩离析,到失而复得,世界冠军头衔从失之交臂,到囊中取物。如果说在我人生的第一个二十九年中,我学到了什么,那就是,我们永远无法预测结局,无论是重要的比赛、冒险,还是轰轰烈烈的爱情。我们唯一可以肯定的只有,出乎意料。不管我们做了多么万全的准备,在生活的真实场景中,我们总是会处于陌生的境地。我们也许会无法冷静,失去理智,感觉似乎整个世界都在针对我们。在这个时候,我们所要做的是要付出加倍的努力,要表现得比预想得更好。我认为,关键在于准备好随机应变,准备好在所能想象的高压下发挥出创造力。</p>
<p class="calibre_7">读者朋友们,我非常希望你们在读过这本书后,可以得到启发,甚至会得到触动,从而能够根据各自的天赋与特长,去实现自己的梦想。这就是我写作此书的目的。我在字里行间所传达的理念曾经使我受益匪浅,我很希望它们可以为大家提供一个基本的框架和方向。如果我的方法言之有理,那么就请接受它,琢磨它,并加之自己的见解。忘记我的那些数字。真正的掌握需要通过自己发现一些最能够引起共鸣的信息,并将其彻底地融合进来,直至成为一体,这样我们才能随心所欲地驾驭它。</p>
<div class="mbp_pagebreak" id="calibre_pb_4"></div>
</body>
</html>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>1892年波兰文版序言title</title>
<link rel="stylesheet" href="css/stylesheet.css" type="text/css" />
</head>
<body>
<div id="page30" />
<h2 id="CHP2-6">1892年波兰文版序言<a id="wzyy_18_30" href="#wz_18_30"><sup>[18]</sup></a></h2>
<p>出版共产主义宣言的一种新的波兰文本已成为必要,这一事实,引起了许多感想。</p>
<p>首先值得注意的是,近来宣言在一定程度上已成为欧洲大陆大工业发展的一种尺度。一个国家的大工业越发展,该国工人中想认清自己作为工人阶级在有产阶级面前所处地位的要求就越增加,他们中间的社会主义运动也越扩大,因而对宣言的需求也越增长。这样,根据宣言用某国文字销行的份数,不仅能够相当确切地断定该国工人运动的状况,而且还能够相当确切地断定该国大工业发展的程度。</p>
<p>因此,波兰文的新版本标志着波兰工业的决定性进步。从十年前发表的上一个版本以来确实有了这种进步,对此丝毫不容置疑。俄国的波兰,会议的波兰<a id="wzyy_19_30" href="#wz_19_30"><sup>[19]</sup></a>,成了俄罗斯帝国巨大的工业区。俄国大工业是零星分散的,一部分在芬兰湾沿岸,一部分在中央区(莫斯科和弗拉基米尔),第三部分在黑海和亚速海沿岸,还有另一些散布在别处;而波兰工业则紧缩于相对狭小的地区,享受到由这种积聚引起的长处与短处。这种长处是竞争着的俄罗斯工厂主所承认的,他们要求实行保护关税以对付波兰,尽管他们渴望使波兰人俄罗斯化。这种短处,对波兰工厂主与俄罗斯政府来说,表现在社会主义思想在波兰工人中间的迅速传播和对宣言需求的增长。</p>
<p>但是,波兰工业的迅速发展——它超过了俄国工业——本身<a id="page31" />是波兰人民的坚强生命力的一个新证明是波兰人民临近的民族复兴的一个新保证。而一个独立强盛的波兰的复兴不只是一件同波兰人有关、而且是同我们大家有关的事情。只有当每个民族在自己内部完全自主时欧洲各民族间真诚的国际合作才是可能的。1848年革命在无产阶级旗帜下使无产阶级的战士最终只作了资产阶级的工作这次革命通过自己遗嘱的执行者路易·波拿巴和俾斯麦也实现了意大利、德国和匈牙利的独立。然而波兰它从1792年以来为革命做的比所有这三个国家总共做的还要多而当它1863年失败于强大十倍的俄军的时候人们却把它抛弃不顾了。贵族既未能保持住、也未能重新争得波兰的独立今天波兰的独立对资产阶级至少是无所谓的。然而波兰的独立对于欧洲各民族和谐的合作是必需的。这种独立只有年轻的波兰无产阶级才能争得而且在它的手中会很好地保持住。因为欧洲所有其余的工人都象波兰工人自己一样也需要波兰的独立。</p>
<p>弗·恩格斯</p>
<p>1892年2月10日于伦敦</p>
<div id="page74" />
<div><a id="wz_18_30" href="#wzyy_18_30">[18]</a> 恩格斯用德文为《宣言》新的波兰文本写了这篇序言。1892年由波兰社会主义者在伦敦办的《黎明》杂志社出版。序言寄出后恩格斯写信给门德尔森1892年2月11日信中说他很愿意学会波兰文并且深入研究波兰工人运动的发展以便能够为《宣言》的下一版写一篇更详细的序言。——第20页</div>
<div><a id="wz_19_30" href="#wzyy_19_30">[19]</a> 指维也纳会议的波兰即根据1814—1815年维也纳会议的决定以波兰王国的正式名义割给俄国的那部分波兰土地。——第20页</div>
</body>
</html>