Skip to content

Commit

Permalink
chore: add one more broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishb committed Aug 18, 2024
1 parent ca3c27e commit 9d57abb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/wp2hugo/internal/hugogenerator/hugopage/hugo_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var (
_preTagExtractor2 = regexp.MustCompile(`<pre class=".*?lang:([^" ]+).*?>([\s\S]*?)</pre>`)

_hugoShortCodeMatcher = regexp.MustCompile(`{{<.*?>}}`)

// Ref: https://github.com/markdownlint/markdownlint/blob/main/docs/RULES.md#md012---multiple-consecutive-blank-lines
// Replace multiple consecutive newlines with just two newlines
_moreThanTwoNewlines = regexp.MustCompile(`\n{3,}`)
)

// Extracts "src" from Hugo figure shortcode
Expand Down Expand Up @@ -301,10 +305,7 @@ func replaceOrderedListNumbers(markdown string) string {
}

func replaceConsecutiveNewlines(markdown string) string {
// Ref: https://github.com/markdownlint/markdownlint/blob/main/docs/RULES.md#md012---multiple-consecutive-blank-lines
// Replace multiple consecutive newlines with just two newlines
reg1 := regexp.MustCompile(`\n{3,}`)
return reg1.ReplaceAllString(markdown, "\n\n")
return _moreThanTwoNewlines.ReplaceAllString(markdown, "\n\n")
}

func (page Page) writeContent(w io.Writer) error {
Expand Down
11 changes: 11 additions & 0 deletions src/wp2hugo/internal/hugogenerator/hugopage/hugo_page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const (
_sampleMarkdownOutput4 = "This is\n\nsome\n\ntext"
)

const (
_sampleHTMLInput5 = "<!-- wp:paragraph --><p>First line<br /><abcedef>Second line<br>Third line</p><!-- /wp:paragraph -->"
_sampleMarkdownOutput5 = "First line \nSecond line \nThird line"
)

func TestMarkdownExtractorWithLink1(t *testing.T) {
testMarkdownExtractor(t, _sampleHTMLInput2, _sampleMarkdownOutput2)
}
Expand All @@ -50,6 +55,12 @@ func TestConsecutiveNewlines(t *testing.T) {
testMarkdownExtractor(t, _sampleHTMLInput4, _sampleMarkdownOutput4)
}

func TestManualLineBreaks(t *testing.T) {
// Ref: https://github.com/ashishb/wp2hugo/issues/12
t.Skipf("This is failing due to a bug in the underlying library. Skipping for now.")
testMarkdownExtractor(t, _sampleHTMLInput5, _sampleMarkdownOutput5)
}

func testMarkdownExtractor(t *testing.T, htmlInput string, markdownOutput string) {
url1, err := url.Parse("https://example.com")
assert.Nil(t, err)
Expand Down

0 comments on commit 9d57abb

Please sign in to comment.