diff --git a/src/wp2hugo/internal/hugogenerator/hugopage/hugo_page_test.go b/src/wp2hugo/internal/hugogenerator/hugopage/hugo_page_test.go index 8157502..3e00feb 100644 --- a/src/wp2hugo/internal/hugogenerator/hugopage/hugo_page_test.go +++ b/src/wp2hugo/internal/hugogenerator/hugopage/hugo_page_test.go @@ -2,9 +2,56 @@ package hugopage import ( "github.com/stretchr/testify/assert" + "net/url" "testing" ) +const ( + _sampleHTMLInput1 = ` + +

Hello world. "Example 1".

+ +` + _sampleMarkdownOutput1 = `[Hello world](https://example.com). "[Example 1](https://example.com)".` +) + +const ( + _sampleHTMLInput2 = `Unlike his other, this book` + _sampleMarkdownOutput2 = `Unlike [his](https://some.com/link1) [other](https://some.com/link2), this book` +) + +const ( + _sampleHTMLInput3 = `
  1. First item
  2. Second item
` + _sampleMarkdownOutput3 = "1. First item\n1. Second item" +) + +func TestMarkdownExtractorWithLink1(t *testing.T) { + testMarkdownExtractor(t, _sampleHTMLInput2, _sampleMarkdownOutput2) +} + +func TestMarkdownExtractorWithLink2(t *testing.T) { + // Ref: + // 1. https://github.com/ashishb/wp2hugo/issues/11 + // 2. https://github.com/JohannesKaufmann/html-to-markdown/issues/95 + t.Skipf("This is failing due to a bug in the underlying library. Skipping for now.") + testMarkdownExtractor(t, _sampleHTMLInput1, _sampleMarkdownOutput1) +} + +func TestListExtractor(t *testing.T) { + t.Skipf("This is failing due to how the underlying library works. Skipping for now.") + testMarkdownExtractor(t, _sampleHTMLInput3, _sampleMarkdownOutput3) +} + +func testMarkdownExtractor(t *testing.T, htmlInput string, markdownOutput string) { + url1, err := url.Parse("https://example.com") + assert.Nil(t, err) + page, err := NewPage(nil, *url1, "author", "Title", nil, false, nil, nil, nil, htmlInput, nil) + assert.Nil(t, err) + md, err := page.getMarkdown(nil, htmlInput, nil) + assert.Nil(t, err) + assert.Equal(t, markdownOutput, *md) +} + func TestPreTagExtractor2(t *testing.T) { const example1 = `
document.querySelector("video").playbackRate = 2.0;   // For 2X speed-up
` const example2 = `
echo "whatever"
`